Skip to content

Commit 9a0dd9c

Browse files
f add helper for iters
1 parent 7ddb95f commit 9a0dd9c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lightning/src/routing/router.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ impl Path {
308308
pub fn len(&self) -> usize {
309309
self.hops.len() + self.blinded_tail.as_ref().map_or(0, |tail| tail.hops.len().saturating_sub(1)) // Don't double count the intro node
310310
}
311+
312+
pub(super) fn node_id_scid_iter(&self) -> impl Iterator<Item=(PublicKey, u64)> + '_ {
313+
self.hops.iter().map(|hop| (hop.pubkey, hop.short_channel_id))
314+
.chain(self.blinded_tail.as_ref().map(|tail| (tail.path.introduction_node_id, tail.intro_node_scid)))
315+
}
311316
}
312317

313318
/// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,

lightning/src/routing/scoring.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,10 +1237,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
12371237
let amount_msat = path.final_value_msat();
12381238
log_trace!(self.logger, "Scoring path through to SCID {} as having failed at {} msat", short_channel_id, amount_msat);
12391239
let network_graph = self.network_graph.read_only();
1240-
for (hop_idx, (pubkey, scid)) in path.hops.iter().map(|hop| (hop.pubkey, hop.short_channel_id))
1241-
.chain(path.blinded_tail.as_ref().map(|tail| (tail.path.introduction_node_id, tail.intro_node_scid)))
1242-
.enumerate()
1243-
{
1240+
for (hop_idx, (pubkey, scid)) in path.node_id_scid_iter().enumerate() {
12441241
let target = NodeId::from_pubkey(&pubkey);
12451242
let channel_directed_from_source = network_graph.channels()
12461243
.get(&scid)
@@ -1283,9 +1280,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
12831280
log_trace!(self.logger, "Scoring path through SCID {} as having succeeded at {} msat.",
12841281
final_scid, amount_msat);
12851282
let network_graph = self.network_graph.read_only();
1286-
for (pubkey, scid) in path.hops.iter().map(|hop| (hop.pubkey, hop.short_channel_id))
1287-
.chain(path.blinded_tail.as_ref().map(|tail| (tail.path.introduction_node_id, tail.intro_node_scid)))
1288-
{
1283+
for (pubkey, scid) in path.node_id_scid_iter() {
12891284
let target = NodeId::from_pubkey(&pubkey);
12901285
let channel_directed_from_source = network_graph.channels()
12911286
.get(&scid)

0 commit comments

Comments
 (0)