Skip to content

Commit d4e63f5

Browse files
f adapt to adding RouteHop for intro node
1 parent 0fdb3c3 commit d4e63f5

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

lightning/src/routing/router.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,11 @@ impl InFlightHtlcs {
171171

172172
/// Takes in a path with payer's node id and adds the path's details to `InFlightHtlcs`.
173173
pub fn process_path(&mut self, path: &Path, payer_node_id: PublicKey) {
174-
if path.len() == 0 { return };
174+
if path.hops.is_empty() { return };
175175

176176
let mut cumulative_msat = 0;
177177
if let Some(tail) = &path.blinded_tail {
178-
cumulative_msat += tail.final_value_msat + tail.fee_msat;
179-
self.0
180-
.entry((tail.intro_node_scid,
181-
NodeId::from_pubkey(&path.hops.last().map_or(payer_node_id, |hop| hop.pubkey)) <
182-
NodeId::from_pubkey(&tail.path.introduction_node_id)))
183-
.and_modify(|used_liquidity_msat| *used_liquidity_msat += cumulative_msat)
184-
.or_insert(cumulative_msat);
178+
cumulative_msat += tail.final_value_msat;
185179
}
186180

187181
// total_inflight_map needs to be direction-sensitive when keeping track of the HTLC value
@@ -304,7 +298,7 @@ pub struct Path {
304298
impl Path {
305299
/// The length of this path, including the hops of its [`Path::blinded_tail`], if any.
306300
pub fn len(&self) -> usize {
307-
self.hops.len() + self.blinded_tail.as_ref().map_or(0, |tail| tail.path.blinded_hops.len())
301+
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
308302
}
309303
}
310304

@@ -2265,7 +2259,7 @@ fn build_route_from_hops_internal<L: Deref>(
22652259

22662260
#[cfg(test)]
22672261
mod tests {
2268-
use crate::blinded_path::BlindedPath;
2262+
use crate::blinded_path::{BlindedHop, BlindedPath};
22692263
use crate::routing::gossip::{NetworkGraph, P2PGossipSync, NodeId, EffectiveCapacity};
22702264
use crate::routing::utxo::UtxoResult;
22712265
use crate::routing::router::{get_route, build_route_from_hops_internal, add_random_cltv_offset, default_node_features,
@@ -5769,8 +5763,14 @@ mod tests {
57695763

57705764
#[test]
57715765
fn blinded_path_inflight_processing() {
5772-
// Ensure we'll score the channel that's inbound to a blinded path's introduction node.
5766+
// Ensure we'll score the channel that's inbound to a blinded path's introduction node, and
5767+
// account for the blinded tail's final amount_msat.
57735768
let mut inflight_htlcs = InFlightHtlcs::new();
5769+
let blinded_path = BlindedPath {
5770+
introduction_node_id: ln_test_utils::pubkey(43),
5771+
blinding_point: ln_test_utils::pubkey(48),
5772+
blinded_hops: vec![BlindedHop { blinded_node_id: ln_test_utils::pubkey(49), encrypted_payload: Vec::new() }],
5773+
};
57745774
let path = Path {
57755775
hops: vec![RouteHop {
57765776
pubkey: ln_test_utils::pubkey(42),
@@ -5779,16 +5779,19 @@ mod tests {
57795779
channel_features: ChannelFeatures::empty(),
57805780
fee_msat: 100,
57815781
cltv_expiry_delta: 0,
5782-
}],
5783-
blinded_tail: Some(BlindedTail {
5784-
path: BlindedPath {
5785-
introduction_node_id: ln_test_utils::pubkey(43),
5786-
blinding_point: ln_test_utils::pubkey(44),
5787-
blinded_hops: Vec::new(),
5788-
},
5789-
intro_node_scid: 43,
5782+
},
5783+
RouteHop {
5784+
pubkey: blinded_path.introduction_node_id,
5785+
node_features: NodeFeatures::empty(),
5786+
short_channel_id: 43,
5787+
channel_features: ChannelFeatures::empty(),
57905788
fee_msat: 1,
57915789
cltv_expiry_delta: 0,
5790+
}],
5791+
blinded_tail: Some(BlindedTail {
5792+
hops: blinded_path.blinded_hops,
5793+
blinding_point: blinded_path.blinding_point,
5794+
final_cltv_expiry_delta: 0,
57925795
final_value_msat: 200,
57935796
}),
57945797
};

0 commit comments

Comments
 (0)