Skip to content

Commit 9b76869

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 361ba90 commit 9b76869

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
@@ -425,6 +425,14 @@ enum BackgroundEvent {
425425
ClosingMonitorUpdate((OutPoint, ChannelMonitorUpdate)),
426426
}
427427

428+
pub(crate) enum MonitorUpdateCompletionAction {
429+
/// Indicates that a payment ultimately destined for us was claimed and we should surface an
430+
/// [`events::Event::PaymentClaimed`] to the user iff no such event has already been surfaced.
431+
PaymentClaimed { payment_hash: PaymentHash },
432+
/// Indicates an [`events::Event`] should be surfaced to the user.
433+
SurfaceEvent { event: events::Event },
434+
}
435+
428436
/// State we hold per-peer. In the future we should put channels in here, but for now we only hold
429437
/// the latest Init features we heard from the peer.
430438
struct PeerState {
@@ -4434,6 +4442,29 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44344442
self.our_network_pubkey.clone()
44354443
}
44364444

4445+
fn handle_monitor_update_completion_actions<I: IntoIterator<Item=MonitorUpdateCompletionAction>>(&self, actions: I) {
4446+
let mut actions = actions.into_iter().peekable();
4447+
if actions.peek().is_some() {
4448+
let mut pending_events = self.pending_events.lock().unwrap();
4449+
for action in actions {
4450+
match action {
4451+
MonitorUpdateCompletionAction::PaymentClaimed { payment_hash } => {
4452+
if let Some(PendingClaimingPayment { amount_msat, payment_purpose: purpose, receiver_node_id }) =
4453+
self.pending_claimed_payments.lock().unwrap().remove(&payment_hash)
4454+
{
4455+
pending_events.push(events::Event::PaymentClaimed {
4456+
payment_hash, purpose, amount_msat, receiver_node_id: Some(receiver_node_id),
4457+
});
4458+
}
4459+
},
4460+
MonitorUpdateCompletionAction::SurfaceEvent { event } => {
4461+
pending_events.push(event);
4462+
},
4463+
}
4464+
}
4465+
}
4466+
}
4467+
44374468
/// Handles a channel reentering a functional state, either due to reconnect or a monitor
44384469
/// update completion.
44394470
fn handle_channel_resumption(&self, pending_msg_events: &mut Vec<MessageSendEvent>,

0 commit comments

Comments
 (0)