Add channel funding txo to Channel Event::ChannelClosed
[rust-lightning] / lightning / src / events / mod.rs
1 // This file is Copyright its original authors, visible in version control
2 // history.
3 //
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
8 // licenses.
9
10 //! Events are returned from various bits in the library which indicate some action must be taken
11 //! by the client.
12 //!
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
15 //! few other things.
16
17 pub mod bump_transaction;
18
19 pub use bump_transaction::BumpTransactionEvent;
20
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;
25 use crate::ln::msgs;
26 use crate::ln::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
27 use crate::chain::transaction;
28 use crate::routing::gossip::NetworkUpdate;
29 use crate::util::errors::APIError;
30 use crate::util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable, RequiredWrapper, UpgradableRequired, WithoutLength};
31 use crate::util::string::UntrustedString;
32 use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters};
33
34 use bitcoin::{Transaction, OutPoint};
35 use bitcoin::blockdata::locktime::absolute::LockTime;
36 use bitcoin::blockdata::script::ScriptBuf;
37 use bitcoin::hashes::Hash;
38 use bitcoin::hashes::sha256::Hash as Sha256;
39 use bitcoin::secp256k1::PublicKey;
40 use crate::io;
41 use crate::prelude::*;
42 use core::time::Duration;
43 use core::ops::Deref;
44 use crate::sync::Arc;
45
46 /// Some information provided on receipt of payment depends on whether the payment received is a
47 /// spontaneous payment or a "conventional" lightning payment that's paying an invoice.
48 #[derive(Clone, Debug, PartialEq, Eq)]
49 pub enum PaymentPurpose {
50         /// Information for receiving a payment that we generated an invoice for.
51         InvoicePayment {
52                 /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via
53                 /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
54                 /// [`ChannelManager::claim_funds`].
55                 ///
56                 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
57                 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
58                 payment_preimage: Option<PaymentPreimage>,
59                 /// The "payment secret". This authenticates the sender to the recipient, preventing a
60                 /// number of deanonymization attacks during the routing process.
61                 /// It is provided here for your reference, however its accuracy is enforced directly by
62                 /// [`ChannelManager`] using the values you previously provided to
63                 /// [`ChannelManager::create_inbound_payment`] or
64                 /// [`ChannelManager::create_inbound_payment_for_hash`].
65                 ///
66                 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
67                 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
68                 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
69                 payment_secret: PaymentSecret,
70         },
71         /// Because this is a spontaneous payment, the payer generated their own preimage rather than us
72         /// (the payee) providing a preimage.
73         SpontaneousPayment(PaymentPreimage),
74 }
75
76 impl PaymentPurpose {
77         /// Returns the preimage for this payment, if it is known.
78         pub fn preimage(&self) -> Option<PaymentPreimage> {
79                 match self {
80                         PaymentPurpose::InvoicePayment { payment_preimage, .. } => *payment_preimage,
81                         PaymentPurpose::SpontaneousPayment(preimage) => Some(*preimage),
82                 }
83         }
84 }
85
86 impl_writeable_tlv_based_enum!(PaymentPurpose,
87         (0, InvoicePayment) => {
88                 (0, payment_preimage, option),
89                 (2, payment_secret, required),
90         };
91         (2, SpontaneousPayment)
92 );
93
94 /// Information about an HTLC that is part of a payment that can be claimed.
95 #[derive(Clone, Debug, PartialEq, Eq)]
96 pub struct ClaimedHTLC {
97         /// The `channel_id` of the channel over which the HTLC was received.
98         pub channel_id: ChannelId,
99         /// The `user_channel_id` of the channel over which the HTLC was received. This is the value
100         /// passed in to [`ChannelManager::create_channel`] for outbound channels, or to
101         /// [`ChannelManager::accept_inbound_channel`] for inbound channels if
102         /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
103         /// `user_channel_id` will be randomized for an inbound channel.
104         ///
105         /// This field will be zero for a payment that was serialized prior to LDK version 0.0.117. (This
106         /// should only happen in the case that a payment was claimable prior to LDK version 0.0.117, but
107         /// was not actually claimed until after upgrading.)
108         ///
109         /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
110         /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
111         /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
112         pub user_channel_id: u128,
113         /// The block height at which this HTLC expires.
114         pub cltv_expiry: u32,
115         /// The amount (in msats) of this part of an MPP.
116         pub value_msat: u64,
117         /// The extra fee our counterparty skimmed off the top of this HTLC, if any.
118         ///
119         /// This value will always be 0 for [`ClaimedHTLC`]s serialized with LDK versions prior to
120         /// 0.0.119.
121         pub counterparty_skimmed_fee_msat: u64,
122 }
123 impl_writeable_tlv_based!(ClaimedHTLC, {
124         (0, channel_id, required),
125         (1, counterparty_skimmed_fee_msat, (default_value, 0u64)),
126         (2, user_channel_id, required),
127         (4, cltv_expiry, required),
128         (6, value_msat, required),
129 });
130
131 /// When the payment path failure took place and extra details about it. [`PathFailure::OnPath`] may
132 /// contain a [`NetworkUpdate`] that needs to be applied to the [`NetworkGraph`].
133 ///
134 /// [`NetworkUpdate`]: crate::routing::gossip::NetworkUpdate
135 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
136 #[derive(Clone, Debug, Eq, PartialEq)]
137 pub enum PathFailure {
138         /// We failed to initially send the payment and no HTLC was committed to. Contains the relevant
139         /// error.
140         InitialSend {
141                 /// The error surfaced from initial send.
142                 err: APIError,
143         },
144         /// A hop on the path failed to forward our payment.
145         OnPath {
146                 /// If present, this [`NetworkUpdate`] should be applied to the [`NetworkGraph`] so that routing
147                 /// decisions can take into account the update.
148                 ///
149                 /// [`NetworkUpdate`]: crate::routing::gossip::NetworkUpdate
150                 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
151                 network_update: Option<NetworkUpdate>,
152         },
153 }
154
155 impl_writeable_tlv_based_enum_upgradable!(PathFailure,
156         (0, OnPath) => {
157                 (0, network_update, upgradable_option),
158         },
159         (2, InitialSend) => {
160                 (0, err, upgradable_required),
161         },
162 );
163
164 #[derive(Clone, Debug, PartialEq, Eq)]
165 /// The reason the channel was closed. See individual variants for more details.
166 pub enum ClosureReason {
167         /// Closure generated from receiving a peer error message.
168         ///
169         /// Our counterparty may have broadcasted their latest commitment state, and we have
170         /// as well.
171         CounterpartyForceClosed {
172                 /// The error which the peer sent us.
173                 ///
174                 /// Be careful about printing the peer_msg, a well-crafted message could exploit
175                 /// a security vulnerability in the terminal emulator or the logging subsystem.
176                 /// To be safe, use `Display` on `UntrustedString`
177                 ///
178                 /// [`UntrustedString`]: crate::util::string::UntrustedString
179                 peer_msg: UntrustedString,
180         },
181         /// Closure generated from [`ChannelManager::force_close_channel`], called by the user.
182         ///
183         /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
184         HolderForceClosed,
185         /// The channel was closed after negotiating a cooperative close and we've now broadcasted
186         /// the cooperative close transaction. Note the shutdown may have been initiated by us.
187         //TODO: split between CounterpartyInitiated/LocallyInitiated
188         CooperativeClosure,
189         /// A commitment transaction was confirmed on chain, closing the channel. Most likely this
190         /// commitment transaction came from our counterparty, but it may also have come from
191         /// a copy of our own `ChannelMonitor`.
192         CommitmentTxConfirmed,
193         /// The funding transaction failed to confirm in a timely manner on an inbound channel.
194         FundingTimedOut,
195         /// Closure generated from processing an event, likely a HTLC forward/relay/reception.
196         ProcessingError {
197                 /// A developer-readable error message which we generated.
198                 err: String,
199         },
200         /// The peer disconnected prior to funding completing. In this case the spec mandates that we
201         /// forget the channel entirely - we can attempt again if the peer reconnects.
202         ///
203         /// This includes cases where we restarted prior to funding completion, including prior to the
204         /// initial [`ChannelMonitor`] persistence completing.
205         ///
206         /// In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the
207         /// peer because of mutual incompatibility between us and our channel counterparty.
208         ///
209         /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
210         DisconnectedPeer,
211         /// Closure generated from `ChannelManager::read` if the [`ChannelMonitor`] is newer than
212         /// the [`ChannelManager`] deserialized.
213         ///
214         /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
215         /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
216         OutdatedChannelManager,
217         /// The counterparty requested a cooperative close of a channel that had not been funded yet.
218         /// The channel has been immediately closed.
219         CounterpartyCoopClosedUnfundedChannel,
220         /// Another channel in the same funding batch closed before the funding transaction
221         /// was ready to be broadcast.
222         FundingBatchClosure,
223 }
224
225 impl core::fmt::Display for ClosureReason {
226         fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
227                 f.write_str("Channel closed because ")?;
228                 match self {
229                         ClosureReason::CounterpartyForceClosed { peer_msg } => {
230                                 f.write_fmt(format_args!("counterparty force-closed with message: {}", peer_msg))
231                         },
232                         ClosureReason::HolderForceClosed => f.write_str("user manually force-closed the channel"),
233                         ClosureReason::CooperativeClosure => f.write_str("the channel was cooperatively closed"),
234                         ClosureReason::CommitmentTxConfirmed => f.write_str("commitment or closing transaction was confirmed on chain."),
235                         ClosureReason::FundingTimedOut => write!(f, "funding transaction failed to confirm within {} blocks", FUNDING_CONF_DEADLINE_BLOCKS),
236                         ClosureReason::ProcessingError { err } => {
237                                 f.write_str("of an exception: ")?;
238                                 f.write_str(&err)
239                         },
240                         ClosureReason::DisconnectedPeer => f.write_str("the peer disconnected prior to the channel being funded"),
241                         ClosureReason::OutdatedChannelManager => f.write_str("the ChannelManager read from disk was stale compared to ChannelMonitor(s)"),
242                         ClosureReason::CounterpartyCoopClosedUnfundedChannel => f.write_str("the peer requested the unfunded channel be closed"),
243                         ClosureReason::FundingBatchClosure => f.write_str("another channel in the same funding batch closed"),
244                 }
245         }
246 }
247
248 impl_writeable_tlv_based_enum_upgradable!(ClosureReason,
249         (0, CounterpartyForceClosed) => { (1, peer_msg, required) },
250         (1, FundingTimedOut) => {},
251         (2, HolderForceClosed) => {},
252         (6, CommitmentTxConfirmed) => {},
253         (4, CooperativeClosure) => {},
254         (8, ProcessingError) => { (1, err, required) },
255         (10, DisconnectedPeer) => {},
256         (12, OutdatedChannelManager) => {},
257         (13, CounterpartyCoopClosedUnfundedChannel) => {},
258         (15, FundingBatchClosure) => {}
259 );
260
261 /// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
262 #[derive(Clone, Debug, PartialEq, Eq)]
263 pub enum HTLCDestination {
264         /// We tried forwarding to a channel but failed to do so. An example of such an instance is when
265         /// there is insufficient capacity in our outbound channel.
266         NextHopChannel {
267                 /// The `node_id` of the next node. For backwards compatibility, this field is
268                 /// marked as optional, versions prior to 0.0.110 may not always be able to provide
269                 /// counterparty node information.
270                 node_id: Option<PublicKey>,
271                 /// The outgoing `channel_id` between us and the next node.
272                 channel_id: ChannelId,
273         },
274         /// Scenario where we are unsure of the next node to forward the HTLC to.
275         UnknownNextHop {
276                 /// Short channel id we are requesting to forward an HTLC to.
277                 requested_forward_scid: u64,
278         },
279         /// We couldn't forward to the outgoing scid. An example would be attempting to send a duplicate
280         /// intercept HTLC.
281         InvalidForward {
282                 /// Short channel id we are requesting to forward an HTLC to.
283                 requested_forward_scid: u64
284         },
285         /// Failure scenario where an HTLC may have been forwarded to be intended for us,
286         /// but is invalid for some reason, so we reject it.
287         ///
288         /// Some of the reasons may include:
289         /// * HTLC Timeouts
290         /// * Excess HTLCs for a payment that we have already fully received, over-paying for the
291         ///   payment,
292         /// * The counterparty node modified the HTLC in transit,
293         /// * A probing attack where an intermediary node is trying to detect if we are the ultimate
294         ///   recipient for a payment.
295         FailedPayment {
296                 /// The payment hash of the payment we attempted to process.
297                 payment_hash: PaymentHash
298         },
299 }
300
301 impl_writeable_tlv_based_enum_upgradable!(HTLCDestination,
302         (0, NextHopChannel) => {
303                 (0, node_id, required),
304                 (2, channel_id, required),
305         },
306         (1, InvalidForward) => {
307                 (0, requested_forward_scid, required),
308         },
309         (2, UnknownNextHop) => {
310                 (0, requested_forward_scid, required),
311         },
312         (4, FailedPayment) => {
313                 (0, payment_hash, required),
314         },
315 );
316
317 /// Will be used in [`Event::HTLCIntercepted`] to identify the next hop in the HTLC's path.
318 /// Currently only used in serialization for the sake of maintaining compatibility. More variants
319 /// will be added for general-purpose HTLC forward intercepts as well as trampoline forward
320 /// intercepts in upcoming work.
321 enum InterceptNextHop {
322         FakeScid {
323                 requested_next_hop_scid: u64,
324         },
325 }
326
327 impl_writeable_tlv_based_enum!(InterceptNextHop,
328         (0, FakeScid) => {
329                 (0, requested_next_hop_scid, required),
330         };
331 );
332
333 /// The reason the payment failed. Used in [`Event::PaymentFailed`].
334 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
335 pub enum PaymentFailureReason {
336         /// The intended recipient rejected our payment.
337         RecipientRejected,
338         /// The user chose to abandon this payment by calling [`ChannelManager::abandon_payment`].
339         ///
340         /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
341         UserAbandoned,
342         /// We exhausted all of our retry attempts while trying to send the payment, or we
343         /// exhausted the [`Retry::Timeout`] if the user set one. If at any point a retry
344         /// attempt failed while being forwarded along the path, an [`Event::PaymentPathFailed`] will
345         /// have come before this.
346         ///
347         /// [`Retry::Timeout`]: crate::ln::channelmanager::Retry::Timeout
348         RetriesExhausted,
349         /// The payment expired while retrying, based on the provided
350         /// [`PaymentParameters::expiry_time`].
351         ///
352         /// [`PaymentParameters::expiry_time`]: crate::routing::router::PaymentParameters::expiry_time
353         PaymentExpired,
354         /// We failed to find a route while retrying the payment.
355         RouteNotFound,
356         /// This error should generally never happen. This likely means that there is a problem with
357         /// your router.
358         UnexpectedError,
359 }
360
361 impl_writeable_tlv_based_enum!(PaymentFailureReason,
362         (0, RecipientRejected) => {},
363         (2, UserAbandoned) => {},
364         (4, RetriesExhausted) => {},
365         (6, PaymentExpired) => {},
366         (8, RouteNotFound) => {},
367         (10, UnexpectedError) => {}, ;
368 );
369
370 /// An Event which you should probably take some action in response to.
371 ///
372 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
373 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
374 /// written as it makes no sense to respond to it after reconnecting to peers).
375 #[derive(Clone, Debug, PartialEq, Eq)]
376 pub enum Event {
377         /// Used to indicate that the client should generate a funding transaction with the given
378         /// parameters and then call [`ChannelManager::funding_transaction_generated`].
379         /// Generated in [`ChannelManager`] message handling.
380         /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
381         /// counterparty can steal your funds!
382         ///
383         /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
384         /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
385         FundingGenerationReady {
386                 /// The random channel_id we picked which you'll need to pass into
387                 /// [`ChannelManager::funding_transaction_generated`].
388                 ///
389                 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
390                 temporary_channel_id: ChannelId,
391                 /// The counterparty's node_id, which you'll need to pass back into
392                 /// [`ChannelManager::funding_transaction_generated`].
393                 ///
394                 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
395                 counterparty_node_id: PublicKey,
396                 /// The value, in satoshis, that the output should have.
397                 channel_value_satoshis: u64,
398                 /// The script which should be used in the transaction output.
399                 output_script: ScriptBuf,
400                 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
401                 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
402                 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
403                 /// `user_channel_id` will be randomized for an inbound channel.  This may be zero for objects
404                 /// serialized with LDK versions prior to 0.0.113.
405                 ///
406                 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
407                 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
408                 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
409                 user_channel_id: u128,
410         },
411         /// Indicates that we've been offered a payment and it needs to be claimed via calling
412         /// [`ChannelManager::claim_funds`] with the preimage given in [`PaymentPurpose`].
413         ///
414         /// Note that if the preimage is not known, you should call
415         /// [`ChannelManager::fail_htlc_backwards`] or [`ChannelManager::fail_htlc_backwards_with_reason`]
416         /// to free up resources for this HTLC and avoid network congestion.
417         ///
418         /// If [`Event::PaymentClaimable::onion_fields`] is `Some`, and includes custom TLVs with even type
419         /// numbers, you should use [`ChannelManager::fail_htlc_backwards_with_reason`] with
420         /// [`FailureCode::InvalidOnionPayload`] if you fail to understand and handle the contents, or
421         /// [`ChannelManager::claim_funds_with_known_custom_tlvs`] upon successful handling.
422         /// If you don't intend to check for custom TLVs, you can simply use
423         /// [`ChannelManager::claim_funds`], which will automatically fail back even custom TLVs.
424         ///
425         /// If you fail to call [`ChannelManager::claim_funds`],
426         /// [`ChannelManager::claim_funds_with_known_custom_tlvs`],
427         /// [`ChannelManager::fail_htlc_backwards`], or
428         /// [`ChannelManager::fail_htlc_backwards_with_reason`] within the HTLC's timeout, the HTLC will
429         /// be automatically failed.
430         ///
431         /// # Note
432         /// LDK will not stop an inbound payment from being paid multiple times, so multiple
433         /// `PaymentClaimable` events may be generated for the same payment. In such a case it is
434         /// polite (and required in the lightning specification) to fail the payment the second time
435         /// and give the sender their money back rather than accepting double payment.
436         ///
437         /// # Note
438         /// This event used to be called `PaymentReceived` in LDK versions 0.0.112 and earlier.
439         ///
440         /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
441         /// [`ChannelManager::claim_funds_with_known_custom_tlvs`]: crate::ln::channelmanager::ChannelManager::claim_funds_with_known_custom_tlvs
442         /// [`FailureCode::InvalidOnionPayload`]: crate::ln::channelmanager::FailureCode::InvalidOnionPayload
443         /// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards
444         /// [`ChannelManager::fail_htlc_backwards_with_reason`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards_with_reason
445         PaymentClaimable {
446                 /// The node that will receive the payment after it has been claimed.
447                 /// This is useful to identify payments received via [phantom nodes].
448                 /// This field will always be filled in when the event was generated by LDK versions
449                 /// 0.0.113 and above.
450                 ///
451                 /// [phantom nodes]: crate::sign::PhantomKeysManager
452                 receiver_node_id: Option<PublicKey>,
453                 /// The hash for which the preimage should be handed to the ChannelManager. Note that LDK will
454                 /// not stop you from registering duplicate payment hashes for inbound payments.
455                 payment_hash: PaymentHash,
456                 /// The fields in the onion which were received with each HTLC. Only fields which were
457                 /// identical in each HTLC involved in the payment will be included here.
458                 ///
459                 /// Payments received on LDK versions prior to 0.0.115 will have this field unset.
460                 onion_fields: Option<RecipientOnionFields>,
461                 /// The value, in thousandths of a satoshi, that this payment is claimable for. May be greater
462                 /// than the invoice amount.
463                 ///
464                 /// May be less than the invoice amount if [`ChannelConfig::accept_underpaying_htlcs`] is set
465                 /// and the previous hop took an extra fee.
466                 ///
467                 /// # Note
468                 /// If [`ChannelConfig::accept_underpaying_htlcs`] is set and you claim without verifying this
469                 /// field, you may lose money!
470                 ///
471                 /// [`ChannelConfig::accept_underpaying_htlcs`]: crate::util::config::ChannelConfig::accept_underpaying_htlcs
472                 amount_msat: u64,
473                 /// The value, in thousands of a satoshi, that was skimmed off of this payment as an extra fee
474                 /// taken by our channel counterparty.
475                 ///
476                 /// Will always be 0 unless [`ChannelConfig::accept_underpaying_htlcs`] is set.
477                 ///
478                 /// [`ChannelConfig::accept_underpaying_htlcs`]: crate::util::config::ChannelConfig::accept_underpaying_htlcs
479                 counterparty_skimmed_fee_msat: u64,
480                 /// Information for claiming this received payment, based on whether the purpose of the
481                 /// payment is to pay an invoice or to send a spontaneous payment.
482                 purpose: PaymentPurpose,
483                 /// The `channel_id` indicating over which channel we received the payment.
484                 via_channel_id: Option<ChannelId>,
485                 /// The `user_channel_id` indicating over which channel we received the payment.
486                 via_user_channel_id: Option<u128>,
487                 /// The block height at which this payment will be failed back and will no longer be
488                 /// eligible for claiming.
489                 ///
490                 /// Prior to this height, a call to [`ChannelManager::claim_funds`] is guaranteed to
491                 /// succeed, however you should wait for [`Event::PaymentClaimed`] to be sure.
492                 ///
493                 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
494                 claim_deadline: Option<u32>,
495         },
496         /// Indicates a payment has been claimed and we've received money!
497         ///
498         /// This most likely occurs when [`ChannelManager::claim_funds`] has been called in response
499         /// to an [`Event::PaymentClaimable`]. However, if we previously crashed during a
500         /// [`ChannelManager::claim_funds`] call you may see this event without a corresponding
501         /// [`Event::PaymentClaimable`] event.
502         ///
503         /// # Note
504         /// LDK will not stop an inbound payment from being paid multiple times, so multiple
505         /// `PaymentClaimable` events may be generated for the same payment. If you then call
506         /// [`ChannelManager::claim_funds`] twice for the same [`Event::PaymentClaimable`] you may get
507         /// multiple `PaymentClaimed` events.
508         ///
509         /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
510         PaymentClaimed {
511                 /// The node that received the payment.
512                 /// This is useful to identify payments which were received via [phantom nodes].
513                 /// This field will always be filled in when the event was generated by LDK versions
514                 /// 0.0.113 and above.
515                 ///
516                 /// [phantom nodes]: crate::sign::PhantomKeysManager
517                 receiver_node_id: Option<PublicKey>,
518                 /// The payment hash of the claimed payment. Note that LDK will not stop you from
519                 /// registering duplicate payment hashes for inbound payments.
520                 payment_hash: PaymentHash,
521                 /// The value, in thousandths of a satoshi, that this payment is for. May be greater than the
522                 /// invoice amount.
523                 amount_msat: u64,
524                 /// The purpose of the claimed payment, i.e. whether the payment was for an invoice or a
525                 /// spontaneous payment.
526                 purpose: PaymentPurpose,
527                 /// The HTLCs that comprise the claimed payment. This will be empty for events serialized prior
528                 /// to LDK version 0.0.117.
529                 htlcs: Vec<ClaimedHTLC>,
530                 /// The sender-intended sum total of all the MPP parts. This will be `None` for events
531                 /// serialized prior to LDK version 0.0.117.
532                 sender_intended_total_msat: Option<u64>,
533         },
534         /// Indicates that a peer connection with a node is needed in order to send an [`OnionMessage`].
535         ///
536         /// Typically, this happens when a [`MessageRouter`] is unable to find a complete path to a
537         /// [`Destination`]. Once a connection is established, any messages buffered by an
538         /// [`OnionMessageHandler`] may be sent.
539         ///
540         /// This event will not be generated for onion message forwards; only for sends including
541         /// replies. Handlers should connect to the node otherwise any buffered messages may be lost.
542         ///
543         /// [`OnionMessage`]: msgs::OnionMessage
544         /// [`MessageRouter`]: crate::onion_message::MessageRouter
545         /// [`Destination`]: crate::onion_message::Destination
546         /// [`OnionMessageHandler`]: crate::ln::msgs::OnionMessageHandler
547         ConnectionNeeded {
548                 /// The node id for the node needing a connection.
549                 node_id: PublicKey,
550                 /// Sockets for connecting to the node.
551                 addresses: Vec<msgs::SocketAddress>,
552         },
553         /// Indicates a request for an invoice failed to yield a response in a reasonable amount of time
554         /// or was explicitly abandoned by [`ChannelManager::abandon_payment`]. This may be for an
555         /// [`InvoiceRequest`] sent for an [`Offer`] or for a [`Refund`] that hasn't been redeemed.
556         ///
557         /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
558         /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
559         /// [`Offer`]: crate::offers::offer::Offer
560         /// [`Refund`]: crate::offers::refund::Refund
561         InvoiceRequestFailed {
562                 /// The `payment_id` to have been associated with payment for the requested invoice.
563                 payment_id: PaymentId,
564         },
565         /// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
566         /// and we got back the payment preimage for it).
567         ///
568         /// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed`
569         /// event. In this situation, you SHOULD treat this payment as having succeeded.
570         PaymentSent {
571                 /// The `payment_id` passed to [`ChannelManager::send_payment`].
572                 ///
573                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
574                 payment_id: Option<PaymentId>,
575                 /// The preimage to the hash given to ChannelManager::send_payment.
576                 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
577                 /// store it somehow!
578                 payment_preimage: PaymentPreimage,
579                 /// The hash that was given to [`ChannelManager::send_payment`].
580                 ///
581                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
582                 payment_hash: PaymentHash,
583                 /// The total fee which was spent at intermediate hops in this payment, across all paths.
584                 ///
585                 /// Note that, like [`Route::get_total_fees`] this does *not* include any potential
586                 /// overpayment to the recipient node.
587                 ///
588                 /// If the recipient or an intermediate node misbehaves and gives us free money, this may
589                 /// overstate the amount paid, though this is unlikely.
590                 ///
591                 /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees
592                 fee_paid_msat: Option<u64>,
593         },
594         /// Indicates an outbound payment failed. Individual [`Event::PaymentPathFailed`] events
595         /// provide failure information for each path attempt in the payment, including retries.
596         ///
597         /// This event is provided once there are no further pending HTLCs for the payment and the
598         /// payment is no longer retryable, due either to the [`Retry`] provided or
599         /// [`ChannelManager::abandon_payment`] having been called for the corresponding payment.
600         ///
601         /// In exceedingly rare cases, it is possible that an [`Event::PaymentFailed`] is generated for
602         /// a payment after an [`Event::PaymentSent`] event for this same payment has already been
603         /// received and processed. In this case, the [`Event::PaymentFailed`] event MUST be ignored,
604         /// and the payment MUST be treated as having succeeded.
605         ///
606         /// [`Retry`]: crate::ln::channelmanager::Retry
607         /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
608         PaymentFailed {
609                 /// The `payment_id` passed to [`ChannelManager::send_payment`].
610                 ///
611                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
612                 payment_id: PaymentId,
613                 /// The hash that was given to [`ChannelManager::send_payment`].
614                 ///
615                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
616                 payment_hash: PaymentHash,
617                 /// The reason the payment failed. This is only `None` for events generated or serialized
618                 /// by versions prior to 0.0.115.
619                 reason: Option<PaymentFailureReason>,
620         },
621         /// Indicates that a path for an outbound payment was successful.
622         ///
623         /// Always generated after [`Event::PaymentSent`] and thus useful for scoring channels. See
624         /// [`Event::PaymentSent`] for obtaining the payment preimage.
625         PaymentPathSuccessful {
626                 /// The `payment_id` passed to [`ChannelManager::send_payment`].
627                 ///
628                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
629                 payment_id: PaymentId,
630                 /// The hash that was given to [`ChannelManager::send_payment`].
631                 ///
632                 /// This will be `Some` for all payments which completed on LDK 0.0.104 or later.
633                 ///
634                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
635                 payment_hash: Option<PaymentHash>,
636                 /// The payment path that was successful.
637                 ///
638                 /// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
639                 path: Path,
640         },
641         /// Indicates an outbound HTLC we sent failed, likely due to an intermediary node being unable to
642         /// handle the HTLC.
643         ///
644         /// Note that this does *not* indicate that all paths for an MPP payment have failed, see
645         /// [`Event::PaymentFailed`].
646         ///
647         /// See [`ChannelManager::abandon_payment`] for giving up on this payment before its retries have
648         /// been exhausted.
649         ///
650         /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
651         PaymentPathFailed {
652                 /// The `payment_id` passed to [`ChannelManager::send_payment`].
653                 ///
654                 /// This will be `Some` for all payment paths which failed on LDK 0.0.103 or later.
655                 ///
656                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
657                 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
658                 payment_id: Option<PaymentId>,
659                 /// The hash that was given to [`ChannelManager::send_payment`].
660                 ///
661                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
662                 payment_hash: PaymentHash,
663                 /// Indicates the payment was rejected for some reason by the recipient. This implies that
664                 /// the payment has failed, not just the route in question. If this is not set, the payment may
665                 /// be retried via a different route.
666                 payment_failed_permanently: bool,
667                 /// Extra error details based on the failure type. May contain an update that needs to be
668                 /// applied to the [`NetworkGraph`].
669                 ///
670                 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
671                 failure: PathFailure,
672                 /// The payment path that failed.
673                 path: Path,
674                 /// The channel responsible for the failed payment path.
675                 ///
676                 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
677                 /// may not refer to a channel in the public network graph. These aliases may also collide
678                 /// with channels in the public network graph.
679                 ///
680                 /// If this is `Some`, then the corresponding channel should be avoided when the payment is
681                 /// retried. May be `None` for older [`Event`] serializations.
682                 short_channel_id: Option<u64>,
683 #[cfg(test)]
684                 error_code: Option<u16>,
685 #[cfg(test)]
686                 error_data: Option<Vec<u8>>,
687         },
688         /// Indicates that a probe payment we sent returned successful, i.e., only failed at the destination.
689         ProbeSuccessful {
690                 /// The id returned by [`ChannelManager::send_probe`].
691                 ///
692                 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
693                 payment_id: PaymentId,
694                 /// The hash generated by [`ChannelManager::send_probe`].
695                 ///
696                 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
697                 payment_hash: PaymentHash,
698                 /// The payment path that was successful.
699                 path: Path,
700         },
701         /// Indicates that a probe payment we sent failed at an intermediary node on the path.
702         ProbeFailed {
703                 /// The id returned by [`ChannelManager::send_probe`].
704                 ///
705                 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
706                 payment_id: PaymentId,
707                 /// The hash generated by [`ChannelManager::send_probe`].
708                 ///
709                 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
710                 payment_hash: PaymentHash,
711                 /// The payment path that failed.
712                 path: Path,
713                 /// The channel responsible for the failed probe.
714                 ///
715                 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
716                 /// may not refer to a channel in the public network graph. These aliases may also collide
717                 /// with channels in the public network graph.
718                 short_channel_id: Option<u64>,
719         },
720         /// Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at
721         /// a time in the future.
722         ///
723         /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
724         PendingHTLCsForwardable {
725                 /// The minimum amount of time that should be waited prior to calling
726                 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
727                 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
728                 /// now + 5*time_forwardable).
729                 time_forwardable: Duration,
730         },
731         /// Used to indicate that we've intercepted an HTLC forward. This event will only be generated if
732         /// you've encoded an intercept scid in the receiver's invoice route hints using
733         /// [`ChannelManager::get_intercept_scid`] and have set [`UserConfig::accept_intercept_htlcs`].
734         ///
735         /// [`ChannelManager::forward_intercepted_htlc`] or
736         /// [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to this event. See
737         /// their docs for more information.
738         ///
739         /// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
740         /// [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
741         /// [`ChannelManager::forward_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::forward_intercepted_htlc
742         /// [`ChannelManager::fail_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::fail_intercepted_htlc
743         HTLCIntercepted {
744                 /// An id to help LDK identify which HTLC is being forwarded or failed.
745                 intercept_id: InterceptId,
746                 /// The fake scid that was programmed as the next hop's scid, generated using
747                 /// [`ChannelManager::get_intercept_scid`].
748                 ///
749                 /// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
750                 requested_next_hop_scid: u64,
751                 /// The payment hash used for this HTLC.
752                 payment_hash: PaymentHash,
753                 /// How many msats were received on the inbound edge of this HTLC.
754                 inbound_amount_msat: u64,
755                 /// How many msats the payer intended to route to the next node. Depending on the reason you are
756                 /// intercepting this payment, you might take a fee by forwarding less than this amount.
757                 /// Forwarding less than this amount may break compatibility with LDK versions prior to 0.0.116.
758                 ///
759                 /// Note that LDK will NOT check that expected fees were factored into this value. You MUST
760                 /// check that whatever fee you want has been included here or subtract it as required. Further,
761                 /// LDK will not stop you from forwarding more than you received.
762                 expected_outbound_amount_msat: u64,
763         },
764         /// Used to indicate that an output which you should know how to spend was confirmed on chain
765         /// and is now spendable.
766         /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
767         /// counterparty spending them due to some kind of timeout. Thus, you need to store them
768         /// somewhere and spend them when you create on-chain transactions.
769         SpendableOutputs {
770                 /// The outputs which you should store as spendable by you.
771                 outputs: Vec<SpendableOutputDescriptor>,
772                 /// The `channel_id` indicating which channel the spendable outputs belong to.
773                 ///
774                 /// This will always be `Some` for events generated by LDK versions 0.0.117 and above.
775                 channel_id: Option<ChannelId>,
776         },
777         /// This event is generated when a payment has been successfully forwarded through us and a
778         /// forwarding fee earned.
779         PaymentForwarded {
780                 /// The incoming channel between the previous node and us. This is only `None` for events
781                 /// generated or serialized by versions prior to 0.0.107.
782                 prev_channel_id: Option<ChannelId>,
783                 /// The outgoing channel between the next node and us. This is only `None` for events
784                 /// generated or serialized by versions prior to 0.0.107.
785                 next_channel_id: Option<ChannelId>,
786                 /// The fee, in milli-satoshis, which was earned as a result of the payment.
787                 ///
788                 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
789                 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
790                 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
791                 /// claimed the full value in millisatoshis from the source. In this case,
792                 /// `claim_from_onchain_tx` will be set.
793                 ///
794                 /// If the channel which sent us the payment has been force-closed, we will claim the funds
795                 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
796                 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
797                 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
798                 /// `None`.
799                 fee_earned_msat: Option<u64>,
800                 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
801                 /// transaction.
802                 claim_from_onchain_tx: bool,
803                 /// The final amount forwarded, in milli-satoshis, after the fee is deducted.
804                 ///
805                 /// The caveat described above the `fee_earned_msat` field applies here as well.
806                 outbound_amount_forwarded_msat: Option<u64>,
807         },
808         /// Used to indicate that a channel with the given `channel_id` is being opened and pending
809         /// confirmation on-chain.
810         ///
811         /// This event is emitted when the funding transaction has been signed and is broadcast to the
812         /// network. For 0conf channels it will be immediately followed by the corresponding
813         /// [`Event::ChannelReady`] event.
814         ChannelPending {
815                 /// The `channel_id` of the channel that is pending confirmation.
816                 channel_id: ChannelId,
817                 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
818                 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
819                 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
820                 /// `user_channel_id` will be randomized for an inbound channel.
821                 ///
822                 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
823                 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
824                 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
825                 user_channel_id: u128,
826                 /// The `temporary_channel_id` this channel used to be known by during channel establishment.
827                 ///
828                 /// Will be `None` for channels created prior to LDK version 0.0.115.
829                 former_temporary_channel_id: Option<ChannelId>,
830                 /// The `node_id` of the channel counterparty.
831                 counterparty_node_id: PublicKey,
832                 /// The outpoint of the channel's funding transaction.
833                 funding_txo: OutPoint,
834         },
835         /// Used to indicate that a channel with the given `channel_id` is ready to
836         /// be used. This event is emitted either when the funding transaction has been confirmed
837         /// on-chain, or, in case of a 0conf channel, when both parties have confirmed the channel
838         /// establishment.
839         ChannelReady {
840                 /// The `channel_id` of the channel that is ready.
841                 channel_id: ChannelId,
842                 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
843                 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
844                 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
845                 /// `user_channel_id` will be randomized for an inbound channel.
846                 ///
847                 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
848                 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
849                 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
850                 user_channel_id: u128,
851                 /// The `node_id` of the channel counterparty.
852                 counterparty_node_id: PublicKey,
853                 /// The features that this channel will operate with.
854                 channel_type: ChannelTypeFeatures,
855         },
856         /// Used to indicate that a previously opened channel with the given `channel_id` is in the
857         /// process of closure.
858         ///
859         /// Note that this event is only triggered for accepted channels: if the
860         /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true and the channel is
861         /// rejected, no `ChannelClosed` event will be sent.
862         ///
863         /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
864         /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
865         ChannelClosed {
866                 /// The `channel_id` of the channel which has been closed. Note that on-chain transactions
867                 /// resolving the channel are likely still awaiting confirmation.
868                 channel_id: ChannelId,
869                 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
870                 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
871                 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
872                 /// `user_channel_id` will be randomized for inbound channels.
873                 /// This may be zero for inbound channels serialized prior to 0.0.113 and will always be
874                 /// zero for objects serialized with LDK versions prior to 0.0.102.
875                 ///
876                 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
877                 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
878                 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
879                 user_channel_id: u128,
880                 /// The reason the channel was closed.
881                 reason: ClosureReason,
882                 /// Counterparty in the closed channel.
883                 ///
884                 /// This field will be `None` for objects serialized prior to LDK 0.0.117.
885                 counterparty_node_id: Option<PublicKey>,
886                 /// Channel capacity of the closing channel (sats).
887                 ///
888                 /// This field will be `None` for objects serialized prior to LDK 0.0.117.
889                 channel_capacity_sats: Option<u64>,
890                 /// The original channel funding TXO; this helps checking for the existence and confirmation
891                 /// status of the closing tx.
892                 /// Note that for instances serialized in v0.0.119 or prior this will be missing (None).
893                 channel_funding_txo: Option<transaction::OutPoint>,
894         },
895         /// Used to indicate to the user that they can abandon the funding transaction and recycle the
896         /// inputs for another purpose.
897         ///
898         /// This event is not guaranteed to be generated for channels that are closed due to a restart.
899         DiscardFunding {
900                 /// The channel_id of the channel which has been closed.
901                 channel_id: ChannelId,
902                 /// The full transaction received from the user
903                 transaction: Transaction
904         },
905         /// Indicates a request to open a new channel by a peer.
906         ///
907         /// To accept the request, call [`ChannelManager::accept_inbound_channel`]. To reject the request,
908         /// call [`ChannelManager::force_close_without_broadcasting_txn`]. Note that a ['ChannelClosed`]
909         /// event will _not_ be triggered if the channel is rejected.
910         ///
911         /// The event is only triggered when a new open channel request is received and the
912         /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
913         ///
914         /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
915         /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
916         /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
917         OpenChannelRequest {
918                 /// The temporary channel ID of the channel requested to be opened.
919                 ///
920                 /// When responding to the request, the `temporary_channel_id` should be passed
921                 /// back to the ChannelManager through [`ChannelManager::accept_inbound_channel`] to accept,
922                 /// or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject.
923                 ///
924                 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
925                 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
926                 temporary_channel_id: ChannelId,
927                 /// The node_id of the counterparty requesting to open the channel.
928                 ///
929                 /// When responding to the request, the `counterparty_node_id` should be passed
930                 /// back to the `ChannelManager` through [`ChannelManager::accept_inbound_channel`] to
931                 /// accept the request, or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject the
932                 /// request.
933                 ///
934                 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
935                 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
936                 counterparty_node_id: PublicKey,
937                 /// The channel value of the requested channel.
938                 funding_satoshis: u64,
939                 /// Our starting balance in the channel if the request is accepted, in milli-satoshi.
940                 push_msat: u64,
941                 /// The features that this channel will operate with. If you reject the channel, a
942                 /// well-behaved counterparty may automatically re-attempt the channel with a new set of
943                 /// feature flags.
944                 ///
945                 /// Note that if [`ChannelTypeFeatures::supports_scid_privacy`] returns true on this type,
946                 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
947                 /// 0.0.106.
948                 ///
949                 /// Furthermore, note that if [`ChannelTypeFeatures::supports_zero_conf`] returns true on this type,
950                 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
951                 /// 0.0.107. Channels setting this type also need to get manually accepted via
952                 /// [`crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`],
953                 /// or will be rejected otherwise.
954                 ///
955                 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
956                 channel_type: ChannelTypeFeatures,
957         },
958         /// Indicates that the HTLC was accepted, but could not be processed when or after attempting to
959         /// forward it.
960         ///
961         /// Some scenarios where this event may be sent include:
962         /// * Insufficient capacity in the outbound channel
963         /// * While waiting to forward the HTLC, the channel it is meant to be forwarded through closes
964         /// * When an unknown SCID is requested for forwarding a payment.
965         /// * Expected MPP amount has already been reached
966         /// * The HTLC has timed out
967         ///
968         /// This event, however, does not get generated if an HTLC fails to meet the forwarding
969         /// requirements (i.e. insufficient fees paid, or a CLTV that is too soon).
970         HTLCHandlingFailed {
971                 /// The channel over which the HTLC was received.
972                 prev_channel_id: ChannelId,
973                 /// Destination of the HTLC that failed to be processed.
974                 failed_next_destination: HTLCDestination,
975         },
976         /// Indicates that a transaction originating from LDK needs to have its fee bumped. This event
977         /// requires confirmed external funds to be readily available to spend.
978         ///
979         /// LDK does not currently generate this event unless the
980         /// [`ChannelHandshakeConfig::negotiate_anchors_zero_fee_htlc_tx`] config flag is set to true.
981         /// It is limited to the scope of channels with anchor outputs.
982         ///
983         /// [`ChannelHandshakeConfig::negotiate_anchors_zero_fee_htlc_tx`]: crate::util::config::ChannelHandshakeConfig::negotiate_anchors_zero_fee_htlc_tx
984         BumpTransaction(BumpTransactionEvent),
985 }
986
987 impl Writeable for Event {
988         fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
989                 match self {
990                         &Event::FundingGenerationReady { .. } => {
991                                 0u8.write(writer)?;
992                                 // We never write out FundingGenerationReady events as, upon disconnection, peers
993                                 // drop any channels which have not yet exchanged funding_signed.
994                         },
995                         &Event::PaymentClaimable { ref payment_hash, ref amount_msat, counterparty_skimmed_fee_msat,
996                                 ref purpose, ref receiver_node_id, ref via_channel_id, ref via_user_channel_id,
997                                 ref claim_deadline, ref onion_fields
998                         } => {
999                                 1u8.write(writer)?;
1000                                 let mut payment_secret = None;
1001                                 let payment_preimage;
1002                                 match &purpose {
1003                                         PaymentPurpose::InvoicePayment { payment_preimage: preimage, payment_secret: secret } => {
1004                                                 payment_secret = Some(secret);
1005                                                 payment_preimage = *preimage;
1006                                         },
1007                                         PaymentPurpose::SpontaneousPayment(preimage) => {
1008                                                 payment_preimage = Some(*preimage);
1009                                         }
1010                                 }
1011                                 let skimmed_fee_opt = if counterparty_skimmed_fee_msat == 0 { None }
1012                                         else { Some(counterparty_skimmed_fee_msat) };
1013                                 write_tlv_fields!(writer, {
1014                                         (0, payment_hash, required),
1015                                         (1, receiver_node_id, option),
1016                                         (2, payment_secret, option),
1017                                         (3, via_channel_id, option),
1018                                         (4, amount_msat, required),
1019                                         (5, via_user_channel_id, option),
1020                                         // Type 6 was `user_payment_id` on 0.0.103 and earlier
1021                                         (7, claim_deadline, option),
1022                                         (8, payment_preimage, option),
1023                                         (9, onion_fields, option),
1024                                         (10, skimmed_fee_opt, option),
1025                                 });
1026                         },
1027                         &Event::PaymentSent { ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat } => {
1028                                 2u8.write(writer)?;
1029                                 write_tlv_fields!(writer, {
1030                                         (0, payment_preimage, required),
1031                                         (1, payment_hash, required),
1032                                         (3, payment_id, option),
1033                                         (5, fee_paid_msat, option),
1034                                 });
1035                         },
1036                         &Event::PaymentPathFailed {
1037                                 ref payment_id, ref payment_hash, ref payment_failed_permanently, ref failure,
1038                                 ref path, ref short_channel_id,
1039                                 #[cfg(test)]
1040                                 ref error_code,
1041                                 #[cfg(test)]
1042                                 ref error_data,
1043                         } => {
1044                                 3u8.write(writer)?;
1045                                 #[cfg(test)]
1046                                 error_code.write(writer)?;
1047                                 #[cfg(test)]
1048                                 error_data.write(writer)?;
1049                                 write_tlv_fields!(writer, {
1050                                         (0, payment_hash, required),
1051                                         (1, None::<NetworkUpdate>, option), // network_update in LDK versions prior to 0.0.114
1052                                         (2, payment_failed_permanently, required),
1053                                         (3, false, required), // all_paths_failed in LDK versions prior to 0.0.114
1054                                         (4, path.blinded_tail, option),
1055                                         (5, path.hops, required_vec),
1056                                         (7, short_channel_id, option),
1057                                         (9, None::<RouteParameters>, option), // retry in LDK versions prior to 0.0.115
1058                                         (11, payment_id, option),
1059                                         (13, failure, required),
1060                                 });
1061                         },
1062                         &Event::PendingHTLCsForwardable { time_forwardable: _ } => {
1063                                 4u8.write(writer)?;
1064                                 // Note that we now ignore these on the read end as we'll re-generate them in
1065                                 // ChannelManager, we write them here only for backwards compatibility.
1066                         },
1067                         &Event::SpendableOutputs { ref outputs, channel_id } => {
1068                                 5u8.write(writer)?;
1069                                 write_tlv_fields!(writer, {
1070                                         (0, WithoutLength(outputs), required),
1071                                         (1, channel_id, option),
1072                                 });
1073                         },
1074                         &Event::HTLCIntercepted { requested_next_hop_scid, payment_hash, inbound_amount_msat, expected_outbound_amount_msat, intercept_id } => {
1075                                 6u8.write(writer)?;
1076                                 let intercept_scid = InterceptNextHop::FakeScid { requested_next_hop_scid };
1077                                 write_tlv_fields!(writer, {
1078                                         (0, intercept_id, required),
1079                                         (2, intercept_scid, required),
1080                                         (4, payment_hash, required),
1081                                         (6, inbound_amount_msat, required),
1082                                         (8, expected_outbound_amount_msat, required),
1083                                 });
1084                         }
1085                         &Event::PaymentForwarded {
1086                                 fee_earned_msat, prev_channel_id, claim_from_onchain_tx,
1087                                 next_channel_id, outbound_amount_forwarded_msat
1088                         } => {
1089                                 7u8.write(writer)?;
1090                                 write_tlv_fields!(writer, {
1091                                         (0, fee_earned_msat, option),
1092                                         (1, prev_channel_id, option),
1093                                         (2, claim_from_onchain_tx, required),
1094                                         (3, next_channel_id, option),
1095                                         (5, outbound_amount_forwarded_msat, option),
1096                                 });
1097                         },
1098                         &Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason,
1099                                 ref counterparty_node_id, ref channel_capacity_sats, ref channel_funding_txo
1100                         } => {
1101                                 9u8.write(writer)?;
1102                                 // `user_channel_id` used to be a single u64 value. In order to remain backwards
1103                                 // compatible with versions prior to 0.0.113, the u128 is serialized as two
1104                                 // separate u64 values.
1105                                 let user_channel_id_low = *user_channel_id as u64;
1106                                 let user_channel_id_high = (*user_channel_id >> 64) as u64;
1107                                 write_tlv_fields!(writer, {
1108                                         (0, channel_id, required),
1109                                         (1, user_channel_id_low, required),
1110                                         (2, reason, required),
1111                                         (3, user_channel_id_high, required),
1112                                         (5, counterparty_node_id, option),
1113                                         (7, channel_capacity_sats, option),
1114                                         (9, channel_funding_txo, option),
1115                                 });
1116                         },
1117                         &Event::DiscardFunding { ref channel_id, ref transaction } => {
1118                                 11u8.write(writer)?;
1119                                 write_tlv_fields!(writer, {
1120                                         (0, channel_id, required),
1121                                         (2, transaction, required)
1122                                 })
1123                         },
1124                         &Event::PaymentPathSuccessful { ref payment_id, ref payment_hash, ref path } => {
1125                                 13u8.write(writer)?;
1126                                 write_tlv_fields!(writer, {
1127                                         (0, payment_id, required),
1128                                         (2, payment_hash, option),
1129                                         (4, path.hops, required_vec),
1130                                         (6, path.blinded_tail, option),
1131                                 })
1132                         },
1133                         &Event::PaymentFailed { ref payment_id, ref payment_hash, ref reason } => {
1134                                 15u8.write(writer)?;
1135                                 write_tlv_fields!(writer, {
1136                                         (0, payment_id, required),
1137                                         (1, reason, option),
1138                                         (2, payment_hash, required),
1139                                 })
1140                         },
1141                         &Event::OpenChannelRequest { .. } => {
1142                                 17u8.write(writer)?;
1143                                 // We never write the OpenChannelRequest events as, upon disconnection, peers
1144                                 // drop any channels which have not yet exchanged funding_signed.
1145                         },
1146                         &Event::PaymentClaimed { ref payment_hash, ref amount_msat, ref purpose, ref receiver_node_id, ref htlcs, ref sender_intended_total_msat } => {
1147                                 19u8.write(writer)?;
1148                                 write_tlv_fields!(writer, {
1149                                         (0, payment_hash, required),
1150                                         (1, receiver_node_id, option),
1151                                         (2, purpose, required),
1152                                         (4, amount_msat, required),
1153                                         (5, *htlcs, optional_vec),
1154                                         (7, sender_intended_total_msat, option),
1155                                 });
1156                         },
1157                         &Event::ProbeSuccessful { ref payment_id, ref payment_hash, ref path } => {
1158                                 21u8.write(writer)?;
1159                                 write_tlv_fields!(writer, {
1160                                         (0, payment_id, required),
1161                                         (2, payment_hash, required),
1162                                         (4, path.hops, required_vec),
1163                                         (6, path.blinded_tail, option),
1164                                 })
1165                         },
1166                         &Event::ProbeFailed { ref payment_id, ref payment_hash, ref path, ref short_channel_id } => {
1167                                 23u8.write(writer)?;
1168                                 write_tlv_fields!(writer, {
1169                                         (0, payment_id, required),
1170                                         (2, payment_hash, required),
1171                                         (4, path.hops, required_vec),
1172                                         (6, short_channel_id, option),
1173                                         (8, path.blinded_tail, option),
1174                                 })
1175                         },
1176                         &Event::HTLCHandlingFailed { ref prev_channel_id, ref failed_next_destination } => {
1177                                 25u8.write(writer)?;
1178                                 write_tlv_fields!(writer, {
1179                                         (0, prev_channel_id, required),
1180                                         (2, failed_next_destination, required),
1181                                 })
1182                         },
1183                         &Event::BumpTransaction(ref event)=> {
1184                                 27u8.write(writer)?;
1185                                 match event {
1186                                         // We never write the ChannelClose|HTLCResolution events as they'll be replayed
1187                                         // upon restarting anyway if they remain unresolved.
1188                                         BumpTransactionEvent::ChannelClose { .. } => {}
1189                                         BumpTransactionEvent::HTLCResolution { .. } => {}
1190                                 }
1191                                 write_tlv_fields!(writer, {}); // Write a length field for forwards compat
1192                         }
1193                         &Event::ChannelReady { ref channel_id, ref user_channel_id, ref counterparty_node_id, ref channel_type } => {
1194                                 29u8.write(writer)?;
1195                                 write_tlv_fields!(writer, {
1196                                         (0, channel_id, required),
1197                                         (2, user_channel_id, required),
1198                                         (4, counterparty_node_id, required),
1199                                         (6, channel_type, required),
1200                                 });
1201                         },
1202                         &Event::ChannelPending { ref channel_id, ref user_channel_id, ref former_temporary_channel_id, ref counterparty_node_id, ref funding_txo } => {
1203                                 31u8.write(writer)?;
1204                                 write_tlv_fields!(writer, {
1205                                         (0, channel_id, required),
1206                                         (2, user_channel_id, required),
1207                                         (4, former_temporary_channel_id, required),
1208                                         (6, counterparty_node_id, required),
1209                                         (8, funding_txo, required),
1210                                 });
1211                         },
1212                         &Event::InvoiceRequestFailed { ref payment_id } => {
1213                                 33u8.write(writer)?;
1214                                 write_tlv_fields!(writer, {
1215                                         (0, payment_id, required),
1216                                 })
1217                         },
1218                         &Event::ConnectionNeeded { .. } => {
1219                                 35u8.write(writer)?;
1220                                 // Never write ConnectionNeeded events as buffered onion messages aren't serialized.
1221                         },
1222                         // Note that, going forward, all new events must only write data inside of
1223                         // `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
1224                         // data via `write_tlv_fields`.
1225                 }
1226                 Ok(())
1227         }
1228 }
1229 impl MaybeReadable for Event {
1230         fn read<R: io::Read>(reader: &mut R) -> Result<Option<Self>, msgs::DecodeError> {
1231                 match Readable::read(reader)? {
1232                         // Note that we do not write a length-prefixed TLV for FundingGenerationReady events.
1233                         0u8 => Ok(None),
1234                         1u8 => {
1235                                 let f = || {
1236                                         let mut payment_hash = PaymentHash([0; 32]);
1237                                         let mut payment_preimage = None;
1238                                         let mut payment_secret = None;
1239                                         let mut amount_msat = 0;
1240                                         let mut counterparty_skimmed_fee_msat_opt = None;
1241                                         let mut receiver_node_id = None;
1242                                         let mut _user_payment_id = None::<u64>; // Used in 0.0.103 and earlier, no longer written in 0.0.116+.
1243                                         let mut via_channel_id = None;
1244                                         let mut claim_deadline = None;
1245                                         let mut via_user_channel_id = None;
1246                                         let mut onion_fields = None;
1247                                         read_tlv_fields!(reader, {
1248                                                 (0, payment_hash, required),
1249                                                 (1, receiver_node_id, option),
1250                                                 (2, payment_secret, option),
1251                                                 (3, via_channel_id, option),
1252                                                 (4, amount_msat, required),
1253                                                 (5, via_user_channel_id, option),
1254                                                 (6, _user_payment_id, option),
1255                                                 (7, claim_deadline, option),
1256                                                 (8, payment_preimage, option),
1257                                                 (9, onion_fields, option),
1258                                                 (10, counterparty_skimmed_fee_msat_opt, option),
1259                                         });
1260                                         let purpose = match payment_secret {
1261                                                 Some(secret) => PaymentPurpose::InvoicePayment {
1262                                                         payment_preimage,
1263                                                         payment_secret: secret
1264                                                 },
1265                                                 None if payment_preimage.is_some() => PaymentPurpose::SpontaneousPayment(payment_preimage.unwrap()),
1266                                                 None => return Err(msgs::DecodeError::InvalidValue),
1267                                         };
1268                                         Ok(Some(Event::PaymentClaimable {
1269                                                 receiver_node_id,
1270                                                 payment_hash,
1271                                                 amount_msat,
1272                                                 counterparty_skimmed_fee_msat: counterparty_skimmed_fee_msat_opt.unwrap_or(0),
1273                                                 purpose,
1274                                                 via_channel_id,
1275                                                 via_user_channel_id,
1276                                                 claim_deadline,
1277                                                 onion_fields,
1278                                         }))
1279                                 };
1280                                 f()
1281                         },
1282                         2u8 => {
1283                                 let f = || {
1284                                         let mut payment_preimage = PaymentPreimage([0; 32]);
1285                                         let mut payment_hash = None;
1286                                         let mut payment_id = None;
1287                                         let mut fee_paid_msat = None;
1288                                         read_tlv_fields!(reader, {
1289                                                 (0, payment_preimage, required),
1290                                                 (1, payment_hash, option),
1291                                                 (3, payment_id, option),
1292                                                 (5, fee_paid_msat, option),
1293                                         });
1294                                         if payment_hash.is_none() {
1295                                                 payment_hash = Some(PaymentHash(Sha256::hash(&payment_preimage.0[..]).to_byte_array()));
1296                                         }
1297                                         Ok(Some(Event::PaymentSent {
1298                                                 payment_id,
1299                                                 payment_preimage,
1300                                                 payment_hash: payment_hash.unwrap(),
1301                                                 fee_paid_msat,
1302                                         }))
1303                                 };
1304                                 f()
1305                         },
1306                         3u8 => {
1307                                 let f = || {
1308                                         #[cfg(test)]
1309                                         let error_code = Readable::read(reader)?;
1310                                         #[cfg(test)]
1311                                         let error_data = Readable::read(reader)?;
1312                                         let mut payment_hash = PaymentHash([0; 32]);
1313                                         let mut payment_failed_permanently = false;
1314                                         let mut network_update = None;
1315                                         let mut blinded_tail: Option<BlindedTail> = None;
1316                                         let mut path: Option<Vec<RouteHop>> = Some(vec![]);
1317                                         let mut short_channel_id = None;
1318                                         let mut payment_id = None;
1319                                         let mut failure_opt = None;
1320                                         read_tlv_fields!(reader, {
1321                                                 (0, payment_hash, required),
1322                                                 (1, network_update, upgradable_option),
1323                                                 (2, payment_failed_permanently, required),
1324                                                 (4, blinded_tail, option),
1325                                                 // Added as a part of LDK 0.0.101 and always filled in since.
1326                                                 // Defaults to an empty Vec, though likely should have been `Option`al.
1327                                                 (5, path, optional_vec),
1328                                                 (7, short_channel_id, option),
1329                                                 (11, payment_id, option),
1330                                                 (13, failure_opt, upgradable_option),
1331                                         });
1332                                         let failure = failure_opt.unwrap_or_else(|| PathFailure::OnPath { network_update });
1333                                         Ok(Some(Event::PaymentPathFailed {
1334                                                 payment_id,
1335                                                 payment_hash,
1336                                                 payment_failed_permanently,
1337                                                 failure,
1338                                                 path: Path { hops: path.unwrap(), blinded_tail },
1339                                                 short_channel_id,
1340                                                 #[cfg(test)]
1341                                                 error_code,
1342                                                 #[cfg(test)]
1343                                                 error_data,
1344                                         }))
1345                                 };
1346                                 f()
1347                         },
1348                         4u8 => Ok(None),
1349                         5u8 => {
1350                                 let f = || {
1351                                         let mut outputs = WithoutLength(Vec::new());
1352                                         let mut channel_id: Option<ChannelId> = None;
1353                                         read_tlv_fields!(reader, {
1354                                                 (0, outputs, required),
1355                                                 (1, channel_id, option),
1356                                         });
1357                                         Ok(Some(Event::SpendableOutputs { outputs: outputs.0, channel_id }))
1358                                 };
1359                                 f()
1360                         },
1361                         6u8 => {
1362                                 let mut payment_hash = PaymentHash([0; 32]);
1363                                 let mut intercept_id = InterceptId([0; 32]);
1364                                 let mut requested_next_hop_scid = InterceptNextHop::FakeScid { requested_next_hop_scid: 0 };
1365                                 let mut inbound_amount_msat = 0;
1366                                 let mut expected_outbound_amount_msat = 0;
1367                                 read_tlv_fields!(reader, {
1368                                         (0, intercept_id, required),
1369                                         (2, requested_next_hop_scid, required),
1370                                         (4, payment_hash, required),
1371                                         (6, inbound_amount_msat, required),
1372                                         (8, expected_outbound_amount_msat, required),
1373                                 });
1374                                 let next_scid = match requested_next_hop_scid {
1375                                         InterceptNextHop::FakeScid { requested_next_hop_scid: scid } => scid
1376                                 };
1377                                 Ok(Some(Event::HTLCIntercepted {
1378                                         payment_hash,
1379                                         requested_next_hop_scid: next_scid,
1380                                         inbound_amount_msat,
1381                                         expected_outbound_amount_msat,
1382                                         intercept_id,
1383                                 }))
1384                         },
1385                         7u8 => {
1386                                 let f = || {
1387                                         let mut fee_earned_msat = None;
1388                                         let mut prev_channel_id = None;
1389                                         let mut claim_from_onchain_tx = false;
1390                                         let mut next_channel_id = None;
1391                                         let mut outbound_amount_forwarded_msat = None;
1392                                         read_tlv_fields!(reader, {
1393                                                 (0, fee_earned_msat, option),
1394                                                 (1, prev_channel_id, option),
1395                                                 (2, claim_from_onchain_tx, required),
1396                                                 (3, next_channel_id, option),
1397                                                 (5, outbound_amount_forwarded_msat, option),
1398                                         });
1399                                         Ok(Some(Event::PaymentForwarded {
1400                                                 fee_earned_msat, prev_channel_id, claim_from_onchain_tx, next_channel_id,
1401                                                 outbound_amount_forwarded_msat
1402                                         }))
1403                                 };
1404                                 f()
1405                         },
1406                         9u8 => {
1407                                 let f = || {
1408                                         let mut channel_id = ChannelId::new_zero();
1409                                         let mut reason = UpgradableRequired(None);
1410                                         let mut user_channel_id_low_opt: Option<u64> = None;
1411                                         let mut user_channel_id_high_opt: Option<u64> = None;
1412                                         let mut counterparty_node_id = None;
1413                                         let mut channel_capacity_sats = None;
1414                                         let mut channel_funding_txo = None;
1415                                         read_tlv_fields!(reader, {
1416                                                 (0, channel_id, required),
1417                                                 (1, user_channel_id_low_opt, option),
1418                                                 (2, reason, upgradable_required),
1419                                                 (3, user_channel_id_high_opt, option),
1420                                                 (5, counterparty_node_id, option),
1421                                                 (7, channel_capacity_sats, option),
1422                                                 (9, channel_funding_txo, option),
1423                                         });
1424
1425                                         // `user_channel_id` used to be a single u64 value. In order to remain
1426                                         // backwards compatible with versions prior to 0.0.113, the u128 is serialized
1427                                         // as two separate u64 values.
1428                                         let user_channel_id = (user_channel_id_low_opt.unwrap_or(0) as u128) +
1429                                                 ((user_channel_id_high_opt.unwrap_or(0) as u128) << 64);
1430
1431                                         Ok(Some(Event::ChannelClosed { channel_id, user_channel_id, reason: _init_tlv_based_struct_field!(reason, upgradable_required),
1432                                                 counterparty_node_id, channel_capacity_sats, channel_funding_txo }))
1433                                 };
1434                                 f()
1435                         },
1436                         11u8 => {
1437                                 let f = || {
1438                                         let mut channel_id = ChannelId::new_zero();
1439                                         let mut transaction = Transaction{ version: 2, lock_time: LockTime::ZERO, input: Vec::new(), output: Vec::new() };
1440                                         read_tlv_fields!(reader, {
1441                                                 (0, channel_id, required),
1442                                                 (2, transaction, required),
1443                                         });
1444                                         Ok(Some(Event::DiscardFunding { channel_id, transaction } ))
1445                                 };
1446                                 f()
1447                         },
1448                         13u8 => {
1449                                 let f = || {
1450                                         _init_and_read_len_prefixed_tlv_fields!(reader, {
1451                                                 (0, payment_id, required),
1452                                                 (2, payment_hash, option),
1453                                                 (4, path, required_vec),
1454                                                 (6, blinded_tail, option),
1455                                         });
1456                                         Ok(Some(Event::PaymentPathSuccessful {
1457                                                 payment_id: payment_id.0.unwrap(),
1458                                                 payment_hash,
1459                                                 path: Path { hops: path, blinded_tail },
1460                                         }))
1461                                 };
1462                                 f()
1463                         },
1464                         15u8 => {
1465                                 let f = || {
1466                                         let mut payment_hash = PaymentHash([0; 32]);
1467                                         let mut payment_id = PaymentId([0; 32]);
1468                                         let mut reason = None;
1469                                         read_tlv_fields!(reader, {
1470                                                 (0, payment_id, required),
1471                                                 (1, reason, upgradable_option),
1472                                                 (2, payment_hash, required),
1473                                         });
1474                                         Ok(Some(Event::PaymentFailed {
1475                                                 payment_id,
1476                                                 payment_hash,
1477                                                 reason,
1478                                         }))
1479                                 };
1480                                 f()
1481                         },
1482                         17u8 => {
1483                                 // Value 17 is used for `Event::OpenChannelRequest`.
1484                                 Ok(None)
1485                         },
1486                         19u8 => {
1487                                 let f = || {
1488                                         let mut payment_hash = PaymentHash([0; 32]);
1489                                         let mut purpose = UpgradableRequired(None);
1490                                         let mut amount_msat = 0;
1491                                         let mut receiver_node_id = None;
1492                                         let mut htlcs: Option<Vec<ClaimedHTLC>> = Some(vec![]);
1493                                         let mut sender_intended_total_msat: Option<u64> = None;
1494                                         read_tlv_fields!(reader, {
1495                                                 (0, payment_hash, required),
1496                                                 (1, receiver_node_id, option),
1497                                                 (2, purpose, upgradable_required),
1498                                                 (4, amount_msat, required),
1499                                                 (5, htlcs, optional_vec),
1500                                                 (7, sender_intended_total_msat, option),
1501                                         });
1502                                         Ok(Some(Event::PaymentClaimed {
1503                                                 receiver_node_id,
1504                                                 payment_hash,
1505                                                 purpose: _init_tlv_based_struct_field!(purpose, upgradable_required),
1506                                                 amount_msat,
1507                                                 htlcs: htlcs.unwrap_or(vec![]),
1508                                                 sender_intended_total_msat,
1509                                         }))
1510                                 };
1511                                 f()
1512                         },
1513                         21u8 => {
1514                                 let f = || {
1515                                         _init_and_read_len_prefixed_tlv_fields!(reader, {
1516                                                 (0, payment_id, required),
1517                                                 (2, payment_hash, required),
1518                                                 (4, path, required_vec),
1519                                                 (6, blinded_tail, option),
1520                                         });
1521                                         Ok(Some(Event::ProbeSuccessful {
1522                                                 payment_id: payment_id.0.unwrap(),
1523                                                 payment_hash: payment_hash.0.unwrap(),
1524                                                 path: Path { hops: path, blinded_tail },
1525                                         }))
1526                                 };
1527                                 f()
1528                         },
1529                         23u8 => {
1530                                 let f = || {
1531                                         _init_and_read_len_prefixed_tlv_fields!(reader, {
1532                                                 (0, payment_id, required),
1533                                                 (2, payment_hash, required),
1534                                                 (4, path, required_vec),
1535                                                 (6, short_channel_id, option),
1536                                                 (8, blinded_tail, option),
1537                                         });
1538                                         Ok(Some(Event::ProbeFailed {
1539                                                 payment_id: payment_id.0.unwrap(),
1540                                                 payment_hash: payment_hash.0.unwrap(),
1541                                                 path: Path { hops: path, blinded_tail },
1542                                                 short_channel_id,
1543                                         }))
1544                                 };
1545                                 f()
1546                         },
1547                         25u8 => {
1548                                 let f = || {
1549                                         let mut prev_channel_id = ChannelId::new_zero();
1550                                         let mut failed_next_destination_opt = UpgradableRequired(None);
1551                                         read_tlv_fields!(reader, {
1552                                                 (0, prev_channel_id, required),
1553                                                 (2, failed_next_destination_opt, upgradable_required),
1554                                         });
1555                                         Ok(Some(Event::HTLCHandlingFailed {
1556                                                 prev_channel_id,
1557                                                 failed_next_destination: _init_tlv_based_struct_field!(failed_next_destination_opt, upgradable_required),
1558                                         }))
1559                                 };
1560                                 f()
1561                         },
1562                         27u8 => Ok(None),
1563                         29u8 => {
1564                                 let f = || {
1565                                         let mut channel_id = ChannelId::new_zero();
1566                                         let mut user_channel_id: u128 = 0;
1567                                         let mut counterparty_node_id = RequiredWrapper(None);
1568                                         let mut channel_type = RequiredWrapper(None);
1569                                         read_tlv_fields!(reader, {
1570                                                 (0, channel_id, required),
1571                                                 (2, user_channel_id, required),
1572                                                 (4, counterparty_node_id, required),
1573                                                 (6, channel_type, required),
1574                                         });
1575
1576                                         Ok(Some(Event::ChannelReady {
1577                                                 channel_id,
1578                                                 user_channel_id,
1579                                                 counterparty_node_id: counterparty_node_id.0.unwrap(),
1580                                                 channel_type: channel_type.0.unwrap()
1581                                         }))
1582                                 };
1583                                 f()
1584                         },
1585                         31u8 => {
1586                                 let f = || {
1587                                         let mut channel_id = ChannelId::new_zero();
1588                                         let mut user_channel_id: u128 = 0;
1589                                         let mut former_temporary_channel_id = None;
1590                                         let mut counterparty_node_id = RequiredWrapper(None);
1591                                         let mut funding_txo = RequiredWrapper(None);
1592                                         read_tlv_fields!(reader, {
1593                                                 (0, channel_id, required),
1594                                                 (2, user_channel_id, required),
1595                                                 (4, former_temporary_channel_id, required),
1596                                                 (6, counterparty_node_id, required),
1597                                                 (8, funding_txo, required),
1598                                         });
1599
1600                                         Ok(Some(Event::ChannelPending {
1601                                                 channel_id,
1602                                                 user_channel_id,
1603                                                 former_temporary_channel_id,
1604                                                 counterparty_node_id: counterparty_node_id.0.unwrap(),
1605                                                 funding_txo: funding_txo.0.unwrap()
1606                                         }))
1607                                 };
1608                                 f()
1609                         },
1610                         33u8 => {
1611                                 let f = || {
1612                                         _init_and_read_len_prefixed_tlv_fields!(reader, {
1613                                                 (0, payment_id, required),
1614                                         });
1615                                         Ok(Some(Event::InvoiceRequestFailed {
1616                                                 payment_id: payment_id.0.unwrap(),
1617                                         }))
1618                                 };
1619                                 f()
1620                         },
1621                         // Note that we do not write a length-prefixed TLV for ConnectionNeeded events.
1622                         35u8 => Ok(None),
1623                         // Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
1624                         // Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
1625                         // reads.
1626                         x if x % 2 == 1 => {
1627                                 // If the event is of unknown type, assume it was written with `write_tlv_fields`,
1628                                 // which prefixes the whole thing with a length BigSize. Because the event is
1629                                 // odd-type unknown, we should treat it as `Ok(None)` even if it has some TLV
1630                                 // fields that are even. Thus, we avoid using `read_tlv_fields` and simply read
1631                                 // exactly the number of bytes specified, ignoring them entirely.
1632                                 let tlv_len: BigSize = Readable::read(reader)?;
1633                                 FixedLengthReader::new(reader, tlv_len.0)
1634                                         .eat_remaining().map_err(|_| msgs::DecodeError::ShortRead)?;
1635                                 Ok(None)
1636                         },
1637                         _ => Err(msgs::DecodeError::InvalidValue)
1638                 }
1639         }
1640 }
1641
1642 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
1643 /// broadcast to most peers).
1644 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
1645 #[derive(Clone, Debug)]
1646 #[cfg_attr(test, derive(PartialEq))]
1647 pub enum MessageSendEvent {
1648         /// Used to indicate that we've accepted a channel open and should send the accept_channel
1649         /// message provided to the given peer.
1650         SendAcceptChannel {
1651                 /// The node_id of the node which should receive this message
1652                 node_id: PublicKey,
1653                 /// The message which should be sent.
1654                 msg: msgs::AcceptChannel,
1655         },
1656         /// Used to indicate that we've accepted a V2 channel open and should send the accept_channel2
1657         /// message provided to the given peer.
1658         SendAcceptChannelV2 {
1659                 /// The node_id of the node which should receive this message
1660                 node_id: PublicKey,
1661                 /// The message which should be sent.
1662                 msg: msgs::AcceptChannelV2,
1663         },
1664         /// Used to indicate that we've initiated a channel open and should send the open_channel
1665         /// message provided to the given peer.
1666         SendOpenChannel {
1667                 /// The node_id of the node which should receive this message
1668                 node_id: PublicKey,
1669                 /// The message which should be sent.
1670                 msg: msgs::OpenChannel,
1671         },
1672         /// Used to indicate that we've initiated a V2 channel open and should send the open_channel2
1673         /// message provided to the given peer.
1674         SendOpenChannelV2 {
1675                 /// The node_id of the node which should receive this message
1676                 node_id: PublicKey,
1677                 /// The message which should be sent.
1678                 msg: msgs::OpenChannelV2,
1679         },
1680         /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
1681         SendFundingCreated {
1682                 /// The node_id of the node which should receive this message
1683                 node_id: PublicKey,
1684                 /// The message which should be sent.
1685                 msg: msgs::FundingCreated,
1686         },
1687         /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
1688         SendFundingSigned {
1689                 /// The node_id of the node which should receive this message
1690                 node_id: PublicKey,
1691                 /// The message which should be sent.
1692                 msg: msgs::FundingSigned,
1693         },
1694         /// Used to indicate that a stfu message should be sent to the peer with the given node id.
1695         SendStfu {
1696                 /// The node_id of the node which should receive this message
1697                 node_id: PublicKey,
1698                 /// The message which should be sent.
1699                 msg: msgs::Stfu,
1700         },
1701         /// Used to indicate that a splice message should be sent to the peer with the given node id.
1702         SendSplice {
1703                 /// The node_id of the node which should receive this message
1704                 node_id: PublicKey,
1705                 /// The message which should be sent.
1706                 msg: msgs::Splice,
1707         },
1708         /// Used to indicate that a splice_ack message should be sent to the peer with the given node id.
1709         SendSpliceAck {
1710                 /// The node_id of the node which should receive this message
1711                 node_id: PublicKey,
1712                 /// The message which should be sent.
1713                 msg: msgs::SpliceAck,
1714         },
1715         /// Used to indicate that a splice_locked message should be sent to the peer with the given node id.
1716         SendSpliceLocked {
1717                 /// The node_id of the node which should receive this message
1718                 node_id: PublicKey,
1719                 /// The message which should be sent.
1720                 msg: msgs::SpliceLocked,
1721         },
1722         /// Used to indicate that a tx_add_input message should be sent to the peer with the given node_id.
1723         SendTxAddInput {
1724                 /// The node_id of the node which should receive this message
1725                 node_id: PublicKey,
1726                 /// The message which should be sent.
1727                 msg: msgs::TxAddInput,
1728         },
1729         /// Used to indicate that a tx_add_output message should be sent to the peer with the given node_id.
1730         SendTxAddOutput {
1731                 /// The node_id of the node which should receive this message
1732                 node_id: PublicKey,
1733                 /// The message which should be sent.
1734                 msg: msgs::TxAddOutput,
1735         },
1736         /// Used to indicate that a tx_remove_input message should be sent to the peer with the given node_id.
1737         SendTxRemoveInput {
1738                 /// The node_id of the node which should receive this message
1739                 node_id: PublicKey,
1740                 /// The message which should be sent.
1741                 msg: msgs::TxRemoveInput,
1742         },
1743         /// Used to indicate that a tx_remove_output message should be sent to the peer with the given node_id.
1744         SendTxRemoveOutput {
1745                 /// The node_id of the node which should receive this message
1746                 node_id: PublicKey,
1747                 /// The message which should be sent.
1748                 msg: msgs::TxRemoveOutput,
1749         },
1750         /// Used to indicate that a tx_complete message should be sent to the peer with the given node_id.
1751         SendTxComplete {
1752                 /// The node_id of the node which should receive this message
1753                 node_id: PublicKey,
1754                 /// The message which should be sent.
1755                 msg: msgs::TxComplete,
1756         },
1757         /// Used to indicate that a tx_signatures message should be sent to the peer with the given node_id.
1758         SendTxSignatures {
1759                 /// The node_id of the node which should receive this message
1760                 node_id: PublicKey,
1761                 /// The message which should be sent.
1762                 msg: msgs::TxSignatures,
1763         },
1764         /// Used to indicate that a tx_init_rbf message should be sent to the peer with the given node_id.
1765         SendTxInitRbf {
1766                 /// The node_id of the node which should receive this message
1767                 node_id: PublicKey,
1768                 /// The message which should be sent.
1769                 msg: msgs::TxInitRbf,
1770         },
1771         /// Used to indicate that a tx_ack_rbf message should be sent to the peer with the given node_id.
1772         SendTxAckRbf {
1773                 /// The node_id of the node which should receive this message
1774                 node_id: PublicKey,
1775                 /// The message which should be sent.
1776                 msg: msgs::TxAckRbf,
1777         },
1778         /// Used to indicate that a tx_abort message should be sent to the peer with the given node_id.
1779         SendTxAbort {
1780                 /// The node_id of the node which should receive this message
1781                 node_id: PublicKey,
1782                 /// The message which should be sent.
1783                 msg: msgs::TxAbort,
1784         },
1785         /// Used to indicate that a channel_ready message should be sent to the peer with the given node_id.
1786         SendChannelReady {
1787                 /// The node_id of the node which should receive these message(s)
1788                 node_id: PublicKey,
1789                 /// The channel_ready message which should be sent.
1790                 msg: msgs::ChannelReady,
1791         },
1792         /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
1793         SendAnnouncementSignatures {
1794                 /// The node_id of the node which should receive these message(s)
1795                 node_id: PublicKey,
1796                 /// The announcement_signatures message which should be sent.
1797                 msg: msgs::AnnouncementSignatures,
1798         },
1799         /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
1800         /// message should be sent to the peer with the given node_id.
1801         UpdateHTLCs {
1802                 /// The node_id of the node which should receive these message(s)
1803                 node_id: PublicKey,
1804                 /// The update messages which should be sent. ALL messages in the struct should be sent!
1805                 updates: msgs::CommitmentUpdate,
1806         },
1807         /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
1808         SendRevokeAndACK {
1809                 /// The node_id of the node which should receive this message
1810                 node_id: PublicKey,
1811                 /// The message which should be sent.
1812                 msg: msgs::RevokeAndACK,
1813         },
1814         /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
1815         SendClosingSigned {
1816                 /// The node_id of the node which should receive this message
1817                 node_id: PublicKey,
1818                 /// The message which should be sent.
1819                 msg: msgs::ClosingSigned,
1820         },
1821         /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
1822         SendShutdown {
1823                 /// The node_id of the node which should receive this message
1824                 node_id: PublicKey,
1825                 /// The message which should be sent.
1826                 msg: msgs::Shutdown,
1827         },
1828         /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
1829         SendChannelReestablish {
1830                 /// The node_id of the node which should receive this message
1831                 node_id: PublicKey,
1832                 /// The message which should be sent.
1833                 msg: msgs::ChannelReestablish,
1834         },
1835         /// Used to send a channel_announcement and channel_update to a specific peer, likely on
1836         /// initial connection to ensure our peers know about our channels.
1837         SendChannelAnnouncement {
1838                 /// The node_id of the node which should receive this message
1839                 node_id: PublicKey,
1840                 /// The channel_announcement which should be sent.
1841                 msg: msgs::ChannelAnnouncement,
1842                 /// The followup channel_update which should be sent.
1843                 update_msg: msgs::ChannelUpdate,
1844         },
1845         /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
1846         /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
1847         ///
1848         /// Note that after doing so, you very likely (unless you did so very recently) want to
1849         /// broadcast a node_announcement (e.g. via [`PeerManager::broadcast_node_announcement`]). This
1850         /// ensures that any nodes which see our channel_announcement also have a relevant
1851         /// node_announcement, including relevant feature flags which may be important for routing
1852         /// through or to us.
1853         ///
1854         /// [`PeerManager::broadcast_node_announcement`]: crate::ln::peer_handler::PeerManager::broadcast_node_announcement
1855         BroadcastChannelAnnouncement {
1856                 /// The channel_announcement which should be sent.
1857                 msg: msgs::ChannelAnnouncement,
1858                 /// The followup channel_update which should be sent.
1859                 update_msg: Option<msgs::ChannelUpdate>,
1860         },
1861         /// Used to indicate that a channel_update should be broadcast to all peers.
1862         BroadcastChannelUpdate {
1863                 /// The channel_update which should be sent.
1864                 msg: msgs::ChannelUpdate,
1865         },
1866         /// Used to indicate that a node_announcement should be broadcast to all peers.
1867         BroadcastNodeAnnouncement {
1868                 /// The node_announcement which should be sent.
1869                 msg: msgs::NodeAnnouncement,
1870         },
1871         /// Used to indicate that a channel_update should be sent to a single peer.
1872         /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
1873         /// private channel and we shouldn't be informing all of our peers of channel parameters.
1874         SendChannelUpdate {
1875                 /// The node_id of the node which should receive this message
1876                 node_id: PublicKey,
1877                 /// The channel_update which should be sent.
1878                 msg: msgs::ChannelUpdate,
1879         },
1880         /// Broadcast an error downstream to be handled
1881         HandleError {
1882                 /// The node_id of the node which should receive this message
1883                 node_id: PublicKey,
1884                 /// The action which should be taken.
1885                 action: msgs::ErrorAction
1886         },
1887         /// Query a peer for channels with funding transaction UTXOs in a block range.
1888         SendChannelRangeQuery {
1889                 /// The node_id of this message recipient
1890                 node_id: PublicKey,
1891                 /// The query_channel_range which should be sent.
1892                 msg: msgs::QueryChannelRange,
1893         },
1894         /// Request routing gossip messages from a peer for a list of channels identified by
1895         /// their short_channel_ids.
1896         SendShortIdsQuery {
1897                 /// The node_id of this message recipient
1898                 node_id: PublicKey,
1899                 /// The query_short_channel_ids which should be sent.
1900                 msg: msgs::QueryShortChannelIds,
1901         },
1902         /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
1903         /// emitted during processing of the query.
1904         SendReplyChannelRange {
1905                 /// The node_id of this message recipient
1906                 node_id: PublicKey,
1907                 /// The reply_channel_range which should be sent.
1908                 msg: msgs::ReplyChannelRange,
1909         },
1910         /// Sends a timestamp filter for inbound gossip. This should be sent on each new connection to
1911         /// enable receiving gossip messages from the peer.
1912         SendGossipTimestampFilter {
1913                 /// The node_id of this message recipient
1914                 node_id: PublicKey,
1915                 /// The gossip_timestamp_filter which should be sent.
1916                 msg: msgs::GossipTimestampFilter,
1917         },
1918 }
1919
1920 /// A trait indicating an object may generate message send events
1921 pub trait MessageSendEventsProvider {
1922         /// Gets the list of pending events which were generated by previous actions, clearing the list
1923         /// in the process.
1924         fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent>;
1925 }
1926
1927 /// A trait indicating an object may generate events.
1928 ///
1929 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
1930 ///
1931 /// Implementations of this trait may also feature an async version of event handling, as shown with
1932 /// [`ChannelManager::process_pending_events_async`] and
1933 /// [`ChainMonitor::process_pending_events_async`].
1934 ///
1935 /// # Requirements
1936 ///
1937 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
1938 /// event since the last invocation.
1939 ///
1940 /// In order to ensure no [`Event`]s are lost, implementors of this trait will persist [`Event`]s
1941 /// and replay any unhandled events on startup. An [`Event`] is considered handled when
1942 /// [`process_pending_events`] returns, thus handlers MUST fully handle [`Event`]s and persist any
1943 /// relevant changes to disk *before* returning.
1944 ///
1945 /// Further, because an application may crash between an [`Event`] being handled and the
1946 /// implementor of this trait being re-serialized, [`Event`] handling must be idempotent - in
1947 /// effect, [`Event`]s may be replayed.
1948 ///
1949 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
1950 /// consult the provider's documentation on the implication of processing events and how a handler
1951 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
1952 /// [`ChainMonitor::process_pending_events`]).
1953 ///
1954 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
1955 /// own type(s).
1956 ///
1957 /// [`process_pending_events`]: Self::process_pending_events
1958 /// [`handle_event`]: EventHandler::handle_event
1959 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
1960 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
1961 /// [`ChannelManager::process_pending_events_async`]: crate::ln::channelmanager::ChannelManager::process_pending_events_async
1962 /// [`ChainMonitor::process_pending_events_async`]: crate::chain::chainmonitor::ChainMonitor::process_pending_events_async
1963 pub trait EventsProvider {
1964         /// Processes any events generated since the last call using the given event handler.
1965         ///
1966         /// See the trait-level documentation for requirements.
1967         fn process_pending_events<H: Deref>(&self, handler: H) where H::Target: EventHandler;
1968 }
1969
1970 /// A trait implemented for objects handling events from [`EventsProvider`].
1971 ///
1972 /// An async variation also exists for implementations of [`EventsProvider`] that support async
1973 /// event handling. The async event handler should satisfy the generic bounds: `F:
1974 /// core::future::Future, H: Fn(Event) -> F`.
1975 pub trait EventHandler {
1976         /// Handles the given [`Event`].
1977         ///
1978         /// See [`EventsProvider`] for details that must be considered when implementing this method.
1979         fn handle_event(&self, event: Event);
1980 }
1981
1982 impl<F> EventHandler for F where F: Fn(Event) {
1983         fn handle_event(&self, event: Event) {
1984                 self(event)
1985         }
1986 }
1987
1988 impl<T: EventHandler> EventHandler for Arc<T> {
1989         fn handle_event(&self, event: Event) {
1990                 self.deref().handle_event(event)
1991         }
1992 }