Skip to content

Commit 4299b14

Browse files
f adapt to adding RouteHop for intro node
1 parent f790909 commit 4299b14

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

lightning/src/routing/router.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,7 @@ impl InFlightHtlcs {
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
@@ -303,7 +297,7 @@ pub struct Path {
303297
impl Path {
304298
/// The length of this path, including the hops of its [`Path::blinded_tail`], if any.
305299
pub fn len(&self) -> usize {
306-
self.hops.len() + self.blinded_tail.as_ref().map_or(0, |tail| tail.path.blinded_hops.len())
300+
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
307301
}
308302
}
309303

@@ -2264,7 +2258,7 @@ fn build_route_from_hops_internal<L: Deref>(
22642258

22652259
#[cfg(test)]
22662260
mod tests {
2267-
use crate::blinded_path::BlindedPath;
2261+
use crate::blinded_path::{BlindedHop, BlindedPath};
22682262
use crate::routing::gossip::{NetworkGraph, P2PGossipSync, NodeId, EffectiveCapacity};
22692263
use crate::routing::utxo::UtxoResult;
22702264
use crate::routing::router::{get_route, build_route_from_hops_internal, add_random_cltv_offset, default_node_features,
@@ -5768,8 +5762,14 @@ mod tests {
57685762

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

0 commit comments

Comments
 (0)