Skip to content

Commit 48010cb

Browse files
Fix PaymentForwarded fields on restart claim
Previously, we were spuriously using the upstream channel's info when we should've been using the downstream channel's.
1 parent b3b59e6 commit 48010cb

3 files changed

Lines changed: 16 additions & 23 deletions

File tree

lightning/src/ln/channel.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7942,7 +7942,7 @@ where
79427942
/// when reconstructing the set of pending HTLCs when deserializing the `ChannelManager`.
79437943
pub(super) fn inbound_forwarded_htlcs(
79447944
&self,
7945-
) -> impl Iterator<Item = (PaymentHash, HTLCPreviousHopData, u64)> + '_ {
7945+
) -> impl Iterator<Item = (PaymentHash, HTLCPreviousHopData, OutboundHop)> + '_ {
79467946
// We don't want to return an HTLC as needing processing if it already has a resolution that's
79477947
// pending in the holding cell.
79487948
let htlc_resolution_in_holding_cell = |id: u64| -> bool {
@@ -7970,7 +7970,7 @@ where
79707970
phantom_shared_secret,
79717971
trampoline_shared_secret,
79727972
blinded_failure,
7973-
outbound_hop: OutboundHop { amt_msat, .. },
7973+
outbound_hop,
79747974
},
79757975
} => {
79767976
if htlc_resolution_in_holding_cell(htlc.htlc_id) {
@@ -7991,7 +7991,7 @@ where
79917991
counterparty_node_id: Some(counterparty_node_id),
79927992
cltv_expiry: Some(htlc.cltv_expiry),
79937993
};
7994-
Some((htlc.payment_hash, prev_hop_data, *amt_msat))
7994+
Some((htlc.payment_hash, prev_hop_data, *outbound_hop))
79957995
},
79967996
_ => None,
79977997
})

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18610,11 +18610,11 @@ impl<
1861018610
// that it is handled.
1861118611
let mut already_forwarded_htlcs: HashMap<
1861218612
(ChannelId, PaymentHash),
18613-
Vec<(HTLCPreviousHopData, u64)>,
18613+
Vec<(HTLCPreviousHopData, OutboundHop)>,
1861418614
> = new_hash_map();
1861518615
let prune_forwarded_htlc = |already_forwarded_htlcs: &mut HashMap<
1861618616
(ChannelId, PaymentHash),
18617-
Vec<(HTLCPreviousHopData, u64)>,
18617+
Vec<(HTLCPreviousHopData, OutboundHop)>,
1861818618
>,
1861918619
prev_hop: &HTLCPreviousHopData,
1862018620
payment_hash: &PaymentHash| {
@@ -18663,13 +18663,13 @@ impl<
1866318663
.or_insert_with(Vec::new)
1866418664
.push(update_add_htlc);
1866518665
}
18666-
for (payment_hash, prev_hop, outbound_amt_msat) in
18666+
for (payment_hash, prev_hop, next_hop) in
1866718667
funded_chan.inbound_forwarded_htlcs()
1866818668
{
1866918669
already_forwarded_htlcs
1867018670
.entry((prev_hop.channel_id, payment_hash))
1867118671
.or_insert_with(Vec::new)
18672-
.push((prev_hop, outbound_amt_msat));
18672+
.push((prev_hop, next_hop));
1867318673
}
1867418674
}
1867518675
}
@@ -19378,34 +19378,33 @@ impl<
1937819378
if let Some(forwarded_htlcs) =
1937919379
already_forwarded_htlcs.remove(&(*channel_id, payment_hash))
1938019380
{
19381-
for (prev_hop, outbound_amt_msat) in forwarded_htlcs {
19381+
for (prev_hop, next_hop) in forwarded_htlcs {
1938219382
let new_pending_claim =
1938319383
!pending_claims_to_replay.iter().any(|(src, _, _, _, _, _, _, _)| {
1938419384
matches!(src, HTLCSource::PreviousHopData(hop) if hop.htlc_id == prev_hop.htlc_id && hop.channel_id == prev_hop.channel_id)
1938519385
});
1938619386
if new_pending_claim {
19387-
let counterparty_node_id = monitor.get_counterparty_node_id();
1938819387
let is_downstream_closed = channel_manager
1938919388
.per_peer_state
1939019389
.read()
1939119390
.unwrap()
19392-
.get(&counterparty_node_id)
19391+
.get(&next_hop.node_id)
1939319392
.map_or(true, |peer_state_mtx| {
1939419393
!peer_state_mtx
1939519394
.lock()
1939619395
.unwrap()
1939719396
.channel_by_id
19398-
.contains_key(channel_id)
19397+
.contains_key(&next_hop.channel_id)
1939919398
});
1940019399
pending_claims_to_replay.push((
1940119400
HTLCSource::PreviousHopData(prev_hop),
1940219401
payment_preimage,
19403-
outbound_amt_msat,
19402+
next_hop.amt_msat,
1940419403
is_downstream_closed,
19405-
counterparty_node_id,
19406-
monitor.get_funding_txo(),
19407-
*channel_id,
19408-
None,
19404+
next_hop.node_id,
19405+
next_hop.funding_txo,
19406+
next_hop.channel_id,
19407+
Some(next_hop.user_channel_id),
1940919408
));
1941019409
}
1941119410
}

lightning/src/ln/reload_tests.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,14 +1958,8 @@ fn test_reload_node_with_preimage_in_monitor_claims_htlc() {
19581958
);
19591959

19601960
// When the claim is reconstructed during reload, a PaymentForwarded event is generated.
1961-
// This event has next_user_channel_id as None since the outbound HTLC was already removed.
19621961
// Fetching events triggers the pending monitor update (adding preimage) to be applied.
1963-
let events = nodes[1].node.get_and_clear_pending_events();
1964-
assert_eq!(events.len(), 1);
1965-
match &events[0] {
1966-
Event::PaymentForwarded { total_fee_earned_msat: Some(1000), .. } => {},
1967-
_ => panic!("Expected PaymentForwarded event"),
1968-
}
1962+
expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(1000), false, false);
19691963
check_added_monitors(&nodes[1], 1);
19701964

19711965
// Reconnect nodes[1] to nodes[0]. The claim should be in nodes[1]'s holding cell.

0 commit comments

Comments
 (0)