Skip to content

Commit f1acbfd

Browse files
committed
f - Rewrite EventsProvider docs
1 parent 0587d0a commit f1acbfd

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ where C::Target: chain::Filter,
308308
}
309309
}
310310

311+
/// Provides [`SpendableOutputs`] events produced from each [`ChannelMonitor`] upon maturity.
312+
///
313+
/// [`SpendableOutputs`]: events::Event::SpendableOutputs
311314
impl<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> events::EventsProvider for ChainMonitor<ChannelSigner, C, T, F, L, P>
312315
where C::Target: chain::Filter,
313316
T::Target: BroadcasterInterface,

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3572,6 +3572,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> MessageSend
35723572
}
35733573
}
35743574

3575+
/// Provides events that must be periodically handled.
3576+
///
3577+
/// An [`EventHandler`] may safely call back to the provider in order to handle an event. However,
3578+
/// it must not call [`Writeable::write`] as doing so would result in a deadlock.
3579+
///
3580+
/// Pending events are persisted as part of [`ChannelManager`]. While these events are cleared when
3581+
/// processed, an [`EventHandler`] must be able to handle previously seen events when restarting
3582+
/// from an old state.
35753583
impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> EventsProvider for ChannelManager<Signer, M, T, K, F, L>
35763584
where
35773585
M::Target: chain::Watch<Signer>,

lightning/src/util/events.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,25 @@ pub trait MessageSendEventsProvider {
383383

384384
/// A trait indicating an object may generate events.
385385
///
386-
/// Events are processed by a handler given to [`process_pending_events`]. Therefore, implementors
387-
/// should be mindful to avoid lock reentrancy if a handler may call back into the provider.
386+
/// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
387+
///
388+
/// # Implementations
389+
///
390+
/// See [`process_pending_events`] for expectations around event processing.
391+
///
392+
/// When implementing this trait, be mindful that handlers may call back into the provider and thus
393+
/// deadlocking must be avoided. Therefore, be sure to document expectations around how the handler
394+
/// may safely use the provider.
395+
///
396+
/// # Uses
397+
///
398+
/// When using this trait, [`process_pending_events`] will call the [`handle_event`] for each
399+
/// pending event since the last invocation. The handler must either act upon the event immediately
400+
/// or preserve it for later handling. Be sure to consult the provider's trait documentation on the
401+
/// implication of processing events and how a handler itself may safely use the provider.
388402
///
389403
/// [`process_pending_events`]: Self::process_pending_events
404+
/// [`handle_event`]: EventHandler::handle_event
390405
pub trait EventsProvider {
391406
/// Processes any events generated since the last call using the given event handler.
392407
///
@@ -400,8 +415,7 @@ pub trait EventsProvider {
400415
pub trait EventHandler {
401416
/// Handles the given [`Event`].
402417
///
403-
/// See [`EventsProvider::process_pending_events`] for details that must be considered when
404-
/// implementing this method.
418+
/// See [`EventsProvider`] for details that must be considered when implementing this method.
405419
fn handle_event(&self, event: Event);
406420
}
407421

0 commit comments

Comments
 (0)