Skip to content

Commit b9ca90e

Browse files
Fix InflightHtlcs::process_path to process the whole Path
1 parent 7aba42b commit b9ca90e

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5698,7 +5698,7 @@ where
56985698
for chan in peer_state.channel_by_id.values() {
56995699
for (htlc_source, _) in chan.inflight_htlc_sources() {
57005700
if let HTLCSource::OutboundRoute { path, .. } = htlc_source {
5701-
inflight_htlcs.process_path(&path.hops, self.get_our_node_id()); // fixed in upcoming commit
5701+
inflight_htlcs.process_path(path, self.get_our_node_id());
57025702
}
57035703
}
57045704
}

lightning/src/routing/router.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,22 +170,33 @@ impl InFlightHtlcs {
170170
pub fn new() -> Self { InFlightHtlcs(HashMap::new()) }
171171

172172
/// Takes in a path with payer's node id and adds the path's details to `InFlightHtlcs`.
173-
pub fn process_path(&mut self, path: &[RouteHop], payer_node_id: PublicKey) {
174-
if path.is_empty() { return };
173+
pub fn process_path(&mut self, path: &Path, payer_node_id: PublicKey) {
174+
if path.len() == 0 { return };
175+
176+
let mut cumulative_msat = 0;
177+
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);
185+
}
186+
175187
// total_inflight_map needs to be direction-sensitive when keeping track of the HTLC value
176188
// that is held up. However, the `hops` array, which is a path returned by `find_route` in
177189
// the router excludes the payer node. In the following lines, the payer's information is
178190
// hardcoded with an inflight value of 0 so that we can correctly represent the first hop
179191
// in our sliding window of two.
180-
let reversed_hops_with_payer = path.iter().rev().skip(1)
192+
let reversed_hops_with_payer = path.hops.iter().rev().skip(1)
181193
.map(|hop| hop.pubkey)
182194
.chain(core::iter::once(payer_node_id));
183-
let mut cumulative_msat = 0;
184195

185196
// Taking the reversed vector from above, we zip it with just the reversed hops list to
186197
// work "backwards" of the given path, since the last hop's `fee_msat` actually represents
187198
// the total amount sent.
188-
for (next_hop, prev_hop) in path.iter().rev().zip(reversed_hops_with_payer) {
199+
for (next_hop, prev_hop) in path.hops.iter().rev().zip(reversed_hops_with_payer) {
189200
cumulative_msat += next_hop.fee_msat;
190201
self.0
191202
.entry((next_hop.short_channel_id, NodeId::from_pubkey(&prev_hop) < NodeId::from_pubkey(&next_hop.pubkey)))

0 commit comments

Comments
 (0)