From: Matt Corallo Date: Fri, 14 Jun 2024 14:10:38 +0000 (+0000) Subject: Use a struct to track MPP parts pending claiming X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=d9175f454bfce665af32c9a3ec54482fbb6a484d;p=rust-lightning 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. --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 3b3a0e37e..c1750c5af 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -1062,10 +1062,20 @@ impl_writeable_tlv_based_enum!(EventCompletionAction, } ); +#[derive(Clone, Debug, PartialEq, Eq)] +/// The source of an HTLC which is being claimed as a part of an incoming payment. Each part is +/// tracked in [`PendingMPPClaim`]. +struct MPPClaimHTLCSource { + counterparty_node_id: PublicKey, + funding_txo: OutPoint, + channel_id: ChannelId, + htlc_id: u64, +} + #[derive(Debug)] pub(crate) struct PendingMPPClaim { - channels_without_preimage: Vec<(PublicKey, OutPoint, ChannelId, u64)>, - channels_with_preimage: Vec<(PublicKey, OutPoint, ChannelId)>, + channels_without_preimage: Vec, + channels_with_preimage: Vec, } #[derive(Clone)] @@ -6765,8 +6775,12 @@ where let pending_mpp_claim_ptr_opt = if sources.len() > 1 { let channels_without_preimage = sources.iter().filter_map(|htlc| { if let Some(cp_id) = htlc.prev_hop.counterparty_node_id { - let prev_hop = &htlc.prev_hop; - Some((cp_id, prev_hop.outpoint, prev_hop.channel_id, prev_hop.htlc_id)) + Some(MPPClaimHTLCSource { + counterparty_node_id: cp_id, + funding_txo: htlc.prev_hop.outpoint, + channel_id: htlc.prev_hop.channel_id, + htlc_id: htlc.prev_hop.htlc_id, + }) } else { None } @@ -7184,15 +7198,25 @@ where if *pending_claim == claim_ptr { let mut pending_claim_state_lock = pending_claim.0.lock().unwrap(); let pending_claim_state = &mut *pending_claim_state_lock; - pending_claim_state.channels_without_preimage.retain(|(cp, outp, cid, hid)| { - if *cp == counterparty_node_id && *cid == chan_id && *hid == htlc_id { - pending_claim_state.channels_with_preimage.push((*cp, *outp, *cid)); + pending_claim_state.channels_without_preimage.retain(|htlc_info| { + let this_claim = + htlc_info.counterparty_node_id == counterparty_node_id + && htlc_info.channel_id == chan_id + && htlc_info.htlc_id == htlc_id; + if this_claim { + pending_claim_state.channels_with_preimage.push(htlc_info.clone()); false } else { true } }); if pending_claim_state.channels_without_preimage.is_empty() { - for (cp, outp, cid) in pending_claim_state.channels_with_preimage.iter() { - freed_channels.push((*cp, *outp, *cid, blocker.clone())); + for htlc_info in pending_claim_state.channels_with_preimage.iter() { + let freed_chan = ( + htlc_info.counterparty_node_id, + htlc_info.funding_txo, + htlc_info.channel_id, + blocker.clone() + ); + freed_channels.push(freed_chan); } } !pending_claim_state.channels_without_preimage.is_empty()