Skip to content

Commit bffbd37

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 27e59ef commit bffbd37

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,16 @@ 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 if we haven't yet generated such an event for
477+
/// this payment. Note that this is only best-effort. On restart it's possible such a duplicate
478+
/// event can be generated.
479+
PaymentClaimed { payment_hash: PaymentHash },
480+
/// Indicates an [`events::Event`] should be surfaced to the user.
481+
EmitEvent { event: events::Event },
482+
}
483+
474484
/// State we hold per-peer. In the future we should put channels in here, but for now we only hold
475485
/// the latest Init features we heard from the peer.
476486
struct PeerState {
@@ -4582,6 +4592,24 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
45824592
self.our_network_pubkey.clone()
45834593
}
45844594

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

0 commit comments

Comments
 (0)