1 // This file is Copyright its original authors, visible in version control
4 // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5 // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7 // You may not use this file except in accordance with one or both of these
10 //! Events are returned from various bits in the library which indicate some action must be taken
13 //! Because we don't have a built-in runtime, it's up to the client to call events at a time in the
14 //! future, as well as generate and broadcast funding transactions handle payment preimages and a
17 pub mod bump_transaction;
19 pub use bump_transaction::BumpTransactionEvent;
21 use crate::sign::SpendableOutputDescriptor;
22 use crate::ln::channelmanager::{InterceptId, PaymentId, RecipientOnionFields};
23 use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
24 use crate::ln::features::ChannelTypeFeatures;
26 use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
27 use crate::routing::gossip::NetworkUpdate;
28 use crate::util::errors::APIError;
29 use crate::util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable, RequiredWrapper, UpgradableRequired, WithoutLength};
30 use crate::util::string::UntrustedString;
31 use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters};
33 use bitcoin::{PackedLockTime, Transaction, OutPoint};
34 use bitcoin::blockdata::script::Script;
35 use bitcoin::hashes::Hash;
36 use bitcoin::hashes::sha256::Hash as Sha256;
37 use bitcoin::secp256k1::PublicKey;
39 use crate::prelude::*;
40 use core::time::Duration;
44 /// Some information provided on receipt of payment depends on whether the payment received is a
45 /// spontaneous payment or a "conventional" lightning payment that's paying an invoice.
46 #[derive(Clone, Debug, PartialEq, Eq)]
47 pub enum PaymentPurpose {
48 /// Information for receiving a payment that we generated an invoice for.
50 /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via
51 /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
52 /// [`ChannelManager::claim_funds`].
54 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
55 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
56 payment_preimage: Option<PaymentPreimage>,
57 /// The "payment secret". This authenticates the sender to the recipient, preventing a
58 /// number of deanonymization attacks during the routing process.
59 /// It is provided here for your reference, however its accuracy is enforced directly by
60 /// [`ChannelManager`] using the values you previously provided to
61 /// [`ChannelManager::create_inbound_payment`] or
62 /// [`ChannelManager::create_inbound_payment_for_hash`].
64 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
65 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
66 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
67 payment_secret: PaymentSecret,
69 /// Because this is a spontaneous payment, the payer generated their own preimage rather than us
70 /// (the payee) providing a preimage.
71 SpontaneousPayment(PaymentPreimage),
74 impl_writeable_tlv_based_enum!(PaymentPurpose,
75 (0, InvoicePayment) => {
76 (0, payment_preimage, option),
77 (2, payment_secret, required),
79 (2, SpontaneousPayment)
82 /// When the payment path failure took place and extra details about it. [`PathFailure::OnPath`] may
83 /// contain a [`NetworkUpdate`] that needs to be applied to the [`NetworkGraph`].
85 /// [`NetworkUpdate`]: crate::routing::gossip::NetworkUpdate
86 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
87 #[derive(Clone, Debug, Eq, PartialEq)]
88 pub enum PathFailure {
89 /// We failed to initially send the payment and no HTLC was committed to. Contains the relevant
92 /// The error surfaced from initial send.
95 /// A hop on the path failed to forward our payment.
97 /// If present, this [`NetworkUpdate`] should be applied to the [`NetworkGraph`] so that routing
98 /// decisions can take into account the update.
100 /// [`NetworkUpdate`]: crate::routing::gossip::NetworkUpdate
101 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
102 network_update: Option<NetworkUpdate>,
106 impl_writeable_tlv_based_enum_upgradable!(PathFailure,
108 (0, network_update, upgradable_option),
110 (2, InitialSend) => {
111 (0, err, upgradable_required),
115 #[derive(Clone, Debug, PartialEq, Eq)]
116 /// The reason the channel was closed. See individual variants for more details.
117 pub enum ClosureReason {
118 /// Closure generated from receiving a peer error message.
120 /// Our counterparty may have broadcasted their latest commitment state, and we have
122 CounterpartyForceClosed {
123 /// The error which the peer sent us.
125 /// Be careful about printing the peer_msg, a well-crafted message could exploit
126 /// a security vulnerability in the terminal emulator or the logging subsystem.
127 /// To be safe, use `Display` on `UntrustedString`
129 /// [`UntrustedString`]: crate::util::string::UntrustedString
130 peer_msg: UntrustedString,
132 /// Closure generated from [`ChannelManager::force_close_channel`], called by the user.
134 /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
136 /// The channel was closed after negotiating a cooperative close and we've now broadcasted
137 /// the cooperative close transaction. Note the shutdown may have been initiated by us.
138 //TODO: split between CounterpartyInitiated/LocallyInitiated
140 /// A commitment transaction was confirmed on chain, closing the channel. Most likely this
141 /// commitment transaction came from our counterparty, but it may also have come from
142 /// a copy of our own `ChannelMonitor`.
143 CommitmentTxConfirmed,
144 /// The funding transaction failed to confirm in a timely manner on an inbound channel.
146 /// Closure generated from processing an event, likely a HTLC forward/relay/reception.
148 /// A developer-readable error message which we generated.
151 /// The peer disconnected prior to funding completing. In this case the spec mandates that we
152 /// forget the channel entirely - we can attempt again if the peer reconnects.
154 /// This includes cases where we restarted prior to funding completion, including prior to the
155 /// initial [`ChannelMonitor`] persistence completing.
157 /// In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the
158 /// peer because of mutual incompatibility between us and our channel counterparty.
160 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
162 /// Closure generated from `ChannelManager::read` if the [`ChannelMonitor`] is newer than
163 /// the [`ChannelManager`] deserialized.
165 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
166 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
167 OutdatedChannelManager,
168 /// The counterparty requested a cooperative close of a channel that had not been funded yet.
169 /// The channel has been immediately closed.
170 CounterpartyCoopClosedUnfundedChannel,
173 impl core::fmt::Display for ClosureReason {
174 fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
175 f.write_str("Channel closed because ")?;
177 ClosureReason::CounterpartyForceClosed { peer_msg } => {
178 f.write_fmt(format_args!("counterparty force-closed with message: {}", peer_msg))
180 ClosureReason::HolderForceClosed => f.write_str("user manually force-closed the channel"),
181 ClosureReason::CooperativeClosure => f.write_str("the channel was cooperatively closed"),
182 ClosureReason::CommitmentTxConfirmed => f.write_str("commitment or closing transaction was confirmed on chain."),
183 ClosureReason::FundingTimedOut => write!(f, "funding transaction failed to confirm within {} blocks", FUNDING_CONF_DEADLINE_BLOCKS),
184 ClosureReason::ProcessingError { err } => {
185 f.write_str("of an exception: ")?;
188 ClosureReason::DisconnectedPeer => f.write_str("the peer disconnected prior to the channel being funded"),
189 ClosureReason::OutdatedChannelManager => f.write_str("the ChannelManager read from disk was stale compared to ChannelMonitor(s)"),
190 ClosureReason::CounterpartyCoopClosedUnfundedChannel => f.write_str("the peer requested the unfunded channel be closed"),
195 impl_writeable_tlv_based_enum_upgradable!(ClosureReason,
196 (0, CounterpartyForceClosed) => { (1, peer_msg, required) },
197 (1, FundingTimedOut) => {},
198 (2, HolderForceClosed) => {},
199 (6, CommitmentTxConfirmed) => {},
200 (4, CooperativeClosure) => {},
201 (8, ProcessingError) => { (1, err, required) },
202 (10, DisconnectedPeer) => {},
203 (12, OutdatedChannelManager) => {},
204 (13, CounterpartyCoopClosedUnfundedChannel) => {},
207 /// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
208 #[derive(Clone, Debug, PartialEq, Eq)]
209 pub enum HTLCDestination {
210 /// We tried forwarding to a channel but failed to do so. An example of such an instance is when
211 /// there is insufficient capacity in our outbound channel.
213 /// The `node_id` of the next node. For backwards compatibility, this field is
214 /// marked as optional, versions prior to 0.0.110 may not always be able to provide
215 /// counterparty node information.
216 node_id: Option<PublicKey>,
217 /// The outgoing `channel_id` between us and the next node.
218 channel_id: [u8; 32],
220 /// Scenario where we are unsure of the next node to forward the HTLC to.
222 /// Short channel id we are requesting to forward an HTLC to.
223 requested_forward_scid: u64,
225 /// We couldn't forward to the outgoing scid. An example would be attempting to send a duplicate
228 /// Short channel id we are requesting to forward an HTLC to.
229 requested_forward_scid: u64
231 /// Failure scenario where an HTLC may have been forwarded to be intended for us,
232 /// but is invalid for some reason, so we reject it.
234 /// Some of the reasons may include:
236 /// * Excess HTLCs for a payment that we have already fully received, over-paying for the
238 /// * The counterparty node modified the HTLC in transit,
239 /// * A probing attack where an intermediary node is trying to detect if we are the ultimate
240 /// recipient for a payment.
242 /// The payment hash of the payment we attempted to process.
243 payment_hash: PaymentHash
247 impl_writeable_tlv_based_enum_upgradable!(HTLCDestination,
248 (0, NextHopChannel) => {
249 (0, node_id, required),
250 (2, channel_id, required),
252 (1, InvalidForward) => {
253 (0, requested_forward_scid, required),
255 (2, UnknownNextHop) => {
256 (0, requested_forward_scid, required),
258 (4, FailedPayment) => {
259 (0, payment_hash, required),
263 /// Will be used in [`Event::HTLCIntercepted`] to identify the next hop in the HTLC's path.
264 /// Currently only used in serialization for the sake of maintaining compatibility. More variants
265 /// will be added for general-purpose HTLC forward intercepts as well as trampoline forward
266 /// intercepts in upcoming work.
267 enum InterceptNextHop {
269 requested_next_hop_scid: u64,
273 impl_writeable_tlv_based_enum!(InterceptNextHop,
275 (0, requested_next_hop_scid, required),
279 /// The reason the payment failed. Used in [`Event::PaymentFailed`].
280 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
281 pub enum PaymentFailureReason {
282 /// The intended recipient rejected our payment.
284 /// The user chose to abandon this payment by calling [`ChannelManager::abandon_payment`].
286 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
288 /// We exhausted all of our retry attempts while trying to send the payment, or we
289 /// exhausted the [`Retry::Timeout`] if the user set one. If at any point a retry
290 /// attempt failed while being forwarded along the path, an [`Event::PaymentPathFailed`] will
291 /// have come before this.
293 /// [`Retry::Timeout`]: crate::ln::channelmanager::Retry::Timeout
295 /// The payment expired while retrying, based on the provided
296 /// [`PaymentParameters::expiry_time`].
298 /// [`PaymentParameters::expiry_time`]: crate::routing::router::PaymentParameters::expiry_time
300 /// We failed to find a route while retrying the payment.
302 /// This error should generally never happen. This likely means that there is a problem with
307 impl_writeable_tlv_based_enum!(PaymentFailureReason,
308 (0, RecipientRejected) => {},
309 (2, UserAbandoned) => {},
310 (4, RetriesExhausted) => {},
311 (6, PaymentExpired) => {},
312 (8, RouteNotFound) => {},
313 (10, UnexpectedError) => {}, ;
316 /// An Event which you should probably take some action in response to.
318 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
319 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
320 /// written as it makes no sense to respond to it after reconnecting to peers).
321 #[derive(Clone, Debug, PartialEq, Eq)]
323 /// Used to indicate that the client should generate a funding transaction with the given
324 /// parameters and then call [`ChannelManager::funding_transaction_generated`].
325 /// Generated in [`ChannelManager`] message handling.
326 /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
327 /// counterparty can steal your funds!
329 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
330 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
331 FundingGenerationReady {
332 /// The random channel_id we picked which you'll need to pass into
333 /// [`ChannelManager::funding_transaction_generated`].
335 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
336 temporary_channel_id: [u8; 32],
337 /// The counterparty's node_id, which you'll need to pass back into
338 /// [`ChannelManager::funding_transaction_generated`].
340 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
341 counterparty_node_id: PublicKey,
342 /// The value, in satoshis, that the output should have.
343 channel_value_satoshis: u64,
344 /// The script which should be used in the transaction output.
345 output_script: Script,
346 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
347 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
348 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
349 /// `user_channel_id` will be randomized for an inbound channel. This may be zero for objects
350 /// serialized with LDK versions prior to 0.0.113.
352 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
353 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
354 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
355 user_channel_id: u128,
357 /// Indicates that we've been offered a payment and it needs to be claimed via calling
358 /// [`ChannelManager::claim_funds`] with the preimage given in [`PaymentPurpose`].
360 /// Note that if the preimage is not known, you should call
361 /// [`ChannelManager::fail_htlc_backwards`] or [`ChannelManager::fail_htlc_backwards_with_reason`]
362 /// to free up resources for this HTLC and avoid network congestion.
364 /// If [`Event::PaymentClaimable::onion_fields`] is `Some`, and includes custom TLVs with even type
365 /// numbers, you should use [`ChannelManager::fail_htlc_backwards_with_reason`] with
366 /// [`FailureCode::InvalidOnionPayload`] if you fail to understand and handle the contents, or
367 /// [`ChannelManager::claim_funds_with_known_custom_tlvs`] upon successful handling.
368 /// If you don't intend to check for custom TLVs, you can simply use
369 /// [`ChannelManager::claim_funds`], which will automatically fail back even custom TLVs.
371 /// If you fail to call [`ChannelManager::claim_funds`],
372 /// [`ChannelManager::claim_funds_with_known_custom_tlvs`],
373 /// [`ChannelManager::fail_htlc_backwards`], or
374 /// [`ChannelManager::fail_htlc_backwards_with_reason`] within the HTLC's timeout, the HTLC will
375 /// be automatically failed.
378 /// LDK will not stop an inbound payment from being paid multiple times, so multiple
379 /// `PaymentClaimable` events may be generated for the same payment. In such a case it is
380 /// polite (and required in the lightning specification) to fail the payment the second time
381 /// and give the sender their money back rather than accepting double payment.
384 /// This event used to be called `PaymentReceived` in LDK versions 0.0.112 and earlier.
386 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
387 /// [`ChannelManager::claim_funds_with_known_custom_tlvs`]: crate::ln::channelmanager::ChannelManager::claim_funds_with_known_custom_tlvs
388 /// [`FailureCode::InvalidOnionPayload`]: crate::ln::channelmanager::FailureCode::InvalidOnionPayload
389 /// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards
390 /// [`ChannelManager::fail_htlc_backwards_with_reason`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards_with_reason
392 /// The node that will receive the payment after it has been claimed.
393 /// This is useful to identify payments received via [phantom nodes].
394 /// This field will always be filled in when the event was generated by LDK versions
395 /// 0.0.113 and above.
397 /// [phantom nodes]: crate::sign::PhantomKeysManager
398 receiver_node_id: Option<PublicKey>,
399 /// The hash for which the preimage should be handed to the ChannelManager. Note that LDK will
400 /// not stop you from registering duplicate payment hashes for inbound payments.
401 payment_hash: PaymentHash,
402 /// The fields in the onion which were received with each HTLC. Only fields which were
403 /// identical in each HTLC involved in the payment will be included here.
405 /// Payments received on LDK versions prior to 0.0.115 will have this field unset.
406 onion_fields: Option<RecipientOnionFields>,
407 /// The value, in thousandths of a satoshi, that this payment is claimable for. May be greater
408 /// than the invoice amount.
410 /// May be less than the invoice amount if [`ChannelConfig::accept_underpaying_htlcs`] is set
411 /// and the previous hop took an extra fee.
414 /// If [`ChannelConfig::accept_underpaying_htlcs`] is set and you claim without verifying this
415 /// field, you may lose money!
417 /// [`ChannelConfig::accept_underpaying_htlcs`]: crate::util::config::ChannelConfig::accept_underpaying_htlcs
419 /// The value, in thousands of a satoshi, that was skimmed off of this payment as an extra fee
420 /// taken by our channel counterparty.
422 /// Will always be 0 unless [`ChannelConfig::accept_underpaying_htlcs`] is set.
424 /// [`ChannelConfig::accept_underpaying_htlcs`]: crate::util::config::ChannelConfig::accept_underpaying_htlcs
425 counterparty_skimmed_fee_msat: u64,
426 /// Information for claiming this received payment, based on whether the purpose of the
427 /// payment is to pay an invoice or to send a spontaneous payment.
428 purpose: PaymentPurpose,
429 /// The `channel_id` indicating over which channel we received the payment.
430 via_channel_id: Option<[u8; 32]>,
431 /// The `user_channel_id` indicating over which channel we received the payment.
432 via_user_channel_id: Option<u128>,
433 /// The block height at which this payment will be failed back and will no longer be
434 /// eligible for claiming.
436 /// Prior to this height, a call to [`ChannelManager::claim_funds`] is guaranteed to
437 /// succeed, however you should wait for [`Event::PaymentClaimed`] to be sure.
439 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
440 claim_deadline: Option<u32>,
442 /// Indicates a payment has been claimed and we've received money!
444 /// This most likely occurs when [`ChannelManager::claim_funds`] has been called in response
445 /// to an [`Event::PaymentClaimable`]. However, if we previously crashed during a
446 /// [`ChannelManager::claim_funds`] call you may see this event without a corresponding
447 /// [`Event::PaymentClaimable`] event.
450 /// LDK will not stop an inbound payment from being paid multiple times, so multiple
451 /// `PaymentClaimable` events may be generated for the same payment. If you then call
452 /// [`ChannelManager::claim_funds`] twice for the same [`Event::PaymentClaimable`] you may get
453 /// multiple `PaymentClaimed` events.
455 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
457 /// The node that received the payment.
458 /// This is useful to identify payments which were received via [phantom nodes].
459 /// This field will always be filled in when the event was generated by LDK versions
460 /// 0.0.113 and above.
462 /// [phantom nodes]: crate::sign::PhantomKeysManager
463 receiver_node_id: Option<PublicKey>,
464 /// The payment hash of the claimed payment. Note that LDK will not stop you from
465 /// registering duplicate payment hashes for inbound payments.
466 payment_hash: PaymentHash,
467 /// The value, in thousandths of a satoshi, that this payment is for. May be greater than the
470 /// The purpose of the claimed payment, i.e. whether the payment was for an invoice or a
471 /// spontaneous payment.
472 purpose: PaymentPurpose,
474 /// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
475 /// and we got back the payment preimage for it).
477 /// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed`
478 /// event. In this situation, you SHOULD treat this payment as having succeeded.
480 /// The `payment_id` passed to [`ChannelManager::send_payment`].
482 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
483 payment_id: Option<PaymentId>,
484 /// The preimage to the hash given to ChannelManager::send_payment.
485 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
486 /// store it somehow!
487 payment_preimage: PaymentPreimage,
488 /// The hash that was given to [`ChannelManager::send_payment`].
490 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
491 payment_hash: PaymentHash,
492 /// The total fee which was spent at intermediate hops in this payment, across all paths.
494 /// Note that, like [`Route::get_total_fees`] this does *not* include any potential
495 /// overpayment to the recipient node.
497 /// If the recipient or an intermediate node misbehaves and gives us free money, this may
498 /// overstate the amount paid, though this is unlikely.
500 /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees
501 fee_paid_msat: Option<u64>,
503 /// Indicates an outbound payment failed. Individual [`Event::PaymentPathFailed`] events
504 /// provide failure information for each path attempt in the payment, including retries.
506 /// This event is provided once there are no further pending HTLCs for the payment and the
507 /// payment is no longer retryable, due either to the [`Retry`] provided or
508 /// [`ChannelManager::abandon_payment`] having been called for the corresponding payment.
510 /// In exceedingly rare cases, it is possible that an [`Event::PaymentFailed`] is generated for
511 /// a payment after an [`Event::PaymentSent`] event for this same payment has already been
512 /// received and processed. In this case, the [`Event::PaymentFailed`] event MUST be ignored,
513 /// and the payment MUST be treated as having succeeded.
515 /// [`Retry`]: crate::ln::channelmanager::Retry
516 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
518 /// The `payment_id` passed to [`ChannelManager::send_payment`].
520 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
521 payment_id: PaymentId,
522 /// The hash that was given to [`ChannelManager::send_payment`].
524 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
525 payment_hash: PaymentHash,
526 /// The reason the payment failed. This is only `None` for events generated or serialized
527 /// by versions prior to 0.0.115.
528 reason: Option<PaymentFailureReason>,
530 /// Indicates that a path for an outbound payment was successful.
532 /// Always generated after [`Event::PaymentSent`] and thus useful for scoring channels. See
533 /// [`Event::PaymentSent`] for obtaining the payment preimage.
534 PaymentPathSuccessful {
535 /// The `payment_id` passed to [`ChannelManager::send_payment`].
537 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
538 payment_id: PaymentId,
539 /// The hash that was given to [`ChannelManager::send_payment`].
541 /// This will be `Some` for all payments which completed on LDK 0.0.104 or later.
543 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
544 payment_hash: Option<PaymentHash>,
545 /// The payment path that was successful.
547 /// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
550 /// Indicates an outbound HTLC we sent failed, likely due to an intermediary node being unable to
553 /// Note that this does *not* indicate that all paths for an MPP payment have failed, see
554 /// [`Event::PaymentFailed`].
556 /// See [`ChannelManager::abandon_payment`] for giving up on this payment before its retries have
559 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
561 /// The `payment_id` passed to [`ChannelManager::send_payment`].
563 /// This will be `Some` for all payment paths which failed on LDK 0.0.103 or later.
565 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
566 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
567 payment_id: Option<PaymentId>,
568 /// The hash that was given to [`ChannelManager::send_payment`].
570 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
571 payment_hash: PaymentHash,
572 /// Indicates the payment was rejected for some reason by the recipient. This implies that
573 /// the payment has failed, not just the route in question. If this is not set, the payment may
574 /// be retried via a different route.
575 payment_failed_permanently: bool,
576 /// Extra error details based on the failure type. May contain an update that needs to be
577 /// applied to the [`NetworkGraph`].
579 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
580 failure: PathFailure,
581 /// The payment path that failed.
583 /// The channel responsible for the failed payment path.
585 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
586 /// may not refer to a channel in the public network graph. These aliases may also collide
587 /// with channels in the public network graph.
589 /// If this is `Some`, then the corresponding channel should be avoided when the payment is
590 /// retried. May be `None` for older [`Event`] serializations.
591 short_channel_id: Option<u64>,
593 error_code: Option<u16>,
595 error_data: Option<Vec<u8>>,
597 /// Indicates that a probe payment we sent returned successful, i.e., only failed at the destination.
599 /// The id returned by [`ChannelManager::send_probe`].
601 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
602 payment_id: PaymentId,
603 /// The hash generated by [`ChannelManager::send_probe`].
605 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
606 payment_hash: PaymentHash,
607 /// The payment path that was successful.
610 /// Indicates that a probe payment we sent failed at an intermediary node on the path.
612 /// The id returned by [`ChannelManager::send_probe`].
614 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
615 payment_id: PaymentId,
616 /// The hash generated by [`ChannelManager::send_probe`].
618 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
619 payment_hash: PaymentHash,
620 /// The payment path that failed.
622 /// The channel responsible for the failed probe.
624 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
625 /// may not refer to a channel in the public network graph. These aliases may also collide
626 /// with channels in the public network graph.
627 short_channel_id: Option<u64>,
629 /// Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at
630 /// a time in the future.
632 /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
633 PendingHTLCsForwardable {
634 /// The minimum amount of time that should be waited prior to calling
635 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
636 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
637 /// now + 5*time_forwardable).
638 time_forwardable: Duration,
640 /// Used to indicate that we've intercepted an HTLC forward. This event will only be generated if
641 /// you've encoded an intercept scid in the receiver's invoice route hints using
642 /// [`ChannelManager::get_intercept_scid`] and have set [`UserConfig::accept_intercept_htlcs`].
644 /// [`ChannelManager::forward_intercepted_htlc`] or
645 /// [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to this event. See
646 /// their docs for more information.
648 /// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
649 /// [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
650 /// [`ChannelManager::forward_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::forward_intercepted_htlc
651 /// [`ChannelManager::fail_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::fail_intercepted_htlc
653 /// An id to help LDK identify which HTLC is being forwarded or failed.
654 intercept_id: InterceptId,
655 /// The fake scid that was programmed as the next hop's scid, generated using
656 /// [`ChannelManager::get_intercept_scid`].
658 /// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
659 requested_next_hop_scid: u64,
660 /// The payment hash used for this HTLC.
661 payment_hash: PaymentHash,
662 /// How many msats were received on the inbound edge of this HTLC.
663 inbound_amount_msat: u64,
664 /// How many msats the payer intended to route to the next node. Depending on the reason you are
665 /// intercepting this payment, you might take a fee by forwarding less than this amount.
666 /// Forwarding less than this amount may break compatibility with LDK versions prior to 0.0.116.
668 /// Note that LDK will NOT check that expected fees were factored into this value. You MUST
669 /// check that whatever fee you want has been included here or subtract it as required. Further,
670 /// LDK will not stop you from forwarding more than you received.
671 expected_outbound_amount_msat: u64,
673 /// Used to indicate that an output which you should know how to spend was confirmed on chain
674 /// and is now spendable.
675 /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
676 /// counterparty spending them due to some kind of timeout. Thus, you need to store them
677 /// somewhere and spend them when you create on-chain transactions.
679 /// The outputs which you should store as spendable by you.
680 outputs: Vec<SpendableOutputDescriptor>,
682 /// This event is generated when a payment has been successfully forwarded through us and a
683 /// forwarding fee earned.
685 /// The incoming channel between the previous node and us. This is only `None` for events
686 /// generated or serialized by versions prior to 0.0.107.
687 prev_channel_id: Option<[u8; 32]>,
688 /// The outgoing channel between the next node and us. This is only `None` for events
689 /// generated or serialized by versions prior to 0.0.107.
690 next_channel_id: Option<[u8; 32]>,
691 /// The fee, in milli-satoshis, which was earned as a result of the payment.
693 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
694 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
695 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
696 /// claimed the full value in millisatoshis from the source. In this case,
697 /// `claim_from_onchain_tx` will be set.
699 /// If the channel which sent us the payment has been force-closed, we will claim the funds
700 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
701 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
702 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
704 fee_earned_msat: Option<u64>,
705 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
707 claim_from_onchain_tx: bool,
708 /// The final amount forwarded, in milli-satoshis, after the fee is deducted.
710 /// The caveat described above the `fee_earned_msat` field applies here as well.
711 outbound_amount_forwarded_msat: Option<u64>,
713 /// Used to indicate that a channel with the given `channel_id` is being opened and pending
714 /// confirmation on-chain.
716 /// This event is emitted when the funding transaction has been signed and is broadcast to the
717 /// network. For 0conf channels it will be immediately followed by the corresponding
718 /// [`Event::ChannelReady`] event.
720 /// The `channel_id` of the channel that is pending confirmation.
721 channel_id: [u8; 32],
722 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
723 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
724 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
725 /// `user_channel_id` will be randomized for an inbound channel.
727 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
728 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
729 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
730 user_channel_id: u128,
731 /// The `temporary_channel_id` this channel used to be known by during channel establishment.
733 /// Will be `None` for channels created prior to LDK version 0.0.115.
734 former_temporary_channel_id: Option<[u8; 32]>,
735 /// The `node_id` of the channel counterparty.
736 counterparty_node_id: PublicKey,
737 /// The outpoint of the channel's funding transaction.
738 funding_txo: OutPoint,
740 /// Used to indicate that a channel with the given `channel_id` is ready to
741 /// be used. This event is emitted either when the funding transaction has been confirmed
742 /// on-chain, or, in case of a 0conf channel, when both parties have confirmed the channel
745 /// The `channel_id` of the channel that is ready.
746 channel_id: [u8; 32],
747 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
748 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
749 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
750 /// `user_channel_id` will be randomized for an inbound channel.
752 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
753 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
754 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
755 user_channel_id: u128,
756 /// The `node_id` of the channel counterparty.
757 counterparty_node_id: PublicKey,
758 /// The features that this channel will operate with.
759 channel_type: ChannelTypeFeatures,
761 /// Used to indicate that a previously opened channel with the given `channel_id` is in the
762 /// process of closure.
764 /// Note that this event is only triggered for accepted channels: if the
765 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true and the channel is
766 /// rejected, no `ChannelClosed` event will be sent.
768 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
769 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
771 /// The `channel_id` of the channel which has been closed. Note that on-chain transactions
772 /// resolving the channel are likely still awaiting confirmation.
773 channel_id: [u8; 32],
774 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
775 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
776 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
777 /// `user_channel_id` will be randomized for inbound channels.
778 /// This may be zero for inbound channels serialized prior to 0.0.113 and will always be
779 /// zero for objects serialized with LDK versions prior to 0.0.102.
781 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
782 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
783 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
784 user_channel_id: u128,
785 /// The reason the channel was closed.
786 reason: ClosureReason,
787 /// Counterparty in the closed channel.
789 /// This field will be `None` for objects serialized prior to LDK 0.0.117.
790 counterparty_node_id: Option<PublicKey>,
791 /// Channel capacity of the closing channel (sats).
793 /// This field will be `None` for objects serialized prior to LDK 0.0.117.
794 channel_capacity_sats: Option<u64>,
796 /// Used to indicate to the user that they can abandon the funding transaction and recycle the
797 /// inputs for another purpose.
799 /// The channel_id of the channel which has been closed.
800 channel_id: [u8; 32],
801 /// The full transaction received from the user
802 transaction: Transaction
804 /// Indicates a request to open a new channel by a peer.
806 /// To accept the request, call [`ChannelManager::accept_inbound_channel`]. To reject the request,
807 /// call [`ChannelManager::force_close_without_broadcasting_txn`]. Note that a ['ChannelClosed`]
808 /// event will _not_ be triggered if the channel is rejected.
810 /// The event is only triggered when a new open channel request is received and the
811 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
813 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
814 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
815 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
817 /// The temporary channel ID of the channel requested to be opened.
819 /// When responding to the request, the `temporary_channel_id` should be passed
820 /// back to the ChannelManager through [`ChannelManager::accept_inbound_channel`] to accept,
821 /// or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject.
823 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
824 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
825 temporary_channel_id: [u8; 32],
826 /// The node_id of the counterparty requesting to open the channel.
828 /// When responding to the request, the `counterparty_node_id` should be passed
829 /// back to the `ChannelManager` through [`ChannelManager::accept_inbound_channel`] to
830 /// accept the request, or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject the
833 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
834 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
835 counterparty_node_id: PublicKey,
836 /// The channel value of the requested channel.
837 funding_satoshis: u64,
838 /// Our starting balance in the channel if the request is accepted, in milli-satoshi.
840 /// The features that this channel will operate with. If you reject the channel, a
841 /// well-behaved counterparty may automatically re-attempt the channel with a new set of
844 /// Note that if [`ChannelTypeFeatures::supports_scid_privacy`] returns true on this type,
845 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
848 /// Furthermore, note that if [`ChannelTypeFeatures::supports_zero_conf`] returns true on this type,
849 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
850 /// 0.0.107. Channels setting this type also need to get manually accepted via
851 /// [`crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`],
852 /// or will be rejected otherwise.
854 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
855 channel_type: ChannelTypeFeatures,
857 /// Indicates that the HTLC was accepted, but could not be processed when or after attempting to
860 /// Some scenarios where this event may be sent include:
861 /// * Insufficient capacity in the outbound channel
862 /// * While waiting to forward the HTLC, the channel it is meant to be forwarded through closes
863 /// * When an unknown SCID is requested for forwarding a payment.
864 /// * Expected MPP amount has already been reached
865 /// * The HTLC has timed out
867 /// This event, however, does not get generated if an HTLC fails to meet the forwarding
868 /// requirements (i.e. insufficient fees paid, or a CLTV that is too soon).
870 /// The channel over which the HTLC was received.
871 prev_channel_id: [u8; 32],
872 /// Destination of the HTLC that failed to be processed.
873 failed_next_destination: HTLCDestination,
875 /// Indicates that a transaction originating from LDK needs to have its fee bumped. This event
876 /// requires confirmed external funds to be readily available to spend.
878 /// LDK does not currently generate this event unless the
879 /// [`ChannelHandshakeConfig::negotiate_anchors_zero_fee_htlc_tx`] config flag is set to true.
880 /// It is limited to the scope of channels with anchor outputs.
882 /// [`ChannelHandshakeConfig::negotiate_anchors_zero_fee_htlc_tx`]: crate::util::config::ChannelHandshakeConfig::negotiate_anchors_zero_fee_htlc_tx
883 BumpTransaction(BumpTransactionEvent),
886 impl Writeable for Event {
887 fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
889 &Event::FundingGenerationReady { .. } => {
891 // We never write out FundingGenerationReady events as, upon disconnection, peers
892 // drop any channels which have not yet exchanged funding_signed.
894 &Event::PaymentClaimable { ref payment_hash, ref amount_msat, counterparty_skimmed_fee_msat,
895 ref purpose, ref receiver_node_id, ref via_channel_id, ref via_user_channel_id,
896 ref claim_deadline, ref onion_fields
899 let mut payment_secret = None;
900 let payment_preimage;
902 PaymentPurpose::InvoicePayment { payment_preimage: preimage, payment_secret: secret } => {
903 payment_secret = Some(secret);
904 payment_preimage = *preimage;
906 PaymentPurpose::SpontaneousPayment(preimage) => {
907 payment_preimage = Some(*preimage);
910 let skimmed_fee_opt = if counterparty_skimmed_fee_msat == 0 { None }
911 else { Some(counterparty_skimmed_fee_msat) };
912 write_tlv_fields!(writer, {
913 (0, payment_hash, required),
914 (1, receiver_node_id, option),
915 (2, payment_secret, option),
916 (3, via_channel_id, option),
917 (4, amount_msat, required),
918 (5, via_user_channel_id, option),
919 // Type 6 was `user_payment_id` on 0.0.103 and earlier
920 (7, claim_deadline, option),
921 (8, payment_preimage, option),
922 (9, onion_fields, option),
923 (10, skimmed_fee_opt, option),
926 &Event::PaymentSent { ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat } => {
928 write_tlv_fields!(writer, {
929 (0, payment_preimage, required),
930 (1, payment_hash, required),
931 (3, payment_id, option),
932 (5, fee_paid_msat, option),
935 &Event::PaymentPathFailed {
936 ref payment_id, ref payment_hash, ref payment_failed_permanently, ref failure,
937 ref path, ref short_channel_id,
945 error_code.write(writer)?;
947 error_data.write(writer)?;
948 write_tlv_fields!(writer, {
949 (0, payment_hash, required),
950 (1, None::<NetworkUpdate>, option), // network_update in LDK versions prior to 0.0.114
951 (2, payment_failed_permanently, required),
952 (3, false, required), // all_paths_failed in LDK versions prior to 0.0.114
953 (4, path.blinded_tail, option),
954 (5, path.hops, required_vec),
955 (7, short_channel_id, option),
956 (9, None::<RouteParameters>, option), // retry in LDK versions prior to 0.0.115
957 (11, payment_id, option),
958 (13, failure, required),
961 &Event::PendingHTLCsForwardable { time_forwardable: _ } => {
963 // Note that we now ignore these on the read end as we'll re-generate them in
964 // ChannelManager, we write them here only for backwards compatibility.
966 &Event::SpendableOutputs { ref outputs } => {
968 write_tlv_fields!(writer, {
969 (0, WithoutLength(outputs), required),
972 &Event::HTLCIntercepted { requested_next_hop_scid, payment_hash, inbound_amount_msat, expected_outbound_amount_msat, intercept_id } => {
974 let intercept_scid = InterceptNextHop::FakeScid { requested_next_hop_scid };
975 write_tlv_fields!(writer, {
976 (0, intercept_id, required),
977 (2, intercept_scid, required),
978 (4, payment_hash, required),
979 (6, inbound_amount_msat, required),
980 (8, expected_outbound_amount_msat, required),
983 &Event::PaymentForwarded {
984 fee_earned_msat, prev_channel_id, claim_from_onchain_tx,
985 next_channel_id, outbound_amount_forwarded_msat
988 write_tlv_fields!(writer, {
989 (0, fee_earned_msat, option),
990 (1, prev_channel_id, option),
991 (2, claim_from_onchain_tx, required),
992 (3, next_channel_id, option),
993 (5, outbound_amount_forwarded_msat, option),
996 &Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason,
997 ref counterparty_node_id, ref channel_capacity_sats
1000 // `user_channel_id` used to be a single u64 value. In order to remain backwards
1001 // compatible with versions prior to 0.0.113, the u128 is serialized as two
1002 // separate u64 values.
1003 let user_channel_id_low = *user_channel_id as u64;
1004 let user_channel_id_high = (*user_channel_id >> 64) as u64;
1005 write_tlv_fields!(writer, {
1006 (0, channel_id, required),
1007 (1, user_channel_id_low, required),
1008 (2, reason, required),
1009 (3, user_channel_id_high, required),
1010 (5, counterparty_node_id, option),
1011 (7, channel_capacity_sats, option),
1014 &Event::DiscardFunding { ref channel_id, ref transaction } => {
1015 11u8.write(writer)?;
1016 write_tlv_fields!(writer, {
1017 (0, channel_id, required),
1018 (2, transaction, required)
1021 &Event::PaymentPathSuccessful { ref payment_id, ref payment_hash, ref path } => {
1022 13u8.write(writer)?;
1023 write_tlv_fields!(writer, {
1024 (0, payment_id, required),
1025 (2, payment_hash, option),
1026 (4, path.hops, required_vec),
1027 (6, path.blinded_tail, option),
1030 &Event::PaymentFailed { ref payment_id, ref payment_hash, ref reason } => {
1031 15u8.write(writer)?;
1032 write_tlv_fields!(writer, {
1033 (0, payment_id, required),
1034 (1, reason, option),
1035 (2, payment_hash, required),
1038 &Event::OpenChannelRequest { .. } => {
1039 17u8.write(writer)?;
1040 // We never write the OpenChannelRequest events as, upon disconnection, peers
1041 // drop any channels which have not yet exchanged funding_signed.
1043 &Event::PaymentClaimed { ref payment_hash, ref amount_msat, ref purpose, ref receiver_node_id } => {
1044 19u8.write(writer)?;
1045 write_tlv_fields!(writer, {
1046 (0, payment_hash, required),
1047 (1, receiver_node_id, option),
1048 (2, purpose, required),
1049 (4, amount_msat, required),
1052 &Event::ProbeSuccessful { ref payment_id, ref payment_hash, ref path } => {
1053 21u8.write(writer)?;
1054 write_tlv_fields!(writer, {
1055 (0, payment_id, required),
1056 (2, payment_hash, required),
1057 (4, path.hops, required_vec),
1058 (6, path.blinded_tail, option),
1061 &Event::ProbeFailed { ref payment_id, ref payment_hash, ref path, ref short_channel_id } => {
1062 23u8.write(writer)?;
1063 write_tlv_fields!(writer, {
1064 (0, payment_id, required),
1065 (2, payment_hash, required),
1066 (4, path.hops, required_vec),
1067 (6, short_channel_id, option),
1068 (8, path.blinded_tail, option),
1071 &Event::HTLCHandlingFailed { ref prev_channel_id, ref failed_next_destination } => {
1072 25u8.write(writer)?;
1073 write_tlv_fields!(writer, {
1074 (0, prev_channel_id, required),
1075 (2, failed_next_destination, required),
1078 &Event::BumpTransaction(ref event)=> {
1079 27u8.write(writer)?;
1081 // We never write the ChannelClose|HTLCResolution events as they'll be replayed
1082 // upon restarting anyway if they remain unresolved.
1083 BumpTransactionEvent::ChannelClose { .. } => {}
1084 BumpTransactionEvent::HTLCResolution { .. } => {}
1086 write_tlv_fields!(writer, {}); // Write a length field for forwards compat
1088 &Event::ChannelReady { ref channel_id, ref user_channel_id, ref counterparty_node_id, ref channel_type } => {
1089 29u8.write(writer)?;
1090 write_tlv_fields!(writer, {
1091 (0, channel_id, required),
1092 (2, user_channel_id, required),
1093 (4, counterparty_node_id, required),
1094 (6, channel_type, required),
1097 &Event::ChannelPending { ref channel_id, ref user_channel_id, ref former_temporary_channel_id, ref counterparty_node_id, ref funding_txo } => {
1098 31u8.write(writer)?;
1099 write_tlv_fields!(writer, {
1100 (0, channel_id, required),
1101 (2, user_channel_id, required),
1102 (4, former_temporary_channel_id, required),
1103 (6, counterparty_node_id, required),
1104 (8, funding_txo, required),
1107 // Note that, going forward, all new events must only write data inside of
1108 // `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
1109 // data via `write_tlv_fields`.
1114 impl MaybeReadable for Event {
1115 fn read<R: io::Read>(reader: &mut R) -> Result<Option<Self>, msgs::DecodeError> {
1116 match Readable::read(reader)? {
1117 // Note that we do not write a length-prefixed TLV for FundingGenerationReady events,
1118 // unlike all other events, thus we return immediately here.
1122 let mut payment_hash = PaymentHash([0; 32]);
1123 let mut payment_preimage = None;
1124 let mut payment_secret = None;
1125 let mut amount_msat = 0;
1126 let mut counterparty_skimmed_fee_msat_opt = None;
1127 let mut receiver_node_id = None;
1128 let mut _user_payment_id = None::<u64>; // Used in 0.0.103 and earlier, no longer written in 0.0.116+.
1129 let mut via_channel_id = None;
1130 let mut claim_deadline = None;
1131 let mut via_user_channel_id = None;
1132 let mut onion_fields = None;
1133 read_tlv_fields!(reader, {
1134 (0, payment_hash, required),
1135 (1, receiver_node_id, option),
1136 (2, payment_secret, option),
1137 (3, via_channel_id, option),
1138 (4, amount_msat, required),
1139 (5, via_user_channel_id, option),
1140 (6, _user_payment_id, option),
1141 (7, claim_deadline, option),
1142 (8, payment_preimage, option),
1143 (9, onion_fields, option),
1144 (10, counterparty_skimmed_fee_msat_opt, option),
1146 let purpose = match payment_secret {
1147 Some(secret) => PaymentPurpose::InvoicePayment {
1149 payment_secret: secret
1151 None if payment_preimage.is_some() => PaymentPurpose::SpontaneousPayment(payment_preimage.unwrap()),
1152 None => return Err(msgs::DecodeError::InvalidValue),
1154 Ok(Some(Event::PaymentClaimable {
1158 counterparty_skimmed_fee_msat: counterparty_skimmed_fee_msat_opt.unwrap_or(0),
1161 via_user_channel_id,
1170 let mut payment_preimage = PaymentPreimage([0; 32]);
1171 let mut payment_hash = None;
1172 let mut payment_id = None;
1173 let mut fee_paid_msat = None;
1174 read_tlv_fields!(reader, {
1175 (0, payment_preimage, required),
1176 (1, payment_hash, option),
1177 (3, payment_id, option),
1178 (5, fee_paid_msat, option),
1180 if payment_hash.is_none() {
1181 payment_hash = Some(PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner()));
1183 Ok(Some(Event::PaymentSent {
1186 payment_hash: payment_hash.unwrap(),
1195 let error_code = Readable::read(reader)?;
1197 let error_data = Readable::read(reader)?;
1198 let mut payment_hash = PaymentHash([0; 32]);
1199 let mut payment_failed_permanently = false;
1200 let mut network_update = None;
1201 let mut blinded_tail: Option<BlindedTail> = None;
1202 let mut path: Option<Vec<RouteHop>> = Some(vec![]);
1203 let mut short_channel_id = None;
1204 let mut payment_id = None;
1205 let mut failure_opt = None;
1206 read_tlv_fields!(reader, {
1207 (0, payment_hash, required),
1208 (1, network_update, upgradable_option),
1209 (2, payment_failed_permanently, required),
1210 (4, blinded_tail, option),
1211 // Added as a part of LDK 0.0.101 and always filled in since.
1212 // Defaults to an empty Vec, though likely should have been `Option`al.
1213 (5, path, optional_vec),
1214 (7, short_channel_id, option),
1215 (11, payment_id, option),
1216 (13, failure_opt, upgradable_option),
1218 let failure = failure_opt.unwrap_or_else(|| PathFailure::OnPath { network_update });
1219 Ok(Some(Event::PaymentPathFailed {
1222 payment_failed_permanently,
1224 path: Path { hops: path.unwrap(), blinded_tail },
1237 let mut outputs = WithoutLength(Vec::new());
1238 read_tlv_fields!(reader, {
1239 (0, outputs, required),
1241 Ok(Some(Event::SpendableOutputs { outputs: outputs.0 }))
1246 let mut payment_hash = PaymentHash([0; 32]);
1247 let mut intercept_id = InterceptId([0; 32]);
1248 let mut requested_next_hop_scid = InterceptNextHop::FakeScid { requested_next_hop_scid: 0 };
1249 let mut inbound_amount_msat = 0;
1250 let mut expected_outbound_amount_msat = 0;
1251 read_tlv_fields!(reader, {
1252 (0, intercept_id, required),
1253 (2, requested_next_hop_scid, required),
1254 (4, payment_hash, required),
1255 (6, inbound_amount_msat, required),
1256 (8, expected_outbound_amount_msat, required),
1258 let next_scid = match requested_next_hop_scid {
1259 InterceptNextHop::FakeScid { requested_next_hop_scid: scid } => scid
1261 Ok(Some(Event::HTLCIntercepted {
1263 requested_next_hop_scid: next_scid,
1264 inbound_amount_msat,
1265 expected_outbound_amount_msat,
1271 let mut fee_earned_msat = None;
1272 let mut prev_channel_id = None;
1273 let mut claim_from_onchain_tx = false;
1274 let mut next_channel_id = None;
1275 let mut outbound_amount_forwarded_msat = None;
1276 read_tlv_fields!(reader, {
1277 (0, fee_earned_msat, option),
1278 (1, prev_channel_id, option),
1279 (2, claim_from_onchain_tx, required),
1280 (3, next_channel_id, option),
1281 (5, outbound_amount_forwarded_msat, option),
1283 Ok(Some(Event::PaymentForwarded {
1284 fee_earned_msat, prev_channel_id, claim_from_onchain_tx, next_channel_id,
1285 outbound_amount_forwarded_msat
1292 let mut channel_id = [0; 32];
1293 let mut reason = UpgradableRequired(None);
1294 let mut user_channel_id_low_opt: Option<u64> = None;
1295 let mut user_channel_id_high_opt: Option<u64> = None;
1296 let mut counterparty_node_id = None;
1297 let mut channel_capacity_sats = None;
1298 read_tlv_fields!(reader, {
1299 (0, channel_id, required),
1300 (1, user_channel_id_low_opt, option),
1301 (2, reason, upgradable_required),
1302 (3, user_channel_id_high_opt, option),
1303 (5, counterparty_node_id, option),
1304 (7, channel_capacity_sats, option),
1307 // `user_channel_id` used to be a single u64 value. In order to remain
1308 // backwards compatible with versions prior to 0.0.113, the u128 is serialized
1309 // as two separate u64 values.
1310 let user_channel_id = (user_channel_id_low_opt.unwrap_or(0) as u128) +
1311 ((user_channel_id_high_opt.unwrap_or(0) as u128) << 64);
1313 Ok(Some(Event::ChannelClosed { channel_id, user_channel_id, reason: _init_tlv_based_struct_field!(reason, upgradable_required),
1314 counterparty_node_id, channel_capacity_sats }))
1320 let mut channel_id = [0; 32];
1321 let mut transaction = Transaction{ version: 2, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() };
1322 read_tlv_fields!(reader, {
1323 (0, channel_id, required),
1324 (2, transaction, required),
1326 Ok(Some(Event::DiscardFunding { channel_id, transaction } ))
1332 _init_and_read_tlv_fields!(reader, {
1333 (0, payment_id, required),
1334 (2, payment_hash, option),
1335 (4, path, required_vec),
1336 (6, blinded_tail, option),
1338 Ok(Some(Event::PaymentPathSuccessful {
1339 payment_id: payment_id.0.unwrap(),
1341 path: Path { hops: path, blinded_tail },
1348 let mut payment_hash = PaymentHash([0; 32]);
1349 let mut payment_id = PaymentId([0; 32]);
1350 let mut reason = None;
1351 read_tlv_fields!(reader, {
1352 (0, payment_id, required),
1353 (1, reason, upgradable_option),
1354 (2, payment_hash, required),
1356 Ok(Some(Event::PaymentFailed {
1365 // Value 17 is used for `Event::OpenChannelRequest`.
1370 let mut payment_hash = PaymentHash([0; 32]);
1371 let mut purpose = UpgradableRequired(None);
1372 let mut amount_msat = 0;
1373 let mut receiver_node_id = None;
1374 read_tlv_fields!(reader, {
1375 (0, payment_hash, required),
1376 (1, receiver_node_id, option),
1377 (2, purpose, upgradable_required),
1378 (4, amount_msat, required),
1380 Ok(Some(Event::PaymentClaimed {
1383 purpose: _init_tlv_based_struct_field!(purpose, upgradable_required),
1391 _init_and_read_tlv_fields!(reader, {
1392 (0, payment_id, required),
1393 (2, payment_hash, required),
1394 (4, path, required_vec),
1395 (6, blinded_tail, option),
1397 Ok(Some(Event::ProbeSuccessful {
1398 payment_id: payment_id.0.unwrap(),
1399 payment_hash: payment_hash.0.unwrap(),
1400 path: Path { hops: path, blinded_tail },
1407 _init_and_read_tlv_fields!(reader, {
1408 (0, payment_id, required),
1409 (2, payment_hash, required),
1410 (4, path, required_vec),
1411 (6, short_channel_id, option),
1412 (8, blinded_tail, option),
1414 Ok(Some(Event::ProbeFailed {
1415 payment_id: payment_id.0.unwrap(),
1416 payment_hash: payment_hash.0.unwrap(),
1417 path: Path { hops: path, blinded_tail },
1425 let mut prev_channel_id = [0; 32];
1426 let mut failed_next_destination_opt = UpgradableRequired(None);
1427 read_tlv_fields!(reader, {
1428 (0, prev_channel_id, required),
1429 (2, failed_next_destination_opt, upgradable_required),
1431 Ok(Some(Event::HTLCHandlingFailed {
1433 failed_next_destination: _init_tlv_based_struct_field!(failed_next_destination_opt, upgradable_required),
1441 let mut channel_id = [0; 32];
1442 let mut user_channel_id: u128 = 0;
1443 let mut counterparty_node_id = RequiredWrapper(None);
1444 let mut channel_type = RequiredWrapper(None);
1445 read_tlv_fields!(reader, {
1446 (0, channel_id, required),
1447 (2, user_channel_id, required),
1448 (4, counterparty_node_id, required),
1449 (6, channel_type, required),
1452 Ok(Some(Event::ChannelReady {
1455 counterparty_node_id: counterparty_node_id.0.unwrap(),
1456 channel_type: channel_type.0.unwrap()
1463 let mut channel_id = [0; 32];
1464 let mut user_channel_id: u128 = 0;
1465 let mut former_temporary_channel_id = None;
1466 let mut counterparty_node_id = RequiredWrapper(None);
1467 let mut funding_txo = RequiredWrapper(None);
1468 read_tlv_fields!(reader, {
1469 (0, channel_id, required),
1470 (2, user_channel_id, required),
1471 (4, former_temporary_channel_id, required),
1472 (6, counterparty_node_id, required),
1473 (8, funding_txo, required),
1476 Ok(Some(Event::ChannelPending {
1479 former_temporary_channel_id,
1480 counterparty_node_id: counterparty_node_id.0.unwrap(),
1481 funding_txo: funding_txo.0.unwrap()
1486 // Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
1487 // Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
1489 x if x % 2 == 1 => {
1490 // If the event is of unknown type, assume it was written with `write_tlv_fields`,
1491 // which prefixes the whole thing with a length BigSize. Because the event is
1492 // odd-type unknown, we should treat it as `Ok(None)` even if it has some TLV
1493 // fields that are even. Thus, we avoid using `read_tlv_fields` and simply read
1494 // exactly the number of bytes specified, ignoring them entirely.
1495 let tlv_len: BigSize = Readable::read(reader)?;
1496 FixedLengthReader::new(reader, tlv_len.0)
1497 .eat_remaining().map_err(|_| msgs::DecodeError::ShortRead)?;
1500 _ => Err(msgs::DecodeError::InvalidValue)
1505 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
1506 /// broadcast to most peers).
1507 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
1508 #[derive(Clone, Debug)]
1509 pub enum MessageSendEvent {
1510 /// Used to indicate that we've accepted a channel open and should send the accept_channel
1511 /// message provided to the given peer.
1513 /// The node_id of the node which should receive this message
1515 /// The message which should be sent.
1516 msg: msgs::AcceptChannel,
1518 /// Used to indicate that we've accepted a V2 channel open and should send the accept_channel2
1519 /// message provided to the given peer.
1520 SendAcceptChannelV2 {
1521 /// The node_id of the node which should receive this message
1523 /// The message which should be sent.
1524 msg: msgs::AcceptChannelV2,
1526 /// Used to indicate that we've initiated a channel open and should send the open_channel
1527 /// message provided to the given peer.
1529 /// The node_id of the node which should receive this message
1531 /// The message which should be sent.
1532 msg: msgs::OpenChannel,
1534 /// Used to indicate that we've initiated a V2 channel open and should send the open_channel2
1535 /// message provided to the given peer.
1537 /// The node_id of the node which should receive this message
1539 /// The message which should be sent.
1540 msg: msgs::OpenChannelV2,
1542 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
1543 SendFundingCreated {
1544 /// The node_id of the node which should receive this message
1546 /// The message which should be sent.
1547 msg: msgs::FundingCreated,
1549 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
1551 /// The node_id of the node which should receive this message
1553 /// The message which should be sent.
1554 msg: msgs::FundingSigned,
1556 /// Used to indicate that a tx_add_input message should be sent to the peer with the given node_id.
1558 /// The node_id of the node which should receive this message
1560 /// The message which should be sent.
1561 msg: msgs::TxAddInput,
1563 /// Used to indicate that a tx_add_output message should be sent to the peer with the given node_id.
1565 /// The node_id of the node which should receive this message
1567 /// The message which should be sent.
1568 msg: msgs::TxAddOutput,
1570 /// Used to indicate that a tx_remove_input message should be sent to the peer with the given node_id.
1572 /// The node_id of the node which should receive this message
1574 /// The message which should be sent.
1575 msg: msgs::TxRemoveInput,
1577 /// Used to indicate that a tx_remove_output message should be sent to the peer with the given node_id.
1578 SendTxRemoveOutput {
1579 /// The node_id of the node which should receive this message
1581 /// The message which should be sent.
1582 msg: msgs::TxRemoveOutput,
1584 /// Used to indicate that a tx_complete message should be sent to the peer with the given node_id.
1586 /// The node_id of the node which should receive this message
1588 /// The message which should be sent.
1589 msg: msgs::TxComplete,
1591 /// Used to indicate that a tx_signatures message should be sent to the peer with the given node_id.
1593 /// The node_id of the node which should receive this message
1595 /// The message which should be sent.
1596 msg: msgs::TxSignatures,
1598 /// Used to indicate that a tx_init_rbf message should be sent to the peer with the given node_id.
1600 /// The node_id of the node which should receive this message
1602 /// The message which should be sent.
1603 msg: msgs::TxInitRbf,
1605 /// Used to indicate that a tx_ack_rbf message should be sent to the peer with the given node_id.
1607 /// The node_id of the node which should receive this message
1609 /// The message which should be sent.
1610 msg: msgs::TxAckRbf,
1612 /// Used to indicate that a tx_abort message should be sent to the peer with the given node_id.
1614 /// The node_id of the node which should receive this message
1616 /// The message which should be sent.
1617 msg: msgs::TxAddInput,
1619 /// Used to indicate that a channel_ready message should be sent to the peer with the given node_id.
1621 /// The node_id of the node which should receive these message(s)
1623 /// The channel_ready message which should be sent.
1624 msg: msgs::ChannelReady,
1626 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
1627 SendAnnouncementSignatures {
1628 /// The node_id of the node which should receive these message(s)
1630 /// The announcement_signatures message which should be sent.
1631 msg: msgs::AnnouncementSignatures,
1633 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
1634 /// message should be sent to the peer with the given node_id.
1636 /// The node_id of the node which should receive these message(s)
1638 /// The update messages which should be sent. ALL messages in the struct should be sent!
1639 updates: msgs::CommitmentUpdate,
1641 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
1643 /// The node_id of the node which should receive this message
1645 /// The message which should be sent.
1646 msg: msgs::RevokeAndACK,
1648 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
1650 /// The node_id of the node which should receive this message
1652 /// The message which should be sent.
1653 msg: msgs::ClosingSigned,
1655 /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
1657 /// The node_id of the node which should receive this message
1659 /// The message which should be sent.
1660 msg: msgs::Shutdown,
1662 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
1663 SendChannelReestablish {
1664 /// The node_id of the node which should receive this message
1666 /// The message which should be sent.
1667 msg: msgs::ChannelReestablish,
1669 /// Used to send a channel_announcement and channel_update to a specific peer, likely on
1670 /// initial connection to ensure our peers know about our channels.
1671 SendChannelAnnouncement {
1672 /// The node_id of the node which should receive this message
1674 /// The channel_announcement which should be sent.
1675 msg: msgs::ChannelAnnouncement,
1676 /// The followup channel_update which should be sent.
1677 update_msg: msgs::ChannelUpdate,
1679 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
1680 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
1682 /// Note that after doing so, you very likely (unless you did so very recently) want to
1683 /// broadcast a node_announcement (e.g. via [`PeerManager::broadcast_node_announcement`]). This
1684 /// ensures that any nodes which see our channel_announcement also have a relevant
1685 /// node_announcement, including relevant feature flags which may be important for routing
1686 /// through or to us.
1688 /// [`PeerManager::broadcast_node_announcement`]: crate::ln::peer_handler::PeerManager::broadcast_node_announcement
1689 BroadcastChannelAnnouncement {
1690 /// The channel_announcement which should be sent.
1691 msg: msgs::ChannelAnnouncement,
1692 /// The followup channel_update which should be sent.
1693 update_msg: Option<msgs::ChannelUpdate>,
1695 /// Used to indicate that a channel_update should be broadcast to all peers.
1696 BroadcastChannelUpdate {
1697 /// The channel_update which should be sent.
1698 msg: msgs::ChannelUpdate,
1700 /// Used to indicate that a node_announcement should be broadcast to all peers.
1701 BroadcastNodeAnnouncement {
1702 /// The node_announcement which should be sent.
1703 msg: msgs::NodeAnnouncement,
1705 /// Used to indicate that a channel_update should be sent to a single peer.
1706 /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
1707 /// private channel and we shouldn't be informing all of our peers of channel parameters.
1709 /// The node_id of the node which should receive this message
1711 /// The channel_update which should be sent.
1712 msg: msgs::ChannelUpdate,
1714 /// Broadcast an error downstream to be handled
1716 /// The node_id of the node which should receive this message
1718 /// The action which should be taken.
1719 action: msgs::ErrorAction
1721 /// Query a peer for channels with funding transaction UTXOs in a block range.
1722 SendChannelRangeQuery {
1723 /// The node_id of this message recipient
1725 /// The query_channel_range which should be sent.
1726 msg: msgs::QueryChannelRange,
1728 /// Request routing gossip messages from a peer for a list of channels identified by
1729 /// their short_channel_ids.
1731 /// The node_id of this message recipient
1733 /// The query_short_channel_ids which should be sent.
1734 msg: msgs::QueryShortChannelIds,
1736 /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
1737 /// emitted during processing of the query.
1738 SendReplyChannelRange {
1739 /// The node_id of this message recipient
1741 /// The reply_channel_range which should be sent.
1742 msg: msgs::ReplyChannelRange,
1744 /// Sends a timestamp filter for inbound gossip. This should be sent on each new connection to
1745 /// enable receiving gossip messages from the peer.
1746 SendGossipTimestampFilter {
1747 /// The node_id of this message recipient
1749 /// The gossip_timestamp_filter which should be sent.
1750 msg: msgs::GossipTimestampFilter,
1754 /// A trait indicating an object may generate message send events
1755 pub trait MessageSendEventsProvider {
1756 /// Gets the list of pending events which were generated by previous actions, clearing the list
1758 fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent>;
1761 /// A trait indicating an object may generate onion messages to send
1762 pub trait OnionMessageProvider {
1763 /// Gets the next pending onion message for the peer with the given node id.
1764 fn next_onion_message_for_peer(&self, peer_node_id: PublicKey) -> Option<msgs::OnionMessage>;
1767 /// A trait indicating an object may generate events.
1769 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
1771 /// Implementations of this trait may also feature an async version of event handling, as shown with
1772 /// [`ChannelManager::process_pending_events_async`] and
1773 /// [`ChainMonitor::process_pending_events_async`].
1777 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
1778 /// event since the last invocation.
1780 /// In order to ensure no [`Event`]s are lost, implementors of this trait will persist [`Event`]s
1781 /// and replay any unhandled events on startup. An [`Event`] is considered handled when
1782 /// [`process_pending_events`] returns, thus handlers MUST fully handle [`Event`]s and persist any
1783 /// relevant changes to disk *before* returning.
1785 /// Further, because an application may crash between an [`Event`] being handled and the
1786 /// implementor of this trait being re-serialized, [`Event`] handling must be idempotent - in
1787 /// effect, [`Event`]s may be replayed.
1789 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
1790 /// consult the provider's documentation on the implication of processing events and how a handler
1791 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
1792 /// [`ChainMonitor::process_pending_events`]).
1794 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
1797 /// [`process_pending_events`]: Self::process_pending_events
1798 /// [`handle_event`]: EventHandler::handle_event
1799 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
1800 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
1801 /// [`ChannelManager::process_pending_events_async`]: crate::ln::channelmanager::ChannelManager::process_pending_events_async
1802 /// [`ChainMonitor::process_pending_events_async`]: crate::chain::chainmonitor::ChainMonitor::process_pending_events_async
1803 pub trait EventsProvider {
1804 /// Processes any events generated since the last call using the given event handler.
1806 /// See the trait-level documentation for requirements.
1807 fn process_pending_events<H: Deref>(&self, handler: H) where H::Target: EventHandler;
1810 /// A trait implemented for objects handling events from [`EventsProvider`].
1812 /// An async variation also exists for implementations of [`EventsProvider`] that support async
1813 /// event handling. The async event handler should satisfy the generic bounds: `F:
1814 /// core::future::Future, H: Fn(Event) -> F`.
1815 pub trait EventHandler {
1816 /// Handles the given [`Event`].
1818 /// See [`EventsProvider`] for details that must be considered when implementing this method.
1819 fn handle_event(&self, event: Event);
1822 impl<F> EventHandler for F where F: Fn(Event) {
1823 fn handle_event(&self, event: Event) {
1828 impl<T: EventHandler> EventHandler for Arc<T> {
1829 fn handle_event(&self, event: Event) {
1830 self.deref().handle_event(event)