Skip to content

Commit cf25c67

Browse files
committed
Introduce get_and_clear_pending_raa_blockers
Note: The `actions_blocking_raa_monitor_updates` list may contain stale entries in the form of `(channel_id, [])`, which do not represent actual dangling actions. To handle this, stale entries are ignored when accumulating pending actions before clearing them. This ensures that the logic focuses only on relevant actions and avoids unnecessary accumulation of already processed data.
1 parent 85d1e5f commit cf25c67

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,11 @@ impl_writeable_tlv_based!(PaymentClaimDetails, {
12291229
});
12301230

12311231
#[derive(Clone)]
1232+
#[cfg(not(any(test, feature = "_test_utils")))]
12321233
pub(crate) struct PendingMPPClaimPointer(Arc<Mutex<PendingMPPClaim>>);
1234+
#[derive(Clone)]
1235+
#[cfg(any(test, feature = "_test_utils"))]
1236+
pub struct PendingMPPClaimPointer(Arc<Mutex<PendingMPPClaim>>);
12331237

12341238
impl PartialEq for PendingMPPClaimPointer {
12351239
fn eq(&self, o: &Self) -> bool { Arc::ptr_eq(&self.0, &o.0) }
@@ -1243,6 +1247,7 @@ impl core::fmt::Debug for PendingMPPClaimPointer {
12431247
}
12441248

12451249
#[derive(Clone, PartialEq, Eq, Debug)]
1250+
#[cfg(not(any(test, feature = "_test_utils")))]
12461251
/// If something is blocked on the completion of an RAA-generated [`ChannelMonitorUpdate`] we track
12471252
/// the blocked action here. See enum variants for more info.
12481253
pub(crate) enum RAAMonitorUpdateBlockingAction {
@@ -1267,6 +1272,32 @@ pub(crate) enum RAAMonitorUpdateBlockingAction {
12671272
}
12681273
}
12691274

1275+
#[derive(Clone, PartialEq, Eq, Debug)]
1276+
#[cfg(any(test, feature = "_test_utils"))]
1277+
/// If something is blocked on the completion of an RAA-generated [`ChannelMonitorUpdate`] we track
1278+
/// the blocked action here. See enum variants for more info.
1279+
pub enum RAAMonitorUpdateBlockingAction {
1280+
/// A forwarded payment was claimed. We block the downstream channel completing its monitor
1281+
/// update which removes the HTLC preimage until the upstream channel has gotten the preimage
1282+
/// durably to disk.
1283+
ForwardedPaymentInboundClaim {
1284+
/// The upstream channel ID (i.e. the inbound edge).
1285+
channel_id: ChannelId,
1286+
/// The HTLC ID on the inbound edge.
1287+
htlc_id: u64,
1288+
},
1289+
/// We claimed an MPP payment across multiple channels. We have to block removing the payment
1290+
/// preimage from any monitor until the last monitor is updated to contain the payment
1291+
/// preimage. Otherwise we may not be able to replay the preimage on the monitor(s) that
1292+
/// weren't updated on startup.
1293+
///
1294+
/// This variant is *not* written to disk, instead being inferred from [`ChannelMonitor`]
1295+
/// state.
1296+
ClaimedMPPPayment {
1297+
pending_claim: PendingMPPClaimPointer,
1298+
}
1299+
}
1300+
12701301
impl RAAMonitorUpdateBlockingAction {
12711302
fn from_prev_hop_data(prev_hop: &HTLCPreviousHopData) -> Self {
12721303
Self::ForwardedPaymentInboundClaim {
@@ -10600,6 +10631,29 @@ where
1060010631
self.pending_outbound_payments.clear_pending_payments()
1060110632
}
1060210633

10634+
#[cfg(any(test, feature = "_test_utils"))]
10635+
pub fn get_and_clear_pending_raa_blockers(
10636+
&self,
10637+
) -> Vec<(ChannelId, Vec<RAAMonitorUpdateBlockingAction>)> {
10638+
let per_peer_state = self.per_peer_state.read().unwrap();
10639+
let mut pending_blockers = Vec::new();
10640+
10641+
for (_peer_pubkey, peer_state_mutex) in per_peer_state.iter() {
10642+
let mut peer_state = peer_state_mutex.lock().unwrap();
10643+
10644+
for (chan_id, actions) in peer_state.actions_blocking_raa_monitor_updates.iter() {
10645+
// Only collect the non-empty actions into `pending_blockers`.
10646+
if !actions.is_empty() {
10647+
pending_blockers.push((chan_id.clone(), actions.clone()));
10648+
}
10649+
}
10650+
10651+
peer_state.actions_blocking_raa_monitor_updates.clear();
10652+
}
10653+
10654+
pending_blockers
10655+
}
10656+
1060310657
/// When something which was blocking a channel from updating its [`ChannelMonitor`] (e.g. an
1060410658
/// [`Event`] being handled) completes, this should be called to restore the channel to normal
1060510659
/// operation. It will double-check that nothing *else* is also blocking the same channel from

0 commit comments

Comments
 (0)