Skip to content

Commit b403b06

Browse files
f adapt to adding RouteHop for intro node
1 parent 9a0dd9c commit b403b06

File tree

2 files changed

+32
-39
lines changed

2 files changed

+32
-39
lines changed

lightning/src/routing/router.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,6 @@ 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-
}
316311
}
317312

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

lightning/src/routing/scoring.rs

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,66 +1237,63 @@ 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.node_id_scid_iter().enumerate() {
1241-
let target = NodeId::from_pubkey(&pubkey);
1240+
for (hop_idx, hop) in path.hops.iter().enumerate() {
1241+
let target = NodeId::from_pubkey(&hop.pubkey);
12421242
let channel_directed_from_source = network_graph.channels()
1243-
.get(&scid)
1243+
.get(&hop.short_channel_id)
12441244
.and_then(|channel| channel.as_directed_to(&target));
12451245

1246-
let at_failed_channel = scid == short_channel_id;
1246+
let at_failed_channel = hop.short_channel_id == short_channel_id;
12471247
if at_failed_channel && hop_idx == 0 {
1248-
log_warn!(self.logger, "Payment failed at the first hop - we do not attempt to learn channel info in such cases as we can directly observe local state.\n\tBecause we know the local state, we should generally not see failures here - this may be an indication that your channel peer on channel {} is broken and you may wish to close the channel.", scid);
1248+
log_warn!(self.logger, "Payment failed at the first hop - we do not attempt to learn channel info in such cases as we can directly observe local state.\n\tBecause we know the local state, we should generally not see failures here - this may be an indication that your channel peer on channel {} is broken and you may wish to close the channel.", hop.short_channel_id);
12491249
}
12501250

12511251
// Only score announced channels.
12521252
if let Some((channel, source)) = channel_directed_from_source {
12531253
let capacity_msat = channel.effective_capacity().as_msat();
12541254
if at_failed_channel {
12551255
self.channel_liquidities
1256-
.entry(scid)
1256+
.entry(hop.short_channel_id)
12571257
.or_insert_with(ChannelLiquidity::new)
12581258
.as_directed_mut(source, &target, 0, capacity_msat, &self.params)
1259-
.failed_at_channel(amount_msat, format_args!("SCID {}, towards {:?}", scid, target), &self.logger);
1259+
.failed_at_channel(amount_msat, format_args!("SCID {}, towards {:?}", hop.short_channel_id, target), &self.logger);
12601260
} else {
12611261
self.channel_liquidities
1262-
.entry(scid)
1262+
.entry(hop.short_channel_id)
12631263
.or_insert_with(ChannelLiquidity::new)
12641264
.as_directed_mut(source, &target, 0, capacity_msat, &self.params)
1265-
.failed_downstream(amount_msat, format_args!("SCID {}, towards {:?}", scid, target), &self.logger);
1265+
.failed_downstream(amount_msat, format_args!("SCID {}, towards {:?}", hop.short_channel_id, target), &self.logger);
12661266
}
12671267
} else {
12681268
log_debug!(self.logger, "Not able to penalize channel with SCID {} as we do not have graph info for it (likely a route-hint last-hop).",
1269-
scid);
1269+
hop.short_channel_id);
12701270
}
12711271
if at_failed_channel { break; }
12721272
}
12731273
}
12741274

