Skip to content

Commit 205e20a

Browse files
committed
Choose the last publicly known node as the starting point for the random walk.
1 parent 893c600 commit 205e20a

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lightning/src/routing/router.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,14 +1520,13 @@ where L::Target: Logger {
15201520
for path in selected_paths.iter_mut() {
15211521
let mut shadow_ctlv_expiry_delta_offset: u32 = 0;
15221522

1523-
// Choose starting point for the random walk
1524-
let mut cur_node_id = if network_nodes.contains_key(&payee_node_id) {
1525-
payee_node_id
1526-
} else {
1527-
assert_eq!(payee_node_id, NodeId::from_pubkey(&path.last().unwrap().as_ref().unwrap().pubkey));
1528-
assert!(path.len() > 1);
1529-
NodeId::from_pubkey(&path.iter().rev().next().unwrap().as_ref().unwrap().pubkey)
1530-
};
1523+
// Choose the last publicly known node as the starting point for the random walk
1524+
let mut cur_node_iter = path.iter().rev();
1525+
let mut cur_node_id = NodeId::from_pubkey(&cur_node_iter.next().unwrap().as_ref().unwrap().pubkey);
1526+
assert_eq!(cur_node_id, payee_node_id);
1527+
while !network_nodes.contains_key(&cur_node_id) {
1528+
cur_node_id = NodeId::from_pubkey(&cur_node_iter.next().unwrap().as_ref().unwrap().pubkey);
1529+
}
15311530

15321531
// Init PRNG
15331532
let mut path_nonce = [0u8; 8];

0 commit comments

Comments
 (0)