Skip to content

Commit fa9715d

Browse files
authored
Merge pull request #77 from TheBlueMatt/2018-07-route-tweaks
Add arg to get_route to specify our local channels explicitly
2 parents b9562b8 + 667cd66 commit fa9715d

File tree

3 files changed

+210
-39
lines changed

3 files changed

+210
-39
lines changed

fuzz/fuzz_targets/full_stack_target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ pub fn do_test(data: &[u8]) {
213213
},
214214
4 => {
215215
let value = slice_to_be24(get_slice!(3)) as u64;
216-
let route = match router.get_route(&get_pubkey!(), &Vec::new(), value, 42) {
216+
let route = match router.get_route(&get_pubkey!(), None, &Vec::new(), value, 42) {
217217
Ok(route) => route,
218218
Err(_) => return,
219219
};

src/ln/channelmanager.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,25 @@ impl ChannelManager {
293293
res
294294
}
295295

296+
/// Gets the list of usable channels, in random order. Useful as an argument to
297+
/// Router::get_route to ensure non-announced channels are used.
298+
pub fn list_usable_channels(&self) -> Vec<ChannelDetails> {
299+
let channel_state = self.channel_state.lock().unwrap();
300+
let mut res = Vec::with_capacity(channel_state.by_id.len());
301+
for (channel_id, channel) in channel_state.by_id.iter() {
302+
if channel.is_usable() {
303+
res.push(ChannelDetails {
304+
channel_id: (*channel_id).clone(),
305+
short_channel_id: channel.get_short_channel_id(),
306+
remote_network_id: channel.get_their_node_id(),
307+
channel_value_satoshis: channel.get_value_satoshis(),
308+
user_id: channel.get_user_id(),
309+
});
310+
}
311+
}
312+
res
313+
}
314+
296315
/// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
297316
/// will be accepted on the given channel, and after additional timeout/the closing of all
298317
/// pending HTLCs, the channel will be closed on chain.
@@ -2436,7 +2455,7 @@ mod tests {
24362455
const TEST_FINAL_CLTV: u32 = 32;
24372456

24382457
fn route_payment(origin_node: &Node, expected_route: &[&Node], recv_value: u64) -> ([u8; 32], [u8; 32]) {
2439-
let route = origin_node.router.get_route(&expected_route.last().unwrap().node.get_our_node_id(), &Vec::new(), recv_value, TEST_FINAL_CLTV).unwrap();
2458+
let route = origin_node.router.get_route(&expected_route.last().unwrap().node.get_our_node_id(), None, &Vec::new(), recv_value, TEST_FINAL_CLTV).unwrap();
24402459
assert_eq!(route.hops.len(), expected_route.len());
24412460
for (node, hop) in expected_route.iter().zip(route.hops.iter()) {
24422461
assert_eq!(hop.pubkey, node.node.get_our_node_id());
@@ -2446,7 +2465,7 @@ mod tests {
24462465
}
24472466

24482467
fn route_over_limit(origin_node: &Node, expected_route: &[&Node], recv_value: u64) {
2449-
let route = origin_node.router.get_route(&expected_route.last().unwrap().node.get_our_node_id(), &Vec::new(), recv_value, TEST_FINAL_CLTV).unwrap();
2468+
let route = origin_node.router.get_route(&expected_route.last().unwrap().node.get_our_node_id(), None, &Vec::new(), recv_value, TEST_FINAL_CLTV).unwrap();
24502469
assert_eq!(route.hops.len(), expected_route.len());
24512470
for (node, hop) in expected_route.iter().zip(route.hops.iter()) {
24522471
assert_eq!(hop.pubkey, node.node.get_our_node_id());

0 commit comments

Comments
 (0)