12751275
fn payment_path_successful(&mut self, path: &Path) {
12761276
let amount_msat = path.final_value_msat();
1277-
let final_scid = path.blinded_tail.as_ref().map_or_else(
1278-
|| path.hops.last().map_or(0, |hop| hop.short_channel_id),
1279-
|tail| tail.intro_node_scid);
12801277
log_trace!(self.logger, "Scoring path through SCID {} as having succeeded at {} msat.",
1281-
final_scid, amount_msat);
1278+
path.hops.split_last().map(|(hop, _)| hop.short_channel_id).unwrap_or(0), amount_msat);
12821279
let network_graph = self.network_graph.read_only();
1283-
for (pubkey, scid) in path.node_id_scid_iter() {
1284-
let target = NodeId::from_pubkey(&pubkey);
1280+
for hop in &path.hops {
1281+
let target = NodeId::from_pubkey(&hop.pubkey);
12851282
let channel_directed_from_source = network_graph.channels()
1286-
.get(&scid)
1283+
.get(&hop.short_channel_id)
12871284
.and_then(|channel| channel.as_directed_to(&target));
12881285

12891286
// Only score announced channels.
12901287
if let Some((channel, source)) = channel_directed_from_source {
12911288
let capacity_msat = channel.effective_capacity().as_msat();
12921289
self.channel_liquidities
1293-
.entry(scid)
1290+
.entry(hop.short_channel_id)
12941291
.or_insert_with(ChannelLiquidity::new)
12951292
.as_directed_mut(source, &target, 0, capacity_msat, &self.params)
1296-
.successful(amount_msat, format_args!("SCID {}, towards {:?}", scid, target), &self.logger);
1293+
.successful(amount_msat, format_args!("SCID {}, towards {:?}", hop.short_channel_id, target), &self.logger);
12971294
} else {
12981295
log_debug!(self.logger, "Not able to learn for channel with SCID {} as we do not have graph info for it (likely a route-hint last-hop).",
1299-
scid);
1296+
hop.short_channel_id);
13001297
}
13011298
}
13021299
}
@@ -1705,7 +1702,7 @@ impl<T: Time> Readable for ChannelLiquidity<T> {
17051702
#[cfg(test)]
17061703
mod tests {
17071704
use super::{ChannelLiquidity, HistoricalBucketRangeTracker, ProbabilisticScoringParameters, ProbabilisticScorerUsingTime};
1708-
use crate::blinded_path::BlindedPath;
1705+
use crate::blinded_path::{BlindedHop, BlindedPath};
17091706
use crate::util::config::UserConfig;
17101707
use crate::util::time::Time;
17111708
use crate::util::time::tests::SinceEpoch;
@@ -2876,8 +2873,8 @@ mod tests {
28762873
}
28772874

28782875
#[test]
2879-
fn scores_intro_node_scid() {
2880-
// Make sure we'll score the scid contained in the blinded portion of a path
2876+
fn scores_with_blinded_path() {
2877+
// Make sure we'll account for a blinded path's final_value_msat in scoring
28812878
let logger = TestLogger::new();
28822879
let network_graph = network_graph(&logger);
28832880
let params = ProbabilisticScoringParameters {
@@ -2896,18 +2893,19 @@ mod tests {
28962893
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), 300);
28972894

28982895
let mut path = payment_path_for_amount(768);
2899-
let last_hop = path.hops.pop().unwrap();
2900-
let _intro_node_hop = path.hops.pop().unwrap();
2896+
let recipient_hop = path.hops.pop().unwrap();
2897+
let blinded_path = BlindedPath {
2898+
introduction_node_id: path.hops.last().as_ref().unwrap().pubkey,
2899+
blinding_point: test_utils::pubkey(42),
2900+
blinded_hops: vec![
2901+
BlindedHop { blinded_node_id: test_utils::pubkey(44), encrypted_payload: Vec::new() }
2902+
],
2903+
};
29012904
path.blinded_tail = Some(BlindedTail {
2902-
path: BlindedPath {
2903-
introduction_node_id: target_pubkey(),
2904-
blinding_point: test_utils::pubkey(42),
2905-
blinded_hops: Vec::new(),
2906-
},
2907-
fee_msat: 2,
2908-
cltv_expiry_delta: last_hop.cltv_expiry_delta,
2909-
final_value_msat: last_hop.fee_msat,
2910-
intro_node_scid: 42,
2905+
hops: blinded_path.blinded_hops,
2906+
blinding_point: blinded_path.blinding_point,
2907+
final_cltv_expiry_delta: recipient_hop.cltv_expiry_delta,
2908+
final_value_msat: recipient_hop.fee_msat,
29112909
});
29122910

29132911
scorer.payment_path_failed(&path, 42);

0 commit comments

Comments
 (0)