Skip to content

Commit 7b1ee8f

Browse files
committed
Add support for handling "actions" after a monitor update completes
This adds a new enum, `MonitorUpdateCompletionAction` and a method to execute the "actions". They are intended to be done once a (potentially-async) `ChannelMonitorUpdate` persistence completes, however this behavior will be implemented in a future PR. For now, this adds the relevant infrastructure which will allow us to prepare `claim_funds` for better monitor async handling.
1 parent 28a0fc0 commit 7b1ee8f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,14 @@ enum BackgroundEvent {
471471
ClosingMonitorUpdate((OutPoint, ChannelMonitorUpdate)),
472472
}
473473

474+
pub(crate) enum MonitorUpdateCompletionAction {
475+
/// Indicates that a payment ultimately destined for us was claimed and we should emit an
476+
/// [`events::Event::PaymentClaimed`] to the user iff no such event has already been surfaced.
477+
PaymentClaimed { payment_hash: PaymentHash },
478+
/// Indicates an [`events::Event`] should be surfaced to the user.
479+
EmitEvent { event: events::Event },
480+
}
481+
474482
/// State we hold per-peer. In the future we should put channels in here, but for now we only hold
475483
/// the latest Init features we heard from the peer.
476484
struct PeerState {
@@ -4583,6 +4591,29 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
45834591
self.our_network_pubkey.clone()
45844592
}
45854593

4594+
fn handle_monitor_update_completion_actions<I: IntoIterator<Item=MonitorUpdateCompletionAction>>(&self, actions: I) {
4595+
let mut actions = actions.into_iter().peekable();
4596+
if actions.peek().is_none() { return; }
4597+
4598+
let mut pending_events = self.pending_events.lock().unwrap();
4599+
for action in actions {
4600+
match action {
4601+
MonitorUpdateCompletionAction::PaymentClaimed { payment_hash } => {
4602+
if let Some(ClaimingPayment { amount_msat, payment_purpose: purpose, receiver_node_id }) =
4603+
self.claimable_payments.lock().unwrap().pending_claimed_payments.remove(&payment_hash)
4604+
{
4605+
pending_events.push(events::Event::PaymentClaimed {
4606+
payment_hash, purpose, amount_msat, receiver_node_id: Some(receiver_node_id),
4607+
});
4608+
}
4609+
},
4610+
MonitorUpdateCompletionAction::EmitEvent { event } => {
4611+
pending_events.push(event);
4612+
},
4613+
}
4614+
}
4615+
}
4616+
45864617
/// Handles a channel reentering a functional state, either due to reconnect or a monitor
45874618
/// update completion.
45884619
fn handle_channel_resumption(&self, pending_msg_events: &mut Vec<MessageSendEvent>,

0 commit comments

Comments
 (0)