1 // This file is Copyright its original authors, visible in version control
4 // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5 // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7 // You may not use this file except in accordance with one or both of these
10 //! Events are returned from various bits in the library which indicate some action must be taken
13 //! Because we don't have a built-in runtime, it's up to the client to call events at a time in the
14 //! future, as well as generate and broadcast funding transactions handle payment preimages and a
17 use chain::keysinterface::SpendableOutputDescriptor;
18 use ln::channelmanager::PaymentId;
19 use ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
20 use ln::features::ChannelTypeFeatures;
22 use ln::msgs::DecodeError;
23 use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
24 use routing::gossip::NetworkUpdate;
25 use util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable, VecReadWrapper, VecWriteWrapper};
26 use routing::router::{RouteHop, RouteParameters};
28 use bitcoin::{PackedLockTime, Transaction};
29 use bitcoin::blockdata::script::Script;
30 use bitcoin::hashes::Hash;
31 use bitcoin::hashes::sha256::Hash as Sha256;
32 use bitcoin::secp256k1::PublicKey;
35 use core::time::Duration;
39 /// Some information provided on receipt of payment depends on whether the payment received is a
40 /// spontaneous payment or a "conventional" lightning payment that's paying an invoice.
41 #[derive(Clone, Debug)]
42 pub enum PaymentPurpose {
43 /// Information for receiving a payment that we generated an invoice for.
45 /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via
46 /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
47 /// [`ChannelManager::claim_funds`].
49 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
50 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
51 payment_preimage: Option<PaymentPreimage>,
52 /// The "payment secret". This authenticates the sender to the recipient, preventing a
53 /// number of deanonymization attacks during the routing process.
54 /// It is provided here for your reference, however its accuracy is enforced directly by
55 /// [`ChannelManager`] using the values you previously provided to
56 /// [`ChannelManager::create_inbound_payment`] or
57 /// [`ChannelManager::create_inbound_payment_for_hash`].
59 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
60 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
61 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
62 payment_secret: PaymentSecret,
64 /// Because this is a spontaneous payment, the payer generated their own preimage rather than us
65 /// (the payee) providing a preimage.
66 SpontaneousPayment(PaymentPreimage),
69 impl_writeable_tlv_based_enum!(PaymentPurpose,
70 (0, InvoicePayment) => {
71 (0, payment_preimage, option),
72 (2, payment_secret, required),
74 (2, SpontaneousPayment)
77 #[derive(Clone, Debug, PartialEq)]
78 /// The reason the channel was closed. See individual variants more details.
79 pub enum ClosureReason {
80 /// Closure generated from receiving a peer error message.
82 /// Our counterparty may have broadcasted their latest commitment state, and we have
84 CounterpartyForceClosed {
85 /// The error which the peer sent us.
87 /// The string should be sanitized before it is used (e.g emitted to logs
88 /// or printed to stdout). Otherwise, a well crafted error message may exploit
89 /// a security vulnerability in the terminal emulator or the logging subsystem.
92 /// Closure generated from [`ChannelManager::force_close_channel`], called by the user.
94 /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
96 /// The channel was closed after negotiating a cooperative close and we've now broadcasted
97 /// the cooperative close transaction. Note the shutdown may have been initiated by us.
98 //TODO: split between CounterpartyInitiated/LocallyInitiated
100 /// A commitment transaction was confirmed on chain, closing the channel. Most likely this
101 /// commitment transaction came from our counterparty, but it may also have come from
102 /// a copy of our own `ChannelMonitor`.
103 CommitmentTxConfirmed,
104 /// The funding transaction failed to confirm in a timely manner on an inbound channel.
106 /// Closure generated from processing an event, likely a HTLC forward/relay/reception.
108 /// A developer-readable error message which we generated.
111 /// The peer disconnected prior to funding completing. In this case the spec mandates that we
112 /// forget the channel entirely - we can attempt again if the peer reconnects.
114 /// This includes cases where we restarted prior to funding completion, including prior to the
115 /// initial [`ChannelMonitor`] persistence completing.
117 /// In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the
118 /// peer because of mutual incompatibility between us and our channel counterparty.
120 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
122 /// Closure generated from `ChannelManager::read` if the [`ChannelMonitor`] is newer than
123 /// the [`ChannelManager`] deserialized.
125 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
126 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
127 OutdatedChannelManager
130 impl core::fmt::Display for ClosureReason {
131 fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
132 f.write_str("Channel closed because ")?;
134 ClosureReason::CounterpartyForceClosed { peer_msg } => {
135 f.write_str("counterparty force-closed with message ")?;
136 f.write_str(&peer_msg)
138 ClosureReason::HolderForceClosed => f.write_str("user manually force-closed the channel"),
139 ClosureReason::CooperativeClosure => f.write_str("the channel was cooperatively closed"),
140 ClosureReason::CommitmentTxConfirmed => f.write_str("commitment or closing transaction was confirmed on chain."),
141 ClosureReason::FundingTimedOut => write!(f, "funding transaction failed to confirm within {} blocks", FUNDING_CONF_DEADLINE_BLOCKS),
142 ClosureReason::ProcessingError { err } => {
143 f.write_str("of an exception: ")?;
146 ClosureReason::DisconnectedPeer => f.write_str("the peer disconnected prior to the channel being funded"),
147 ClosureReason::OutdatedChannelManager => f.write_str("the ChannelManager read from disk was stale compared to ChannelMonitor(s)"),
152 impl_writeable_tlv_based_enum_upgradable!(ClosureReason,
153 (0, CounterpartyForceClosed) => { (1, peer_msg, required) },
154 (1, FundingTimedOut) => {},
155 (2, HolderForceClosed) => {},
156 (6, CommitmentTxConfirmed) => {},
157 (4, CooperativeClosure) => {},
158 (8, ProcessingError) => { (1, err, required) },
159 (10, DisconnectedPeer) => {},
160 (12, OutdatedChannelManager) => {},
163 /// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
164 #[derive(Clone, Debug, PartialEq)]
165 pub enum HTLCDestination {
166 /// We tried forwarding to a channel but failed to do so. An example of such an instance is when
167 /// there is insufficient capacity in our outbound channel.
169 /// The `node_id` of the next node. For backwards compatibility, this field is
170 /// marked as optional, versions prior to 0.0.110 may not always be able to provide
171 /// counterparty node information.
172 node_id: Option<PublicKey>,
173 /// The outgoing `channel_id` between us and the next node.
174 channel_id: [u8; 32],
176 /// Scenario where we are unsure of the next node to forward the HTLC to.
178 /// Short channel id we are requesting to forward an HTLC to.
179 requested_forward_scid: u64,
181 /// Failure scenario where an HTLC may have been forwarded to be intended for us,
182 /// but is invalid for some reason, so we reject it.
184 /// Some of the reasons may include:
186 /// * Expected MPP amount to claim does not equal HTLC total
187 /// * Claimable amount does not match expected amount
189 /// The payment hash of the payment we attempted to process.
190 payment_hash: PaymentHash
194 impl_writeable_tlv_based_enum_upgradable!(HTLCDestination,
195 (0, NextHopChannel) => {
196 (0, node_id, required),
197 (2, channel_id, required),
199 (2, UnknownNextHop) => {
200 (0, requested_forward_scid, required),
202 (4, FailedPayment) => {
203 (0, payment_hash, required),
207 /// An Event which you should probably take some action in response to.
209 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
210 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
211 /// written as it makes no sense to respond to it after reconnecting to peers).
212 #[derive(Clone, Debug)]
214 /// Used to indicate that the client should generate a funding transaction with the given
215 /// parameters and then call [`ChannelManager::funding_transaction_generated`].
216 /// Generated in [`ChannelManager`] message handling.
217 /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
218 /// counterparty can steal your funds!
220 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
221 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
222 FundingGenerationReady {
223 /// The random channel_id we picked which you'll need to pass into
224 /// [`ChannelManager::funding_transaction_generated`].
226 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
227 temporary_channel_id: [u8; 32],
228 /// The counterparty's node_id, which you'll need to pass back into
229 /// [`ChannelManager::funding_transaction_generated`].
231 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
232 counterparty_node_id: PublicKey,
233 /// The value, in satoshis, that the output should have.
234 channel_value_satoshis: u64,
235 /// The script which should be used in the transaction output.
236 output_script: Script,
237 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for
238 /// an inbound channel.
240 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
241 user_channel_id: u64,
243 /// Indicates we've received (an offer of) money! Just gotta dig out that payment preimage and
244 /// feed it to [`ChannelManager::claim_funds`] to get it....
246 /// Note that if the preimage is not known, you should call
247 /// [`ChannelManager::fail_htlc_backwards`] to free up resources for this HTLC and avoid
248 /// network congestion.
249 /// If you fail to call either [`ChannelManager::claim_funds`] or
250 /// [`ChannelManager::fail_htlc_backwards`] within the HTLC's timeout, the HTLC will be
251 /// automatically failed.
254 /// LDK will not stop an inbound payment from being paid multiple times, so multiple
255 /// `PaymentReceived` events may be generated for the same payment.
257 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
258 /// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards
260 /// The hash for which the preimage should be handed to the ChannelManager. Note that LDK will
261 /// not stop you from registering duplicate payment hashes for inbound payments.
262 payment_hash: PaymentHash,
263 /// The value, in thousandths of a satoshi, that this payment is for.
265 /// Information for claiming this received payment, based on whether the purpose of the
266 /// payment is to pay an invoice or to send a spontaneous payment.
267 purpose: PaymentPurpose,
269 /// Indicates a payment has been claimed and we've received money!
271 /// This most likely occurs when [`ChannelManager::claim_funds`] has been called in response
272 /// to an [`Event::PaymentReceived`]. However, if we previously crashed during a
273 /// [`ChannelManager::claim_funds`] call you may see this event without a corresponding
274 /// [`Event::PaymentReceived`] event.
277 /// LDK will not stop an inbound payment from being paid multiple times, so multiple
278 /// `PaymentReceived` events may be generated for the same payment. If you then call
279 /// [`ChannelManager::claim_funds`] twice for the same [`Event::PaymentReceived`] you may get
280 /// multiple `PaymentClaimed` events.
282 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
284 /// The payment hash of the claimed payment. Note that LDK will not stop you from
285 /// registering duplicate payment hashes for inbound payments.
286 payment_hash: PaymentHash,
287 /// The value, in thousandths of a satoshi, that this payment is for.
289 /// The purpose of this claimed payment, i.e. whether the payment was for an invoice or a
290 /// spontaneous payment.
291 purpose: PaymentPurpose,
293 /// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
294 /// and we got back the payment preimage for it).
296 /// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed`
297 /// event. In this situation, you SHOULD treat this payment as having succeeded.
299 /// The id returned by [`ChannelManager::send_payment`] and used with
300 /// [`ChannelManager::retry_payment`].
302 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
303 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
304 payment_id: Option<PaymentId>,
305 /// The preimage to the hash given to ChannelManager::send_payment.
306 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
307 /// store it somehow!
308 payment_preimage: PaymentPreimage,
309 /// The hash that was given to [`ChannelManager::send_payment`].
311 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
312 payment_hash: PaymentHash,
313 /// The total fee which was spent at intermediate hops in this payment, across all paths.
315 /// Note that, like [`Route::get_total_fees`] this does *not* include any potential
316 /// overpayment to the recipient node.
318 /// If the recipient or an intermediate node misbehaves and gives us free money, this may
319 /// overstate the amount paid, though this is unlikely.
321 /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees
322 fee_paid_msat: Option<u64>,
324 /// Indicates an outbound payment failed. Individual [`Event::PaymentPathFailed`] events
325 /// provide failure information for each MPP part in the payment.
327 /// This event is provided once there are no further pending HTLCs for the payment and the
328 /// payment is no longer retryable, either due to a several-block timeout or because
329 /// [`ChannelManager::abandon_payment`] was previously called for the corresponding payment.
331 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
333 /// The id returned by [`ChannelManager::send_payment`] and used with
334 /// [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`].
336 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
337 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
338 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
339 payment_id: PaymentId,
340 /// The hash that was given to [`ChannelManager::send_payment`].
342 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
343 payment_hash: PaymentHash,
345 /// Indicates that a path for an outbound payment was successful.
347 /// Always generated after [`Event::PaymentSent`] and thus useful for scoring channels. See
348 /// [`Event::PaymentSent`] for obtaining the payment preimage.
349 PaymentPathSuccessful {
350 /// The id returned by [`ChannelManager::send_payment`] and used with
351 /// [`ChannelManager::retry_payment`].
353 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
354 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
355 payment_id: PaymentId,
356 /// The hash that was given to [`ChannelManager::send_payment`].
358 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
359 payment_hash: Option<PaymentHash>,
360 /// The payment path that was successful.
362 /// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
365 /// Indicates an outbound HTLC we sent failed. Probably some intermediary node dropped
366 /// something. You may wish to retry with a different route.
368 /// Note that this does *not* indicate that all paths for an MPP payment have failed, see
369 /// [`Event::PaymentFailed`] and [`all_paths_failed`].
371 /// [`all_paths_failed`]: Self::PaymentPathFailed::all_paths_failed
373 /// The id returned by [`ChannelManager::send_payment`] and used with
374 /// [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`].
376 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
377 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
378 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
379 payment_id: Option<PaymentId>,
380 /// The hash that was given to [`ChannelManager::send_payment`].
382 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
383 payment_hash: PaymentHash,
384 /// Indicates the payment was rejected for some reason by the recipient. This implies that
385 /// the payment has failed, not just the route in question. If this is not set, you may
386 /// retry the payment via a different route.
387 payment_failed_permanently: bool,
388 /// Any failure information conveyed via the Onion return packet by a node along the failed
391 /// Should be applied to the [`NetworkGraph`] so that routing decisions can take into
392 /// account the update.
394 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
395 network_update: Option<NetworkUpdate>,
396 /// For both single-path and multi-path payments, this is set if all paths of the payment have
397 /// failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the
398 /// larger MPP payment were still in flight when this event was generated.
400 /// Note that if you are retrying individual MPP parts, using this value to determine if a
401 /// payment has fully failed is race-y. Because multiple failures can happen prior to events
402 /// being processed, you may retry in response to a first failure, with a second failure
403 /// (with `all_paths_failed` set) still pending. Then, when the second failure is processed
404 /// you will see `all_paths_failed` set even though the retry of the first failure still
405 /// has an associated in-flight HTLC. See (1) for an example of such a failure.
407 /// If you wish to retry individual MPP parts and learn when a payment has failed, you must
408 /// call [`ChannelManager::abandon_payment`] and wait for a [`Event::PaymentFailed`] event.
410 /// (1) <https://github.com/lightningdevkit/rust-lightning/issues/1164>
412 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
413 all_paths_failed: bool,
414 /// The payment path that failed.
416 /// The channel responsible for the failed payment path.
418 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
419 /// may not refer to a channel in the public network graph. These aliases may also collide
420 /// with channels in the public network graph.
422 /// If this is `Some`, then the corresponding channel should be avoided when the payment is
423 /// retried. May be `None` for older [`Event`] serializations.
424 short_channel_id: Option<u64>,
425 /// Parameters needed to compute a new [`Route`] when retrying the failed payment path.
427 /// See [`find_route`] for details.
429 /// [`Route`]: crate::routing::router::Route
430 /// [`find_route`]: crate::routing::router::find_route
431 retry: Option<RouteParameters>,
433 error_code: Option<u16>,
435 error_data: Option<Vec<u8>>,
437 /// Indicates that a probe payment we sent returned successful, i.e., only failed at the destination.
439 /// The id returned by [`ChannelManager::send_probe`].
441 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
442 payment_id: PaymentId,
443 /// The hash generated by [`ChannelManager::send_probe`].
445 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
446 payment_hash: PaymentHash,
447 /// The payment path that was successful.
450 /// Indicates that a probe payment we sent failed at an intermediary node on the path.
452 /// The id returned by [`ChannelManager::send_probe`].
454 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
455 payment_id: PaymentId,
456 /// The hash generated by [`ChannelManager::send_probe`].
458 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
459 payment_hash: PaymentHash,
460 /// The payment path that failed.
462 /// The channel responsible for the failed probe.
464 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
465 /// may not refer to a channel in the public network graph. These aliases may also collide
466 /// with channels in the public network graph.
467 short_channel_id: Option<u64>,
469 /// Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at
470 /// a time in the future.
472 /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
473 PendingHTLCsForwardable {
474 /// The minimum amount of time that should be waited prior to calling
475 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
476 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
477 /// now + 5*time_forwardable).
478 time_forwardable: Duration,
480 /// Used to indicate that an output which you should know how to spend was confirmed on chain
481 /// and is now spendable.
482 /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
483 /// counterparty spending them due to some kind of timeout. Thus, you need to store them
484 /// somewhere and spend them when you create on-chain transactions.
486 /// The outputs which you should store as spendable by you.
487 outputs: Vec<SpendableOutputDescriptor>,
489 /// This event is generated when a payment has been successfully forwarded through us and a
490 /// forwarding fee earned.
492 /// The incoming channel between the previous node and us. This is only `None` for events
493 /// generated or serialized by versions prior to 0.0.107.
494 prev_channel_id: Option<[u8; 32]>,
495 /// The outgoing channel between the next node and us. This is only `None` for events
496 /// generated or serialized by versions prior to 0.0.107.
497 next_channel_id: Option<[u8; 32]>,
498 /// The fee, in milli-satoshis, which was earned as a result of the payment.
500 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
501 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
502 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
503 /// claimed the full value in millisatoshis from the source. In this case,
504 /// `claim_from_onchain_tx` will be set.
506 /// If the channel which sent us the payment has been force-closed, we will claim the funds
507 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
508 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
509 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
511 fee_earned_msat: Option<u64>,
512 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
514 claim_from_onchain_tx: bool,
516 /// Used to indicate that a previously opened channel with the given `channel_id` is in the
517 /// process of closure.
519 /// The channel_id of the channel which has been closed. Note that on-chain transactions
520 /// resolving the channel are likely still awaiting confirmation.
521 channel_id: [u8; 32],
522 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
523 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
524 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
525 /// `user_channel_id` will be 0 for an inbound channel.
526 /// This will always be zero for objects serialized with LDK versions prior to 0.0.102.
528 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
529 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
530 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
531 user_channel_id: u64,
532 /// The reason the channel was closed.
533 reason: ClosureReason
535 /// Used to indicate to the user that they can abandon the funding transaction and recycle the
536 /// inputs for another purpose.
538 /// The channel_id of the channel which has been closed.
539 channel_id: [u8; 32],
540 /// The full transaction received from the user
541 transaction: Transaction
543 /// Indicates a request to open a new channel by a peer.
545 /// To accept the request, call [`ChannelManager::accept_inbound_channel`]. To reject the
546 /// request, call [`ChannelManager::force_close_without_broadcasting_txn`].
548 /// The event is only triggered when a new open channel request is received and the
549 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
551 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
552 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
553 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
555 /// The temporary channel ID of the channel requested to be opened.
557 /// When responding to the request, the `temporary_channel_id` should be passed
558 /// back to the ChannelManager through [`ChannelManager::accept_inbound_channel`] to accept,
559 /// or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject.
561 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
562 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
563 temporary_channel_id: [u8; 32],
564 /// The node_id of the counterparty requesting to open the channel.
566 /// When responding to the request, the `counterparty_node_id` should be passed
567 /// back to the `ChannelManager` through [`ChannelManager::accept_inbound_channel`] to
568 /// accept the request, or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject the
571 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
572 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
573 counterparty_node_id: PublicKey,
574 /// The channel value of the requested channel.
575 funding_satoshis: u64,
576 /// Our starting balance in the channel if the request is accepted, in milli-satoshi.
578 /// The features that this channel will operate with. If you reject the channel, a
579 /// well-behaved counterparty may automatically re-attempt the channel with a new set of
582 /// Note that if [`ChannelTypeFeatures::supports_scid_privacy`] returns true on this type,
583 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
586 /// Furthermore, note that if [`ChannelTypeFeatures::supports_zero_conf`] returns true on this type,
587 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
588 /// 0.0.107. Channels setting this type also need to get manually accepted via
589 /// [`crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`],
590 /// or will be rejected otherwise.
592 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
593 channel_type: ChannelTypeFeatures,
595 /// Indicates that the HTLC was accepted, but could not be processed when or after attempting to
598 /// Some scenarios where this event may be sent include:
599 /// * Insufficient capacity in the outbound channel
600 /// * While waiting to forward the HTLC, the channel it is meant to be forwarded through closes
601 /// * When an unknown SCID is requested for forwarding a payment.
602 /// * Claiming an amount for an MPP payment that exceeds the HTLC total
603 /// * The HTLC has timed out
605 /// This event, however, does not get generated if an HTLC fails to meet the forwarding
606 /// requirements (i.e. insufficient fees paid, or a CLTV that is too soon).
608 /// The channel over which the HTLC was received.
609 prev_channel_id: [u8; 32],
610 /// Destination of the HTLC that failed to be processed.
611 failed_next_destination: HTLCDestination,
615 impl Writeable for Event {
616 fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
618 &Event::FundingGenerationReady { .. } => {
620 // We never write out FundingGenerationReady events as, upon disconnection, peers
621 // drop any channels which have not yet exchanged funding_signed.
623 &Event::PaymentReceived { ref payment_hash, ref amount_msat, ref purpose } => {
625 let mut payment_secret = None;
626 let payment_preimage;
628 PaymentPurpose::InvoicePayment { payment_preimage: preimage, payment_secret: secret } => {
629 payment_secret = Some(secret);
630 payment_preimage = *preimage;
632 PaymentPurpose::SpontaneousPayment(preimage) => {
633 payment_preimage = Some(*preimage);
636 write_tlv_fields!(writer, {
637 (0, payment_hash, required),
638 (2, payment_secret, option),
639 (4, amount_msat, required),
640 (6, 0u64, required), // user_payment_id required for compatibility with 0.0.103 and earlier
641 (8, payment_preimage, option),
644 &Event::PaymentSent { ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat } => {
646 write_tlv_fields!(writer, {
647 (0, payment_preimage, required),
648 (1, payment_hash, required),
649 (3, payment_id, option),
650 (5, fee_paid_msat, option),
653 &Event::PaymentPathFailed {
654 ref payment_id, ref payment_hash, ref payment_failed_permanently, ref network_update,
655 ref all_paths_failed, ref path, ref short_channel_id, ref retry,
663 error_code.write(writer)?;
665 error_data.write(writer)?;
666 write_tlv_fields!(writer, {
667 (0, payment_hash, required),
668 (1, network_update, option),
669 (2, payment_failed_permanently, required),
670 (3, all_paths_failed, required),
672 (7, short_channel_id, option),
674 (11, payment_id, option),
677 &Event::PendingHTLCsForwardable { time_forwardable: _ } => {
679 // Note that we now ignore these on the read end as we'll re-generate them in
680 // ChannelManager, we write them here only for backwards compatibility.
682 &Event::SpendableOutputs { ref outputs } => {
684 write_tlv_fields!(writer, {
685 (0, VecWriteWrapper(outputs), required),
688 &Event::PaymentForwarded { fee_earned_msat, prev_channel_id, claim_from_onchain_tx, next_channel_id } => {
690 write_tlv_fields!(writer, {
691 (0, fee_earned_msat, option),
692 (1, prev_channel_id, option),
693 (2, claim_from_onchain_tx, required),
694 (3, next_channel_id, option),
697 &Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason } => {
699 write_tlv_fields!(writer, {
700 (0, channel_id, required),
701 (1, user_channel_id, required),
702 (2, reason, required)
705 &Event::DiscardFunding { ref channel_id, ref transaction } => {
707 write_tlv_fields!(writer, {
708 (0, channel_id, required),
709 (2, transaction, required)
712 &Event::PaymentPathSuccessful { ref payment_id, ref payment_hash, ref path } => {
714 write_tlv_fields!(writer, {
715 (0, payment_id, required),
716 (2, payment_hash, option),
720 &Event::PaymentFailed { ref payment_id, ref payment_hash } => {
722 write_tlv_fields!(writer, {
723 (0, payment_id, required),
724 (2, payment_hash, required),
727 &Event::OpenChannelRequest { .. } => {
729 // We never write the OpenChannelRequest events as, upon disconnection, peers
730 // drop any channels which have not yet exchanged funding_signed.
732 &Event::PaymentClaimed { ref payment_hash, ref amount_msat, ref purpose } => {
734 write_tlv_fields!(writer, {
735 (0, payment_hash, required),
736 (2, purpose, required),
737 (4, amount_msat, required),
740 &Event::ProbeSuccessful { ref payment_id, ref payment_hash, ref path } => {
742 write_tlv_fields!(writer, {
743 (0, payment_id, required),
744 (2, payment_hash, required),
748 &Event::ProbeFailed { ref payment_id, ref payment_hash, ref path, ref short_channel_id } => {
750 write_tlv_fields!(writer, {
751 (0, payment_id, required),
752 (2, payment_hash, required),
754 (6, short_channel_id, option),
757 &Event::HTLCHandlingFailed { ref prev_channel_id, ref failed_next_destination } => {
759 write_tlv_fields!(writer, {
760 (0, prev_channel_id, required),
761 (2, failed_next_destination, required),
764 // Note that, going forward, all new events must only write data inside of
765 // `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
766 // data via `write_tlv_fields`.
771 impl MaybeReadable for Event {
772 fn read<R: io::Read>(reader: &mut R) -> Result<Option<Self>, msgs::DecodeError> {
773 match Readable::read(reader)? {
774 // Note that we do not write a length-prefixed TLV for FundingGenerationReady events,
775 // unlike all other events, thus we return immediately here.
779 let mut payment_hash = PaymentHash([0; 32]);
780 let mut payment_preimage = None;
781 let mut payment_secret = None;
782 let mut amount_msat = 0;
783 let mut _user_payment_id = None::<u64>; // For compatibility with 0.0.103 and earlier
784 read_tlv_fields!(reader, {
785 (0, payment_hash, required),
786 (2, payment_secret, option),
787 (4, amount_msat, required),
788 (6, _user_payment_id, option),
789 (8, payment_preimage, option),
791 let purpose = match payment_secret {
792 Some(secret) => PaymentPurpose::InvoicePayment {
794 payment_secret: secret
796 None if payment_preimage.is_some() => PaymentPurpose::SpontaneousPayment(payment_preimage.unwrap()),
797 None => return Err(msgs::DecodeError::InvalidValue),
799 Ok(Some(Event::PaymentReceived {
809 let mut payment_preimage = PaymentPreimage([0; 32]);
810 let mut payment_hash = None;
811 let mut payment_id = None;
812 let mut fee_paid_msat = None;
813 read_tlv_fields!(reader, {
814 (0, payment_preimage, required),
815 (1, payment_hash, option),
816 (3, payment_id, option),
817 (5, fee_paid_msat, option),
819 if payment_hash.is_none() {
820 payment_hash = Some(PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner()));
822 Ok(Some(Event::PaymentSent {
825 payment_hash: payment_hash.unwrap(),
834 let error_code = Readable::read(reader)?;
836 let error_data = Readable::read(reader)?;
837 let mut payment_hash = PaymentHash([0; 32]);
838 let mut payment_failed_permanently = false;
839 let mut network_update = None;
840 let mut all_paths_failed = Some(true);
841 let mut path: Option<Vec<RouteHop>> = Some(vec![]);
842 let mut short_channel_id = None;
843 let mut retry = None;
844 let mut payment_id = None;
845 read_tlv_fields!(reader, {
846 (0, payment_hash, required),
847 (1, network_update, ignorable),
848 (2, payment_failed_permanently, required),
849 (3, all_paths_failed, option),
851 (7, short_channel_id, option),
853 (11, payment_id, option),
855 Ok(Some(Event::PaymentPathFailed {
858 payment_failed_permanently,
860 all_paths_failed: all_paths_failed.unwrap(),
875 let mut outputs = VecReadWrapper(Vec::new());
876 read_tlv_fields!(reader, {
877 (0, outputs, required),
879 Ok(Some(Event::SpendableOutputs { outputs: outputs.0 }))
885 let mut fee_earned_msat = None;
886 let mut prev_channel_id = None;
887 let mut claim_from_onchain_tx = false;
888 let mut next_channel_id = None;
889 read_tlv_fields!(reader, {
890 (0, fee_earned_msat, option),
891 (1, prev_channel_id, option),
892 (2, claim_from_onchain_tx, required),
893 (3, next_channel_id, option),
895 Ok(Some(Event::PaymentForwarded { fee_earned_msat, prev_channel_id, claim_from_onchain_tx, next_channel_id }))
901 let mut channel_id = [0; 32];
902 let mut reason = None;
903 let mut user_channel_id_opt = None;
904 read_tlv_fields!(reader, {
905 (0, channel_id, required),
906 (1, user_channel_id_opt, option),
907 (2, reason, ignorable),
909 if reason.is_none() { return Ok(None); }
910 let user_channel_id = if let Some(id) = user_channel_id_opt { id } else { 0 };
911 Ok(Some(Event::ChannelClosed { channel_id, user_channel_id, reason: reason.unwrap() }))
917 let mut channel_id = [0; 32];
918 let mut transaction = Transaction{ version: 2, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() };
919 read_tlv_fields!(reader, {
920 (0, channel_id, required),
921 (2, transaction, required),
923 Ok(Some(Event::DiscardFunding { channel_id, transaction } ))
929 let mut payment_id = PaymentId([0; 32]);
930 let mut payment_hash = None;
931 let mut path: Option<Vec<RouteHop>> = Some(vec![]);
932 read_tlv_fields!(reader, {
933 (0, payment_id, required),
934 (2, payment_hash, option),
937 Ok(Some(Event::PaymentPathSuccessful {
947 let mut payment_hash = PaymentHash([0; 32]);
948 let mut payment_id = PaymentId([0; 32]);
949 read_tlv_fields!(reader, {
950 (0, payment_id, required),
951 (2, payment_hash, required),
953 Ok(Some(Event::PaymentFailed {
961 // Value 17 is used for `Event::OpenChannelRequest`.
966 let mut payment_hash = PaymentHash([0; 32]);
967 let mut purpose = None;
968 let mut amount_msat = 0;
969 read_tlv_fields!(reader, {
970 (0, payment_hash, required),
971 (2, purpose, ignorable),
972 (4, amount_msat, required),
974 if purpose.is_none() { return Ok(None); }
975 Ok(Some(Event::PaymentClaimed {
977 purpose: purpose.unwrap(),
985 let mut payment_id = PaymentId([0; 32]);
986 let mut payment_hash = PaymentHash([0; 32]);
987 let mut path: Option<Vec<RouteHop>> = Some(vec![]);
988 read_tlv_fields!(reader, {
989 (0, payment_id, required),
990 (2, payment_hash, required),
993 Ok(Some(Event::ProbeSuccessful {
1003 let mut payment_id = PaymentId([0; 32]);
1004 let mut payment_hash = PaymentHash([0; 32]);
1005 let mut path: Option<Vec<RouteHop>> = Some(vec![]);
1006 let mut short_channel_id = None;
1007 read_tlv_fields!(reader, {
1008 (0, payment_id, required),
1009 (2, payment_hash, required),
1010 (4, path, vec_type),
1011 (6, short_channel_id, option),
1013 Ok(Some(Event::ProbeFailed {
1016 path: path.unwrap(),
1024 let mut prev_channel_id = [0; 32];
1025 let mut failed_next_destination_opt = None;
1026 read_tlv_fields!(reader, {
1027 (0, prev_channel_id, required),
1028 (2, failed_next_destination_opt, ignorable),
1030 if let Some(failed_next_destination) = failed_next_destination_opt {
1031 Ok(Some(Event::HTLCHandlingFailed {
1033 failed_next_destination,
1036 // If we fail to read a `failed_next_destination` assume it's because
1037 // `MaybeReadable::read` returned `Ok(None)`, though it's also possible we
1038 // were simply missing the field.
1044 // Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
1045 // Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
1047 x if x % 2 == 1 => {
1048 // If the event is of unknown type, assume it was written with `write_tlv_fields`,
1049 // which prefixes the whole thing with a length BigSize. Because the event is
1050 // odd-type unknown, we should treat it as `Ok(None)` even if it has some TLV
1051 // fields that are even. Thus, we avoid using `read_tlv_fields` and simply read
1052 // exactly the number of bytes specified, ignoring them entirely.
1053 let tlv_len: BigSize = Readable::read(reader)?;
1054 FixedLengthReader::new(reader, tlv_len.0)
1055 .eat_remaining().map_err(|_| msgs::DecodeError::ShortRead)?;
1058 _ => Err(msgs::DecodeError::InvalidValue)
1063 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
1064 /// broadcast to most peers).
1065 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
1066 #[derive(Clone, Debug)]
1067 pub enum MessageSendEvent {
1068 /// Used to indicate that we've accepted a channel open and should send the accept_channel
1069 /// message provided to the given peer.
1071 /// The node_id of the node which should receive this message
1073 /// The message which should be sent.
1074 msg: msgs::AcceptChannel,
1076 /// Used to indicate that we've initiated a channel open and should send the open_channel
1077 /// message provided to the given peer.
1079 /// The node_id of the node which should receive this message
1081 /// The message which should be sent.
1082 msg: msgs::OpenChannel,
1084 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
1085 SendFundingCreated {
1086 /// The node_id of the node which should receive this message
1088 /// The message which should be sent.
1089 msg: msgs::FundingCreated,
1091 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
1093 /// The node_id of the node which should receive this message
1095 /// The message which should be sent.
1096 msg: msgs::FundingSigned,
1098 /// Used to indicate that a channel_ready message should be sent to the peer with the given node_id.
1100 /// The node_id of the node which should receive these message(s)
1102 /// The channel_ready message which should be sent.
1103 msg: msgs::ChannelReady,
1105 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
1106 SendAnnouncementSignatures {
1107 /// The node_id of the node which should receive these message(s)
1109 /// The announcement_signatures message which should be sent.
1110 msg: msgs::AnnouncementSignatures,
1112 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
1113 /// message should be sent to the peer with the given node_id.
1115 /// The node_id of the node which should receive these message(s)
1117 /// The update messages which should be sent. ALL messages in the struct should be sent!
1118 updates: msgs::CommitmentUpdate,
1120 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
1122 /// The node_id of the node which should receive this message
1124 /// The message which should be sent.
1125 msg: msgs::RevokeAndACK,
1127 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
1129 /// The node_id of the node which should receive this message
1131 /// The message which should be sent.
1132 msg: msgs::ClosingSigned,
1134 /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
1136 /// The node_id of the node which should receive this message
1138 /// The message which should be sent.
1139 msg: msgs::Shutdown,
1141 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
1142 SendChannelReestablish {
1143 /// The node_id of the node which should receive this message
1145 /// The message which should be sent.
1146 msg: msgs::ChannelReestablish,
1148 /// Used to send a channel_announcement and channel_update to a specific peer, likely on
1149 /// initial connection to ensure our peers know about our channels.
1150 SendChannelAnnouncement {
1151 /// The node_id of the node which should receive this message
1153 /// The channel_announcement which should be sent.
1154 msg: msgs::ChannelAnnouncement,
1155 /// The followup channel_update which should be sent.
1156 update_msg: msgs::ChannelUpdate,
1158 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
1159 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
1161 /// Note that after doing so, you very likely (unless you did so very recently) want to
1162 /// broadcast a node_announcement (e.g. via [`PeerManager::broadcast_node_announcement`]). This
1163 /// ensures that any nodes which see our channel_announcement also have a relevant
1164 /// node_announcement, including relevant feature flags which may be important for routing
1165 /// through or to us.
1167 /// [`PeerManager::broadcast_node_announcement`]: crate::ln::peer_handler::PeerManager::broadcast_node_announcement
1168 BroadcastChannelAnnouncement {
1169 /// The channel_announcement which should be sent.
1170 msg: msgs::ChannelAnnouncement,
1171 /// The followup channel_update which should be sent.
1172 update_msg: msgs::ChannelUpdate,
1174 /// Used to indicate that a channel_update should be broadcast to all peers.
1175 BroadcastChannelUpdate {
1176 /// The channel_update which should be sent.
1177 msg: msgs::ChannelUpdate,
1179 /// Used to indicate that a channel_update should be sent to a single peer.
1180 /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
1181 /// private channel and we shouldn't be informing all of our peers of channel parameters.
1183 /// The node_id of the node which should receive this message
1185 /// The channel_update which should be sent.
1186 msg: msgs::ChannelUpdate,
1188 /// Broadcast an error downstream to be handled
1190 /// The node_id of the node which should receive this message
1192 /// The action which should be taken.
1193 action: msgs::ErrorAction
1195 /// Query a peer for channels with funding transaction UTXOs in a block range.
1196 SendChannelRangeQuery {
1197 /// The node_id of this message recipient
1199 /// The query_channel_range which should be sent.
1200 msg: msgs::QueryChannelRange,
1202 /// Request routing gossip messages from a peer for a list of channels identified by
1203 /// their short_channel_ids.
1205 /// The node_id of this message recipient
1207 /// The query_short_channel_ids which should be sent.
1208 msg: msgs::QueryShortChannelIds,
1210 /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
1211 /// emitted during processing of the query.
1212 SendReplyChannelRange {
1213 /// The node_id of this message recipient
1215 /// The reply_channel_range which should be sent.
1216 msg: msgs::ReplyChannelRange,
1218 /// Sends a timestamp filter for inbound gossip. This should be sent on each new connection to
1219 /// enable receiving gossip messages from the peer.
1220 SendGossipTimestampFilter {
1221 /// The node_id of this message recipient
1223 /// The gossip_timestamp_filter which should be sent.
1224 msg: msgs::GossipTimestampFilter,
1228 /// A trait indicating an object may generate message send events
1229 pub trait MessageSendEventsProvider {
1230 /// Gets the list of pending events which were generated by previous actions, clearing the list
1232 fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent>;
1235 /// A trait indicating an object may generate onion messages to send
1236 pub trait OnionMessageProvider {
1237 /// Gets the next pending onion message for the peer with the given node id.
1238 fn next_onion_message_for_peer(&self, peer_node_id: PublicKey) -> Option<msgs::OnionMessage>;
1241 /// A trait indicating an object may generate events.
1243 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
1247 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
1248 /// event since the last invocation.
1250 /// In order to ensure no [`Event`]s are lost, implementors of this trait will persist [`Event`]s
1251 /// and replay any unhandled events on startup. An [`Event`] is considered handled when
1252 /// [`process_pending_events`] returns, thus handlers MUST fully handle [`Event`]s and persist any
1253 /// relevant changes to disk *before* returning.
1255 /// Further, because an application may crash between an [`Event`] being handled and the
1256 /// implementor of this trait being re-serialized, [`Event`] handling must be idempotent - in
1257 /// effect, [`Event`]s may be replayed.
1259 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
1260 /// consult the provider's documentation on the implication of processing events and how a handler
1261 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
1262 /// [`ChainMonitor::process_pending_events`]).
1264 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
1267 /// [`process_pending_events`]: Self::process_pending_events
1268 /// [`handle_event`]: EventHandler::handle_event
1269 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
1270 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
1271 pub trait EventsProvider {
1272 /// Processes any events generated since the last call using the given event handler.
1274 /// See the trait-level documentation for requirements.
1275 fn process_pending_events<H: Deref>(&self, handler: H) where H::Target: EventHandler;
1278 /// A trait implemented for objects handling events from [`EventsProvider`].
1279 pub trait EventHandler {
1280 /// Handles the given [`Event`].
1282 /// See [`EventsProvider`] for details that must be considered when implementing this method.
1283 fn handle_event(&self, event: &Event);
1286 impl<F> EventHandler for F where F: Fn(&Event) {
1287 fn handle_event(&self, event: &Event) {
1292 impl<T: EventHandler> EventHandler for Arc<T> {
1293 fn handle_event(&self, event: &Event) {
1294 self.deref().handle_event(event)