Skip to content

Commit 9b47af9

Browse files
Account for Path::blinded_tail in InflightHtlcs::process_path
1 parent fcdb8cb commit 9b47af9

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

lightning/src/routing/router.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ impl InFlightHtlcs {
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) {
174174
if path.hops.is_empty() { return };
175+
176+
let mut cumulative_msat = 0;
177+
if let Some(tail) = &path.blinded_tail {
178+
cumulative_msat += tail.final_value_msat;
179+
}
180+
175181
// total_inflight_map needs to be direction-sensitive when keeping track of the HTLC value
176182
// that is held up. However, the `hops` array, which is a path returned by `find_route` in
177183
// the router excludes the payer node. In the following lines, the payer's information is
@@ -180,7 +186,6 @@ impl InFlightHtlcs {
180186
let reversed_hops_with_payer = path.hops.iter().rev().skip(1)
181187
.map(|hop| hop.pubkey)
182188
.chain(core::iter::once(payer_node_id));
183-
let mut cumulative_msat = 0;
184189

185190
// Taking the reversed vector from above, we zip it with just the reversed hops list to
186191
// work "backwards" of the given path, since the last hop's `fee_msat` actually represents
@@ -2266,7 +2271,7 @@ mod tests {
22662271
use crate::routing::gossip::{NetworkGraph, P2PGossipSync, NodeId, EffectiveCapacity};
22672272
use crate::routing::utxo::UtxoResult;
22682273
use crate::routing::router::{get_route, build_route_from_hops_internal, add_random_cltv_offset, default_node_features,
2269-
BlindedTail, Path, PaymentParameters, Route, RouteHint, RouteHintHop, RouteHop, RoutingFees,
2274+
BlindedTail, InFlightHtlcs, Path, PaymentParameters, Route, RouteHint, RouteHintHop, RouteHop, RoutingFees,
22702275
DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, MAX_PATH_LENGTH_ESTIMATE};
22712276
use crate::routing::scoring::{ChannelUsage, FixedPenaltyScorer, Score, ProbabilisticScorer, ProbabilisticScoringParameters};
22722277
use crate::routing::test_utils::{add_channel, add_or_update_node, build_graph, build_line_graph, id_to_feature_flags, get_nodes, update_channel};
@@ -5827,6 +5832,45 @@ mod tests {
58275832
assert_eq!(decoded_route.paths[0].blinded_tail, route.paths[0].blinded_tail);
58285833
assert_eq!(decoded_route.paths[1].blinded_tail, route.paths[1].blinded_tail);
58295834
}
5835+
5836+
#[test]
5837+
fn blinded_path_inflight_processing() {
5838+
// Ensure we'll score the channel that's inbound to a blinded path's introduction node, and
5839+
// account for the blinded tail's final amount_msat.
5840+
let mut inflight_htlcs = InFlightHtlcs::new();
5841+
let blinded_path = BlindedPath {
5842+
introduction_node_id: ln_test_utils::pubkey(43),
5843+
blinding_point: ln_test_utils::pubkey(48),
5844+
blinded_hops: vec![BlindedHop { blinded_node_id: ln_test_utils::pubkey(49), encrypted_payload: Vec::new() }],
5845+
};
5846+
let path = Path {
5847+
hops: vec![RouteHop {
5848+
pubkey: ln_test_utils::pubkey(42),
5849+
node_features: NodeFeatures::empty(),
5850+
short_channel_id: 42,
5851+
channel_features: ChannelFeatures::empty(),
5852+
fee_msat: 100,
5853+
cltv_expiry_delta: 0,
5854+
},
5855+
RouteHop {
5856+
pubkey: blinded_path.introduction_node_id,
5857+
node_features: NodeFeatures::empty(),
5858+
short_channel_id: 43,
5859+
channel_features: ChannelFeatures::empty(),
5860+
fee_msat: 1,
5861+
cltv_expiry_delta: 0,
5862+
}],
5863+
blinded_tail: Some(BlindedTail {
5864+
hops: blinded_path.blinded_hops,
5865+
blinding_point: blinded_path.blinding_point,
5866+
final_cltv_expiry_delta: 0,
5867+
final_value_msat: 200,
5868+
}),
5869+
};
5870+
inflight_htlcs.process_path(&path, ln_test_utils::pubkey(44));
5871+
assert_eq!(*inflight_htlcs.0.get(&(42, true)).unwrap(), 301);
5872+
assert_eq!(*inflight_htlcs.0.get(&(43, false)).unwrap(), 201);
5873+
}
58305874
}
58315875

58325876
#[cfg(all(test, not(feature = "no-std")))]

0 commit comments

Comments
 (0)