Skip to content

Commit 843b826

Browse files
committed
Document expected call frequency of ChainMonitor::process_pending_events
1 parent 892f8fe commit 843b826

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ impl<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> even
707707
L::Target: Logger,
708708
P::Target: Persist<ChannelSigner>,
709709
{
710+
#[cfg(not(anchors))]
710711
/// Processes [`SpendableOutputs`] events produced from each [`ChannelMonitor`] upon maturity.
711712
///
712713
/// An [`EventHandler`] may safely call back to the provider, though this shouldn't be needed in
@@ -722,6 +723,29 @@ impl<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> even
722723
handler.handle_event(&event);
723724
}
724725
}
726+
#[cfg(anchors)]
727+
/// Processes [`SpendableOutputs`] events produced from each [`ChannelMonitor`] upon maturity.
728+
///
729+
/// For channels featuring anchor outputs, this method will also process [`BumpTransaction`]
730+
/// events produced from each [`ChannelMonitor`] while there is a balance to claim onchain
731+
/// within each channel. As the confirmation of a commitment transaction may be critical to the
732+
/// safety of funds, this method must be invoked frequently, ideally once for every chain tip
733+
/// update (block connected or disconnected).
734+
///
735+
/// An [`EventHandler`] may safely call back to the provider, though this shouldn't be needed in
736+
/// order to handle these events.
737+
///
738+
/// [`SpendableOutputs`]: events::Event::SpendableOutputs
739+
/// [`BumpTransaction`]: events::Event::BumpTransaction
740+
fn process_pending_events<H: Deref>(&self, handler: H) where H::Target: EventHandler {
741+
let mut pending_events = Vec::new();
742+
for monitor_state in self.monitors.read().unwrap().values() {
743+
pending_events.append(&mut monitor_state.monitor.get_and_clear_pending_events());
744+
}
745+
for event in pending_events.drain(..) {
746+
handler.handle_event(&event);
747+
}
748+
}
725749
}
726750

727751
#[cfg(test)]

0 commit comments

Comments
 (0)