Skip to content

Commit e617a39

Browse files
committed
Document Failure Behavior and Persistence for every event type
1 parent 8599bc9 commit e617a39

File tree

1 file changed

+102
-1
lines changed

1 file changed

+102
-1
lines changed

lightning/src/events/mod.rs

+102-1
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ pub enum Event {
551551
/// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
552552
/// counterparty can steal your funds!
553553
///
554+
/// # Failure Behavior and Persistence
555+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
556+
/// returning `Err(ReplayEvent ())`), but won't be persisted across restarts.
557+
///
554558
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
555559
/// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
556560
FundingGenerationReady {
@@ -608,6 +612,10 @@ pub enum Event {
608612
/// # Note
609613
/// This event used to be called `PaymentReceived` in LDK versions 0.0.112 and earlier.
610614
///
615+
/// # Failure Behavior and Persistence
616+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
617+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
618+
///
611619
/// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
612620
/// [`ChannelManager::claim_funds_with_known_custom_tlvs`]: crate::ln::channelmanager::ChannelManager::claim_funds_with_known_custom_tlvs
613621
/// [`FailureCode::InvalidOnionPayload`]: crate::ln::channelmanager::FailureCode::InvalidOnionPayload
@@ -677,6 +685,10 @@ pub enum Event {
677685
/// [`ChannelManager::claim_funds`] twice for the same [`Event::PaymentClaimable`] you may get
678686
/// multiple `PaymentClaimed` events.
679687
///
688+
/// # Failure Behavior and Persistence
689+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
690+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
691+
///
680692
/// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
681693
PaymentClaimed {
682694
/// The node that received the payment.
@@ -716,6 +728,10 @@ pub enum Event {
716728
/// This event will not be generated for onion message forwards; only for sends including
717729
/// replies. Handlers should connect to the node otherwise any buffered messages may be lost.
718730
///
731+
/// # Failure Behavior and Persistence
732+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
733+
/// returning `Err(ReplayEvent ())`), but won't be persisted across restarts.
734+
///
719735
/// [`OnionMessage`]: msgs::OnionMessage
720736
/// [`MessageRouter`]: crate::onion_message::messenger::MessageRouter
721737
/// [`Destination`]: crate::onion_message::messenger::Destination
@@ -730,6 +746,10 @@ pub enum Event {
730746
/// or was explicitly abandoned by [`ChannelManager::abandon_payment`]. This may be for an
731747
/// [`InvoiceRequest`] sent for an [`Offer`] or for a [`Refund`] that hasn't been redeemed.
732748
///
749+
/// # Failure Behavior and Persistence
750+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
751+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
752+
///
733753
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
734754
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
735755
/// [`Offer`]: crate::offers::offer::Offer
@@ -746,6 +766,10 @@ pub enum Event {
746766
/// [`ChannelManager::abandon_payment`] to abandon the associated payment. See those docs for
747767
/// further details.
748768
///
769+
/// # Failure Behavior and Persistence
770+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
771+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
772+
///
749773
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
750774
/// [`Refund`]: crate::offers::refund::Refund
751775
/// [`UserConfig::manually_handle_bolt12_invoices`]: crate::util::config::UserConfig::manually_handle_bolt12_invoices
@@ -768,6 +792,10 @@ pub enum Event {
768792
///
769793
/// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed`
770794
/// event. In this situation, you SHOULD treat this payment as having succeeded.
795+
///
796+
/// # Failure Behavior and Persistence
797+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
798+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
771799
PaymentSent {
772800
/// The `payment_id` passed to [`ChannelManager::send_payment`].
773801
///
@@ -806,6 +834,10 @@ pub enum Event {
806834
/// received and processed. In this case, the [`Event::PaymentFailed`] event MUST be ignored,
807835
/// and the payment MUST be treated as having succeeded.
808836
///
837+
/// # Failure Behavior and Persistence
838+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
839+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
840+
///
809841
/// [`Retry`]: crate::ln::channelmanager::Retry
810842
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
811843
PaymentFailed {
@@ -825,6 +857,10 @@ pub enum Event {
825857
///
826858
/// Always generated after [`Event::PaymentSent`] and thus useful for scoring channels. See
827859
/// [`Event::PaymentSent`] for obtaining the payment preimage.
860+
///
861+
/// # Failure Behavior and Persistence
862+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
863+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
828864
PaymentPathSuccessful {
829865
/// The `payment_id` passed to [`ChannelManager::send_payment`].
830866
///
@@ -850,6 +886,10 @@ pub enum Event {
850886
/// See [`ChannelManager::abandon_payment`] for giving up on this payment before its retries have
851887
/// been exhausted.
852888
///
889+
/// # Failure Behavior and Persistence
890+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
891+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
892+
///
853893
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
854894
PaymentPathFailed {
855895
/// The `payment_id` passed to [`ChannelManager::send_payment`].
@@ -889,6 +929,10 @@ pub enum Event {
889929
error_data: Option<Vec<u8>>,
890930
},
891931
/// Indicates that a probe payment we sent returned successful, i.e., only failed at the destination.
932+
///
933+
/// # Failure Behavior and Persistence
934+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
935+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
892936
ProbeSuccessful {
893937
/// The id returned by [`ChannelManager::send_probe`].
894938
///
@@ -902,6 +946,10 @@ pub enum Event {
902946
path: Path,
903947
},
904948
/// Indicates that a probe payment we sent failed at an intermediary node on the path.
949+
///
950+
/// # Failure Behavior and Persistence
951+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
952+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
905953
ProbeFailed {
906954
/// The id returned by [`ChannelManager::send_probe`].
907955
///
@@ -923,6 +971,10 @@ pub enum Event {
923971
/// Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at
924972
/// a time in the future.
925973
///
974+
/// # Failure Behavior and Persistence
975+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
976+
/// returning `Err(ReplayEvent ())`) and will be regenerated after restarts.
977+
///
926978
/// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
927979
PendingHTLCsForwardable {
928980
/// The minimum amount of time that should be waited prior to calling
@@ -939,6 +991,10 @@ pub enum Event {
939991
/// [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to this event. See
940992
/// their docs for more information.
941993
///
994+
/// # Failure Behavior and Persistence
995+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
996+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
997+
///
942998
/// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
943999
/// [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
9441000
/// [`ChannelManager::forward_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::forward_intercepted_htlc
@@ -974,6 +1030,10 @@ pub enum Event {
9741030
/// You may hand them to the [`OutputSweeper`] utility which will store and (re-)generate spending
9751031
/// transactions for you.
9761032
///
1033+
/// # Failure Behavior and Persistence
1034+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1035+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
1036+
///
9771037
/// [`OutputSweeper`]: crate::util::sweep::OutputSweeper
9781038
SpendableOutputs {
9791039
/// The outputs which you should store as spendable by you.
@@ -985,6 +1045,10 @@ pub enum Event {
9851045
},
9861046
/// This event is generated when a payment has been successfully forwarded through us and a
9871047
/// forwarding fee earned.
1048+
///
1049+
/// # Failure Behavior and Persistence
1050+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1051+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
9881052
PaymentForwarded {
9891053
/// The channel id of the incoming channel between the previous node and us.
9901054
///
@@ -1046,6 +1110,10 @@ pub enum Event {
10461110
/// This event is emitted when the funding transaction has been signed and is broadcast to the
10471111
/// network. For 0conf channels it will be immediately followed by the corresponding
10481112
/// [`Event::ChannelReady`] event.
1113+
///
1114+
/// # Failure Behavior and Persistence
1115+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1116+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
10491117
ChannelPending {
10501118
/// The `channel_id` of the channel that is pending confirmation.
10511119
channel_id: ChannelId,
@@ -1075,6 +1143,10 @@ pub enum Event {
10751143
/// be used. This event is emitted either when the funding transaction has been confirmed
10761144
/// on-chain, or, in case of a 0conf channel, when both parties have confirmed the channel
10771145
/// establishment.
1146+
///
1147+
/// # Failure Behavior and Persistence
1148+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1149+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
10781150
ChannelReady {
10791151
/// The `channel_id` of the channel that is ready.
10801152
channel_id: ChannelId,
@@ -1101,6 +1173,10 @@ pub enum Event {
11011173
///
11021174
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
11031175
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1176+
///
1177+
/// # Failure Behavior and Persistence
1178+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1179+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
11041180
ChannelClosed {
11051181
/// The `channel_id` of the channel which has been closed. Note that on-chain transactions
11061182
/// resolving the channel are likely still awaiting confirmation.
@@ -1135,6 +1211,10 @@ pub enum Event {
11351211
/// inputs for another purpose.
11361212
///
11371213
/// This event is not guaranteed to be generated for channels that are closed due to a restart.
1214+
///
1215+
/// # Failure Behavior and Persistence
1216+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1217+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
11381218
DiscardFunding {
11391219
/// The channel_id of the channel which has been closed.
11401220
channel_id: ChannelId,
@@ -1150,6 +1230,10 @@ pub enum Event {
11501230
/// The event is only triggered when a new open channel request is received and the
11511231
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
11521232
///
1233+
/// # Failure Behavior and Persistence
1234+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1235+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
1236+
///
11531237
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
11541238
/// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
11551239
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
@@ -1206,6 +1290,10 @@ pub enum Event {
12061290
///
12071291
/// This event, however, does not get generated if an HTLC fails to meet the forwarding
12081292
/// requirements (i.e. insufficient fees paid, or a CLTV that is too soon).
1293+
///
1294+
/// # Failure Behavior and Persistence
1295+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1296+
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
12091297
HTLCHandlingFailed {
12101298
/// The channel over which the HTLC was received.
12111299
prev_channel_id: ChannelId,
@@ -1219,13 +1307,21 @@ pub enum Event {
12191307
/// [`ChannelHandshakeConfig::negotiate_anchors_zero_fee_htlc_tx`] config flag is set to true.
12201308
/// It is limited to the scope of channels with anchor outputs.
12211309
///
1310+
/// # Failure Behavior and Persistence
1311+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1312+
/// returning `Err(ReplayEvent ())`), but will only be regenerated as needed after restarts.
1313+
///
12221314
/// [`ChannelHandshakeConfig::negotiate_anchors_zero_fee_htlc_tx`]: crate::util::config::ChannelHandshakeConfig::negotiate_anchors_zero_fee_htlc_tx
12231315
BumpTransaction(BumpTransactionEvent),
12241316
/// We received an onion message that is intended to be forwarded to a peer
12251317
/// that is currently offline. This event will only be generated if the
12261318
/// `OnionMessenger` was initialized with
12271319
/// [`OnionMessenger::new_with_offline_peer_interception`], see its docs.
12281320
///
1321+
/// # Failure Behavior and Persistence
1322+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1323+
/// returning `Err(ReplayEvent ())`), but won't be persisted across restarts.
1324+
///
12291325
/// [`OnionMessenger::new_with_offline_peer_interception`]: crate::onion_message::messenger::OnionMessenger::new_with_offline_peer_interception
12301326
OnionMessageIntercepted {
12311327
/// The node id of the offline peer.
@@ -1239,6 +1335,10 @@ pub enum Event {
12391335
/// initialized with
12401336
/// [`OnionMessenger::new_with_offline_peer_interception`], see its docs.
12411337
///
1338+
/// # Failure Behavior and Persistence
1339+
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
1340+
/// returning `Err(ReplayEvent ())`), but won't be persisted across restarts.
1341+
///
12421342
/// [`OnionMessenger::new_with_offline_peer_interception`]: crate::onion_message::messenger::OnionMessenger::new_with_offline_peer_interception
12431343
OnionMessagePeerConnected {
12441344
/// The node id of the peer we just connected to, who advertises support for
@@ -2335,7 +2435,8 @@ pub trait EventsProvider {
23352435
/// An error type that may be returned to LDK in order to safely abort event handling if it can't
23362436
/// currently succeed (e.g., due to a persistence failure).
23372437
///
2338-
/// LDK will ensure the event is persisted and will eventually be replayed.
2438+
/// Depending on the type, LDK may ensure the event is persisted and will eventually be replayed.
2439+
/// Please refer to the documentation of each [`Event`] variant for more details.
23392440
#[derive(Clone, Copy, Debug)]
23402441
pub struct ReplayEvent();
23412442

0 commit comments

Comments
 (0)