Skip to content

Commit 934be71

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 77172ee commit 934be71

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
@@ -453,6 +453,14 @@ enum BackgroundEvent {
453453
ClosingMonitorUpdate((OutPoint, ChannelMonitorUpdate)),
454454
}
455455

456+
pub(crate) enum MonitorUpdateCompletionAction {
457+
/// Indicates that a payment ultimately destined for us was claimed and we should surface an
458+
/// [`events::Event::PaymentClaimed`] to the user iff no such event has already been surfaced.
459+
PaymentClaimed { payment_hash: PaymentHash },
460+
/// Indicates an [`events::Event`] should be surfaced to the user.
461+
SurfaceEvent { event: events::Event },
462+
}
463+
456464
/// State we hold per-peer. In the future we should put channels in here, but for now we only hold
457465
/// the latest Init features we heard from the peer.
458466
struct PeerState {
@@ -4574,6 +4582,29 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
45744582
self.our_network_pubkey.clone()
45754583
}
45764584

4585+
fn handle_monitor_update_completion_actions<I: IntoIterator<Item=MonitorUpdateCompletionAction>>(&self, actions: I) {
4586+
let mut actions = actions.into_iter().peekable();
4587+
if actions.peek().is_some() {
4588+
let mut pending_events = self.pending_events.lock().unwrap();
4589+
for action in actions {
4590+
match action {
4591+
MonitorUpdateCompletionAction::PaymentClaimed { payment_hash } => {
4592+
if let Some(PendingClaimingPayment { amount_msat, payment_purpose: purpose, receiver_node_id }) =
4593+
self.pending_claimed_payments.lock().unwrap().remove(&payment_hash)
4594+
{
4595+
pending_events.push(events::Event::PaymentClaimed {
4596+
payment_hash, purpose, amount_msat, receiver_node_id: Some(receiver_node_id),
4597+
});
4598+
}
4599+
},
4600+
MonitorUpdateCompletionAction::SurfaceEvent { event } => {
4601+
pending_events.push(event);
4602+
},
4603+
}
4604+
}
4605+
}
4606+
}
4607+
45774608
/// Handles a channel reentering a functional state, either due to reconnect or a monitor
45784609
/// update completion.
45794610
fn handle_channel_resumption(&self, pending_msg_events: &mut Vec<MessageSendEvent>,

0 commit comments

Comments
 (0)