Skip to content

Commit d9175f4

Browse files
committed
Use a struct to track MPP parts pending claiming
When we started tracking which channels had MPP parts claimed durably on-disk in their `ChannelMonitor`, we did so with a tuple. This was fine in that it was only ever accessed in two places, but as we will start tracking it through to the `ChannelMonitor`s themselves in the coming commit(s), it is useful to have it in a struct instead.
1 parent a65d37b commit d9175f4

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,10 +1062,20 @@ impl_writeable_tlv_based_enum!(EventCompletionAction,
10621062
}
10631063
);
10641064

1065+
#[derive(Clone, Debug, PartialEq, Eq)]
1066+
/// The source of an HTLC which is being claimed as a part of an incoming payment. Each part is
1067+
/// tracked in [`PendingMPPClaim`].
1068+
struct MPPClaimHTLCSource {
1069+
counterparty_node_id: PublicKey,
1070+
funding_txo: OutPoint,
1071+
channel_id: ChannelId,
1072+
htlc_id: u64,
1073+
}
1074+
10651075
#[derive(Debug)]
10661076
pub(crate) struct PendingMPPClaim {
1067-
channels_without_preimage: Vec<(PublicKey, OutPoint, ChannelId, u64)>,
1068-
channels_with_preimage: Vec<(PublicKey, OutPoint, ChannelId)>,
1077+
channels_without_preimage: Vec<MPPClaimHTLCSource>,
1078+
channels_with_preimage: Vec<MPPClaimHTLCSource>,
10691079
}
10701080

10711081
#[derive(Clone)]
@@ -6765,8 +6775,12 @@ where
67656775
let pending_mpp_claim_ptr_opt = if sources.len() > 1 {
67666776
let channels_without_preimage = sources.iter().filter_map(|htlc| {
67676777
if let Some(cp_id) = htlc.prev_hop.counterparty_node_id {
6768-
let prev_hop = &htlc.prev_hop;
6769-
Some((cp_id, prev_hop.outpoint, prev_hop.channel_id, prev_hop.htlc_id))
6778+
Some(MPPClaimHTLCSource {
6779+
counterparty_node_id: cp_id,
6780+
funding_txo: htlc.prev_hop.outpoint,
6781+
channel_id: htlc.prev_hop.channel_id,
6782+
htlc_id: htlc.prev_hop.htlc_id,
6783+
})
67706784
} else {
67716785
None
67726786
}
@@ -7184,15 +7198,25 @@ where
71847198
if *pending_claim == claim_ptr {
71857199
let mut pending_claim_state_lock = pending_claim.0.lock().unwrap();
71867200
let pending_claim_state = &mut *pending_claim_state_lock;
7187-
pending_claim_state.channels_without_preimage.retain(|(cp, outp, cid, hid)| {
7188-
if *cp == counterparty_node_id && *cid == chan_id && *hid == htlc_id {
7189-
pending_claim_state.channels_with_preimage.push((*cp, *outp, *cid));
7201+
pending_claim_state.channels_without_preimage.retain(|htlc_info| {
7202+
let this_claim =
7203+
htlc_info.counterparty_node_id == counterparty_node_id
7204+
&& htlc_info.channel_id == chan_id
7205+
&& htlc_info.htlc_id == htlc_id;
7206+
if this_claim {
7207+
pending_claim_state.channels_with_preimage.push(htlc_info.clone());
71907208
false
71917209
} else { true }
71927210
});
71937211
if pending_claim_state.channels_without_preimage.is_empty() {
7194-
for (cp, outp, cid) in pending_claim_state.channels_with_preimage.iter() {
7195-
freed_channels.push((*cp, *outp, *cid, blocker.clone()));
7212+
for htlc_info in pending_claim_state.channels_with_preimage.iter() {
7213+
let freed_chan = (
7214+
htlc_info.counterparty_node_id,
7215+
htlc_info.funding_txo,
7216+
htlc_info.channel_id,
7217+
blocker.clone()
7218+
);
7219+
freed_channels.push(freed_chan);
71967220
}
71977221
}
71987222
!pending_claim_state.channels_without_preimage.is_empty()

0 commit comments

Comments
 (0)