diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 8a0061f8c6b..b018c6c74cd 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -1,5 +1,3 @@ -#![cfg_attr(rustfmt, rustfmt_skip)] - // This file is Copyright its original authors, visible in version control // history. // @@ -20,55 +18,77 @@ //! imply it needs to fail HTLCs/payments/channels it manages). use bitcoin::block::Header; -use bitcoin::transaction::Transaction; use bitcoin::constants::ChainHash; use bitcoin::key::constants::SECRET_KEY_SIZE; use bitcoin::network::Network; +use bitcoin::transaction::Transaction; -use bitcoin::hashes::{Hash, HashEngine, HmacEngine}; +use bitcoin::hash_types::{BlockHash, Txid}; use bitcoin::hashes::hmac::Hmac; use bitcoin::hashes::sha256::Hash as Sha256; -use bitcoin::hash_types::{BlockHash, Txid}; +use bitcoin::hashes::{Hash, HashEngine, HmacEngine}; -use bitcoin::secp256k1::{SecretKey,PublicKey}; use bitcoin::secp256k1::Secp256k1; +use bitcoin::secp256k1::{PublicKey, SecretKey}; use bitcoin::{secp256k1, Sequence}; #[cfg(splicing)] use bitcoin::{TxIn, Weight}; -use crate::events::{FundingInfo, PaidBolt12Invoice}; +use crate::blinded_path::message::MessageForwardNode; use crate::blinded_path::message::{AsyncPaymentsContext, OffersContext}; +use crate::blinded_path::payment::{ + AsyncBolt12OfferContext, Bolt12OfferContext, PaymentContext, UnauthenticatedReceiveTlvs, +}; use crate::blinded_path::NodeIdLookUp; -use crate::blinded_path::message::MessageForwardNode; -use crate::blinded_path::payment::{AsyncBolt12OfferContext, Bolt12OfferContext, PaymentContext, UnauthenticatedReceiveTlvs}; use crate::chain; -use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock}; -use crate::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator}; -use crate::chain::channelmonitor::{Balance, ChannelMonitor, ChannelMonitorUpdate, WithChannelMonitor, ChannelMonitorUpdateStep, HTLC_FAIL_BACK_BUFFER, MAX_BLOCKS_FOR_CONF, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY, MonitorEvent}; +use crate::chain::chaininterface::{ + BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator, +}; +use crate::chain::channelmonitor::{ + Balance, ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, MonitorEvent, + WithChannelMonitor, ANTI_REORG_DELAY, CLTV_CLAIM_BUFFER, HTLC_FAIL_BACK_BUFFER, + LATENCY_GRACE_PERIOD_BLOCKS, MAX_BLOCKS_FOR_CONF, +}; use crate::chain::transaction::{OutPoint, TransactionData}; -use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFunds, ClosureReason, HTLCHandlingFailureType, PaymentFailureReason, ReplayEvent}; +use crate::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Watch}; +use crate::events::{ + self, ClosureReason, Event, EventHandler, EventsProvider, HTLCHandlingFailureType, + InboundChannelFunds, PaymentFailureReason, ReplayEvent, +}; +use crate::events::{FundingInfo, PaidBolt12Invoice}; // Since this struct is returned in `list_channels` methods, expose it here in case users want to // construct one themselves. -use crate::ln::inbound_payment; -use crate::ln::types::ChannelId; -use crate::offers::flow::OffersMessageFlow; -use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret}; -use crate::ln::channel::{self, Channel, ChannelError, ChannelUpdateStatus, FundedChannel, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, ReconnectionMsg, InboundV1Channel, WithChannelContext}; use crate::ln::channel::PendingV2Channel; +use crate::ln::channel::{ + self, Channel, ChannelError, ChannelUpdateStatus, FundedChannel, InboundV1Channel, + OutboundV1Channel, ReconnectionMsg, ShutdownResult, UpdateFulfillCommitFetch, + WithChannelContext, +}; use crate::ln::channel_state::ChannelDetails; -use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures}; -#[cfg(any(feature = "_test_utils", test))] -use crate::types::features::Bolt11InvoiceFeatures; -use crate::routing::router::{BlindedTail, InFlightHtlcs, Path, Payee, PaymentParameters, RouteParameters, RouteParametersConfig, Router, FixedRouter, Route}; -use crate::ln::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, HopConnector, InboundHTLCErr, NextPacketDetails, invalid_payment_err_data}; +use crate::ln::inbound_payment; use crate::ln::msgs; +use crate::ln::msgs::{ + BaseMessageHandler, ChannelMessageHandler, CommitmentUpdate, DecodeError, LightningError, + MessageSendEvent, +}; +use crate::ln::onion_payment::{ + check_incoming_htlc_cltv, create_fwd_pending_htlc_info, create_recv_pending_htlc_info, + decode_incoming_update_add_htlc_onion, invalid_payment_err_data, HopConnector, InboundHTLCErr, + NextPacketDetails, +}; use crate::ln::onion_utils::{self}; use crate::ln::onion_utils::{HTLCFailReason, LocalHTLCFailureReason}; -use crate::ln::msgs::{BaseMessageHandler, ChannelMessageHandler, CommitmentUpdate, DecodeError, LightningError, MessageSendEvent}; #[cfg(test)] use crate::ln::outbound_payment; -use crate::ln::outbound_payment::{Bolt11PaymentError, OutboundPayments, PendingOutboundPayment, RetryableInvoiceRequest, SendAlongPathArgs, StaleExpiration}; -use crate::offers::invoice::{Bolt12Invoice, DerivedSigningPubkey, InvoiceBuilder, DEFAULT_RELATIVE_EXPIRY}; +use crate::ln::outbound_payment::{ + Bolt11PaymentError, OutboundPayments, PendingOutboundPayment, RetryableInvoiceRequest, + SendAlongPathArgs, StaleExpiration, +}; +use crate::ln::types::ChannelId; +use crate::offers::flow::OffersMessageFlow; +use crate::offers::invoice::{ + Bolt12Invoice, DerivedSigningPubkey, InvoiceBuilder, DEFAULT_RELATIVE_EXPIRY, +}; use crate::offers::invoice_error::InvoiceError; use crate::offers::invoice_request::InvoiceRequest; use crate::offers::nonce::Nonce; @@ -76,70 +96,98 @@ use crate::offers::offer::Offer; use crate::offers::parse::Bolt12SemanticError; use crate::offers::refund::Refund; use crate::offers::signer; -use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailable, ReleaseHeldHtlc, AsyncPaymentsMessageHandler}; +use crate::onion_message::async_payments::{ + AsyncPaymentsMessage, AsyncPaymentsMessageHandler, HeldHtlcAvailable, ReleaseHeldHtlc, +}; use crate::onion_message::dns_resolution::HumanReadableName; -use crate::onion_message::messenger::{MessageRouter, Responder, ResponseInstruction, MessageSendInstructions}; +use crate::onion_message::messenger::{ + MessageRouter, MessageSendInstructions, Responder, ResponseInstruction, +}; use crate::onion_message::offers::{OffersMessage, OffersMessageHandler}; -use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider}; +use crate::routing::router::{ + BlindedTail, FixedRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, + RouteParameters, RouteParametersConfig, Router, +}; use crate::sign::ecdsa::EcdsaChannelSigner; -use crate::util::config::{ChannelConfig, ChannelConfigUpdate, ChannelConfigOverrides, UserConfig}; -use crate::util::wakers::{Future, Notifier}; +use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider}; +#[cfg(any(feature = "_test_utils", test))] +use crate::types::features::Bolt11InvoiceFeatures; +use crate::types::features::{ + Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures, +}; +use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret}; +use crate::util::config::{ChannelConfig, ChannelConfigOverrides, ChannelConfigUpdate, UserConfig}; +use crate::util::errors::APIError; +use crate::util::logger::{Level, Logger, WithContext}; use crate::util::scid_utils::fake_scid; +use crate::util::ser::{ + BigSize, FixedLengthReader, LengthReadable, MaybeReadable, Readable, ReadableArgs, VecWriter, + Writeable, Writer, +}; use crate::util::string::UntrustedString; -use crate::util::ser::{BigSize, FixedLengthReader, LengthReadable, Readable, ReadableArgs, MaybeReadable, Writeable, Writer, VecWriter}; -use crate::util::logger::{Level, Logger, WithContext}; -use crate::util::errors::APIError; +use crate::util::wakers::{Future, Notifier}; -#[cfg(async_payments)] use { +#[cfg(all(test, async_payments))] +use crate::blinded_path::payment::BlindedPaymentPath; +#[cfg(async_payments)] +use { crate::blinded_path::message::BlindedMessagePath, crate::offers::offer::Amount, - crate::offers::static_invoice::{DEFAULT_RELATIVE_EXPIRY as STATIC_INVOICE_DEFAULT_RELATIVE_EXPIRY, StaticInvoice, StaticInvoiceBuilder}, + crate::offers::static_invoice::{ + StaticInvoice, StaticInvoiceBuilder, + DEFAULT_RELATIVE_EXPIRY as STATIC_INVOICE_DEFAULT_RELATIVE_EXPIRY, + }, }; -#[cfg(all(test, async_payments))] -use crate::blinded_path::payment::BlindedPaymentPath; #[cfg(feature = "dnssec")] use { - crate::onion_message::dns_resolution::{DNSResolverMessage, DNSResolverMessageHandler, DNSSECQuery, DNSSECProof}, - crate::onion_message::messenger::Destination, crate::blinded_path::message::DNSResolverContext, + crate::onion_message::dns_resolution::{ + DNSResolverMessage, DNSResolverMessageHandler, DNSSECProof, DNSSECQuery, + }, + crate::onion_message::messenger::Destination, }; +#[cfg(c_bindings)] +use { + crate::offers::offer::OfferWithDerivedMetadataBuilder, + crate::offers::refund::RefundMaybeWithDerivedMetadataBuilder, +}; #[cfg(not(c_bindings))] use { crate::offers::offer::{DerivedMetadata, OfferBuilder}, crate::offers::refund::RefundBuilder, crate::onion_message::messenger::DefaultMessageRouter, - crate::routing::router::DefaultRouter, crate::routing::gossip::NetworkGraph, + crate::routing::router::DefaultRouter, crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters}, crate::sign::KeysManager, }; -#[cfg(c_bindings)] -use { - crate::offers::offer::OfferWithDerivedMetadataBuilder, - crate::offers::refund::RefundMaybeWithDerivedMetadataBuilder, -}; -use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, CreationError, Currency, Description, InvoiceBuilder as Bolt11InvoiceBuilder, SignOrCreationError, DEFAULT_EXPIRY_TIME}; +use lightning_invoice::{ + Bolt11Invoice, Bolt11InvoiceDescription, CreationError, Currency, Description, + InvoiceBuilder as Bolt11InvoiceBuilder, SignOrCreationError, DEFAULT_EXPIRY_TIME, +}; use alloc::collections::{btree_map, BTreeMap}; use crate::io; +use crate::io::Read; use crate::prelude::*; -use core::{cmp, mem}; +use crate::sync::{Arc, FairRwLock, LockHeldState, LockTestExt, Mutex, RwLock, RwLockReadGuard}; +use bitcoin::hex::impl_fmt_traits; use core::borrow::Borrow; use core::cell::RefCell; -use crate::io::Read; -use crate::sync::{Arc, FairRwLock, LockHeldState, LockTestExt, Mutex, RwLock, RwLockReadGuard}; -use core::sync::atomic::{AtomicUsize, AtomicBool, Ordering}; -use core::time::Duration; use core::ops::Deref; -use bitcoin::hex::impl_fmt_traits; +use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; +use core::time::Duration; +use core::{cmp, mem}; // Re-export this for use in the public API. -pub use crate::ln::outbound_payment::{Bolt12PaymentError, ProbeSendFailure, Retry, RetryableSendFailure, RecipientOnionFields}; #[cfg(any(test, feature = "_externalize_tests"))] pub(crate) use crate::ln::outbound_payment::PaymentSendFailure; +pub use crate::ln::outbound_payment::{ + Bolt12PaymentError, ProbeSendFailure, RecipientOnionFields, Retry, RetryableSendFailure, +}; use crate::ln::script::ShutdownScript; // We hold various information about HTLC relay in the HTLC objects in Channel itself: @@ -296,6 +344,7 @@ pub struct BlindedForward { impl PendingHTLCRouting { // Used to override the onion failure code and data if the HTLC is blinded. + #[rustfmt::skip] fn blinded_failure(&self) -> Option { match self { Self::Forward { blinded: Some(BlindedForward { failure, .. }), .. } => Some(*failure), @@ -395,15 +444,8 @@ pub(super) struct PendingAddHTLCInfo { #[cfg_attr(test, derive(Clone, Debug, PartialEq))] pub(super) enum HTLCForwardInfo { AddHTLC(PendingAddHTLCInfo), - FailHTLC { - htlc_id: u64, - err_packet: msgs::OnionErrorPacket, - }, - FailMalformedHTLC { - htlc_id: u64, - failure_code: u16, - sha256_of_onion: [u8; 32], - }, + FailHTLC { htlc_id: u64, err_packet: msgs::OnionErrorPacket }, + FailMalformedHTLC { htlc_id: u64, failure_code: u16, sha256_of_onion: [u8; 32] }, } /// Whether this blinded HTLC is being failed backwards by the introduction node or a blinded node, @@ -470,6 +512,7 @@ impl PartialOrd for ClaimableHTLC { } } impl Ord for ClaimableHTLC { + #[rustfmt::skip] fn cmp(&self, other: &ClaimableHTLC) -> cmp::Ordering { let res = (self.prev_hop.channel_id, self.prev_hop.htlc_id).cmp( &(other.prev_hop.channel_id, other.prev_hop.htlc_id) @@ -576,7 +619,9 @@ impl Verification for PaymentId { } impl PaymentId { - fn for_inbound_from_htlcs>(key: &[u8; 32], htlcs: I) -> PaymentId { + fn for_inbound_from_htlcs>( + key: &[u8; 32], htlcs: I, + ) -> PaymentId { let mut prev_pair = None; let mut hasher = HmacEngine::new(key); for (channel_id, htlc_id) in htlcs { @@ -642,6 +687,7 @@ pub(crate) enum SentHTLCId { OutboundRoute { session_priv: [u8; SECRET_KEY_SIZE] }, } impl SentHTLCId { + #[rustfmt::skip] pub(crate) fn from_source(source: &HTLCSource) -> Self { match source { HTLCSource::PreviousHopData(hop_data) => Self::PreviousHopData { @@ -713,6 +759,7 @@ pub(crate) use self::fuzzy_channelmanager::*; #[allow(clippy::derive_hash_xor_eq)] // Our Hash is faithful to the data, we just don't have SecretKey::hash impl core::hash::Hash for HTLCSource { + #[rustfmt::skip] fn hash(&self, hasher: &mut H) { match self { HTLCSource::PreviousHopData(prev_hop_data) => { @@ -744,7 +791,9 @@ impl HTLCSource { /// Checks whether this HTLCSource could possibly match the given HTLC output in a commitment /// transaction. Useful to ensure different datastructures match up. - pub(crate) fn possibly_matches_output(&self, htlc: &super::chan_utils::HTLCOutputInCommitment) -> bool { + pub(crate) fn possibly_matches_output( + &self, htlc: &super::chan_utils::HTLCOutputInCommitment, + ) -> bool { if let HTLCSource::OutboundRoute { first_hop_htlc_msat, .. } = self { *first_hop_htlc_msat == htlc.amount_msat } else { @@ -789,6 +838,7 @@ pub enum FailureCode { } impl Into for FailureCode { + #[rustfmt::skip] fn into(self) -> LocalHTLCFailureReason { match self { FailureCode::TemporaryNodeFailure => LocalHTLCFailureReason::TemporaryNodeFailure, @@ -811,6 +861,7 @@ struct MsgHandleErrInternal { } impl MsgHandleErrInternal { #[inline] + #[rustfmt::skip] fn send_err_msg_no_close(err: String, channel_id: ChannelId) -> Self { Self { err: LightningError { @@ -831,7 +882,10 @@ impl MsgHandleErrInternal { Self { err, closes_channel: false, shutdown_finish: None } } #[inline] - fn from_finish_shutdown(err: String, channel_id: ChannelId, shutdown_res: ShutdownResult, channel_update: Option) -> Self { + fn from_finish_shutdown( + err: String, channel_id: ChannelId, shutdown_res: ShutdownResult, + channel_update: Option, + ) -> Self { let err_msg = msgs::ErrorMessage { channel_id, data: err.clone() }; let action = if shutdown_res.monitor_update.is_some() { // We have a closing `ChannelMonitorUpdate`, which means the channel was funded and we @@ -848,6 +902,7 @@ impl MsgHandleErrInternal { } } #[inline] + #[rustfmt::skip] fn from_chan_no_close(err: ChannelError, channel_id: ChannelId) -> Self { Self { err: match err { @@ -940,6 +995,7 @@ struct ClaimablePayment { } impl ClaimablePayment { + #[rustfmt::skip] fn inbound_payment_id(&self, secret: &[u8; 32]) -> PaymentId { PaymentId::for_inbound_from_htlcs( secret, @@ -950,6 +1006,7 @@ impl ClaimablePayment { /// Returns the inbound `(channel_id, user_channel_id)` pairs for all HTLCs associated with the payment. /// /// Note: The `user_channel_id` will be `None` for HTLCs created using LDK version 0.0.117 or prior. + #[rustfmt::skip] fn via_channel_ids(&self) -> Vec<(ChannelId, Option)> { self.htlcs.iter().map(|htlc| { (htlc.prev_hop.channel_id, htlc.prev_hop.user_channel_id) @@ -1031,6 +1088,7 @@ impl ClaimablePayments { /// If `custom_tlvs_known` is true, and a matching payment is found, it will always be moved. /// /// If no payment is found, `Err(Vec::new())` is returned. + #[rustfmt::skip] fn begin_claiming_payment( &mut self, payment_hash: PaymentHash, node_signer: &S, logger: &L, inbound_payment_id_secret: &[u8; 32], custom_tlvs_known: bool, @@ -1105,15 +1163,12 @@ enum BackgroundEvent { counterparty_node_id: PublicKey, funding_txo: OutPoint, channel_id: ChannelId, - update: ChannelMonitorUpdate + update: ChannelMonitorUpdate, }, /// Some [`ChannelMonitorUpdate`] (s) completed before we were serialized but we still have /// them marked pending, thus we need to run any [`MonitorUpdateCompletionAction`] (s) pending /// on a channel. - MonitorUpdatesComplete { - counterparty_node_id: PublicKey, - channel_id: ChannelId, - }, + MonitorUpdatesComplete { counterparty_node_id: PublicKey, channel_id: ChannelId }, } /// A pointer to a channel that is unblocked when an event is surfaced @@ -1310,6 +1365,7 @@ impl_writeable_tlv_based!(PaymentClaimDetails, { pub(crate) struct PendingMPPClaimPointer(Arc>); impl PartialEq for PendingMPPClaimPointer { + #[rustfmt::skip] fn eq(&self, o: &Self) -> bool { Arc::ptr_eq(&self.0, &o.0) } } impl Eq for PendingMPPClaimPointer {} @@ -1340,9 +1396,7 @@ pub(crate) enum RAAMonitorUpdateBlockingAction { /// /// This variant is *not* written to disk, instead being inferred from [`ChannelMonitor`] /// state. - ClaimedMPPPayment { - pending_claim: PendingMPPClaimPointer, - } + ClaimedMPPPayment { pending_claim: PendingMPPClaimPointer }, } impl RAAMonitorUpdateBlockingAction { @@ -1366,7 +1420,10 @@ impl Readable for Option { } /// State we hold per-peer. -pub(super) struct PeerState where SP::Target: SignerProvider { +pub(super) struct PeerState +where + SP::Target: SignerProvider, +{ /// `channel_id` -> `Channel` /// /// Holds all channels where the peer is the counterparty. @@ -1434,10 +1491,14 @@ pub(super) struct PeerState where SP::Target: SignerProvider { peer_storage: Vec, } -impl PeerState where SP::Target: SignerProvider { +impl PeerState +where + SP::Target: SignerProvider, +{ /// Indicates that a peer meets the criteria where we're ok to remove it from our storage. /// If true is passed for `require_disconnected`, the function will return false if we haven't /// disconnected from the node already, ie. `PeerState::is_connected` is set to `true`. + #[rustfmt::skip] fn ok_to_remove(&self, require_disconnected: bool) -> bool { if require_disconnected && self.is_connected { return false @@ -1458,6 +1519,7 @@ impl PeerState where SP::Target: SignerProvider { } // Returns a bool indicating if the given `channel_id` matches a channel we have with this peer. + #[rustfmt::skip] fn has_channel(&self, channel_id: &ChannelId) -> bool { self.channel_by_id.contains_key(channel_id) || self.inbound_channel_request_by_id.contains_key(channel_id) @@ -1533,20 +1595,18 @@ pub type SimpleArcChannelManager = ChannelManager< Arc, Arc, Arc, - Arc>>, - Arc, - Arc, - Arc>>, Arc>>>, - ProbabilisticScoringFeeParameters, - ProbabilisticScorer>>, Arc>, - >>, - Arc>>, - Arc, - Arc, - >>, - Arc + Arc< + DefaultRouter< + Arc>>, + Arc, + Arc, + Arc>>, Arc>>>, + ProbabilisticScoringFeeParameters, + ProbabilisticScorer>>, Arc>, + >, + >, + Arc>>, Arc, Arc>>, + Arc, >; /// [`SimpleRefChannelManager`] is a type alias for a ChannelManager reference, and is the reference @@ -1561,29 +1621,24 @@ pub type SimpleArcChannelManager = ChannelManager< /// /// This is not exported to bindings users as type aliases aren't supported in most languages. #[cfg(not(c_bindings))] -pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, M, T, F, L> = - ChannelManager< - &'a M, - &'b T, - &'c KeysManager, - &'c KeysManager, +pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, M, T, F, L> = ChannelManager< + &'a M, + &'b T, + &'c KeysManager, + &'c KeysManager, + &'c KeysManager, + &'d F, + &'e DefaultRouter< + &'f NetworkGraph<&'g L>, + &'g L, &'c KeysManager, - &'d F, - &'e DefaultRouter< - &'f NetworkGraph<&'g L>, - &'g L, - &'c KeysManager, - &'h RwLock, &'g L>>, - ProbabilisticScoringFeeParameters, - ProbabilisticScorer<&'f NetworkGraph<&'g L>, &'g L> - >, - &'i DefaultMessageRouter< - &'f NetworkGraph<&'g L>, - &'g L, - &'c KeysManager, - >, - &'g L - >; + &'h RwLock, &'g L>>, + ProbabilisticScoringFeeParameters, + ProbabilisticScorer<&'f NetworkGraph<&'g L>, &'g L>, + >, + &'i DefaultMessageRouter<&'f NetworkGraph<&'g L>, &'g L, &'c KeysManager>, + &'g L, +>; /// A trivial trait which describes any [`ChannelManager`]. /// @@ -1609,7 +1664,7 @@ pub trait AChannelManager { /// A type implementing [`EcdsaChannelSigner`]. type Signer: EcdsaChannelSigner + Sized; /// A type implementing [`SignerProvider`] for [`Self::Signer`]. - type SignerProvider: SignerProvider + ?Sized; + type SignerProvider: SignerProvider + ?Sized; /// A type that may be dereferenced to [`Self::SignerProvider`]. type SP: Deref; /// A type implementing [`FeeEstimator`]. @@ -1629,11 +1684,32 @@ pub trait AChannelManager { /// A type that may be dereferenced to [`Self::Logger`]. type L: Deref; /// Returns a reference to the actual [`ChannelManager`] object. - fn get_cm(&self) -> &ChannelManager; + fn get_cm( + &self, + ) -> &ChannelManager< + Self::M, + Self::T, + Self::ES, + Self::NS, + Self::SP, + Self::F, + Self::R, + Self::MR, + Self::L, + >; } -impl AChannelManager -for ChannelManager +impl< + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > AChannelManager for ChannelManager where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -1664,6 +1740,7 @@ where type MR = MR; type Logger = L::Target; type L = L; + #[rustfmt::skip] fn get_cm(&self) -> &ChannelManager { self } } @@ -2450,8 +2527,17 @@ where // | // |__`pending_background_events` // -pub struct ChannelManager -where +pub struct ChannelManager< + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, +> where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, ES::Target: EntropySource, @@ -2737,17 +2823,21 @@ struct PersistenceNotifierGuard<'a, F: FnMut() -> NotifyOption> { _read_guard: RwLockReadGuard<'a, ()>, } -impl<'a> PersistenceNotifierGuard<'a, fn() -> NotifyOption> { // We don't care what the concrete F is here, it's unused +// We don't care what the concrete F is here, it's unused +impl<'a> PersistenceNotifierGuard<'a, fn() -> NotifyOption> { /// Notifies any waiters and indicates that we need to persist, in addition to possibly having /// events to handle. /// /// This must always be called if the changes included a `ChannelMonitorUpdate`, as well as in /// other cases where losing the changes on restart may result in a force-close or otherwise /// isn't ideal. - fn notify_on_drop(cm: &'a C) -> PersistenceNotifierGuard<'a, impl FnMut() -> NotifyOption> { + fn notify_on_drop( + cm: &'a C, + ) -> PersistenceNotifierGuard<'a, impl FnMut() -> NotifyOption> { Self::optionally_notify(cm, || -> NotifyOption { NotifyOption::DoPersist }) } + #[rustfmt::skip] fn optionally_notify NotifyOption, C: AChannelManager>(cm: &'a C, mut persist_check: F) -> PersistenceNotifierGuard<'a, impl FnMut() -> NotifyOption> { let read_guard = cm.get_cm().total_consistency_lock.read().unwrap(); @@ -2775,8 +2865,9 @@ impl<'a> PersistenceNotifierGuard<'a, fn() -> NotifyOption> { // We don't care w /// Note that if any [`ChannelMonitorUpdate`]s are possibly generated, /// [`ChannelManager::process_background_events`] MUST be called first (or /// [`Self::optionally_notify`] used). - fn optionally_notify_skipping_background_events NotifyOption, C: AChannelManager> - (cm: &'a C, persist_check: F) -> PersistenceNotifierGuard<'a, F> { + fn optionally_notify_skipping_background_events NotifyOption, C: AChannelManager>( + cm: &'a C, persist_check: F, + ) -> PersistenceNotifierGuard<'a, F> { let read_guard = cm.get_cm().total_consistency_lock.read().unwrap(); PersistenceNotifierGuard { @@ -2789,6 +2880,7 @@ impl<'a> PersistenceNotifierGuard<'a, fn() -> NotifyOption> { // We don't care w } impl<'a, F: FnMut() -> NotifyOption> Drop for PersistenceNotifierGuard<'a, F> { + #[rustfmt::skip] fn drop(&mut self) { match (self.should_persist)() { NotifyOption::DoPersist => { @@ -2823,7 +2915,7 @@ pub(crate) const MAX_LOCAL_BREAKDOWN_TIMEOUT: u16 = 2 * 6 * 24 * 7; // i.e. the node we forwarded the payment on to should always have enough room to reliably time out // the HTLC via a full update_fail_htlc/commitment_signed dance before we hit the // CLTV_CLAIM_BUFFER point (we static assert that it's at least 3 blocks more). -pub const MIN_CLTV_EXPIRY_DELTA: u16 = 6*8; +pub const MIN_CLTV_EXPIRY_DELTA: u16 = 6 * 8; // This should be long enough to allow a payment path drawn across multiple routing hops with substantial // `cltv_expiry_delta`. Indeed, the length of those values is the reaction delay offered to a routing node // in case of HTLC on-chain settlement. While appearing less competitive, a node operator could decide to @@ -2850,7 +2942,8 @@ pub const MIN_FINAL_CLTV_EXPIRY_DELTA: u16 = HTLC_FAIL_BACK_BUFFER as u16 + 3; // expiry, i.e. assuming the peer force-closes right at the expiry and we're behind by // LATENCY_GRACE_PERIOD_BLOCKS). const _CHECK_CLTV_EXPIRY_SANITY: () = assert!( - MIN_CLTV_EXPIRY_DELTA as u32 >= 2*LATENCY_GRACE_PERIOD_BLOCKS + 2*MAX_BLOCKS_FOR_CONF + ANTI_REORG_DELAY + MIN_CLTV_EXPIRY_DELTA as u32 + >= 2 * LATENCY_GRACE_PERIOD_BLOCKS + 2 * MAX_BLOCKS_FOR_CONF + ANTI_REORG_DELAY ); // Check that our MIN_CLTV_EXPIRY_DELTA gives us enough time to get the HTLC preimage back to our @@ -2866,7 +2959,8 @@ const _CHECK_COUNTERPARTY_REALISTIC: () = assert!(_ASSUMED_COUNTERPARTY_CLTV_CLAIM_BUFFER >= CLTV_CLAIM_BUFFER); const _CHECK_CLTV_EXPIRY_OFFCHAIN: () = assert!( - MIN_CLTV_EXPIRY_DELTA as u32 >= 2*LATENCY_GRACE_PERIOD_BLOCKS - 1 + _ASSUMED_COUNTERPARTY_CLTV_CLAIM_BUFFER + MIN_CLTV_EXPIRY_DELTA as u32 + >= 2 * LATENCY_GRACE_PERIOD_BLOCKS - 1 + _ASSUMED_COUNTERPARTY_CLTV_CLAIM_BUFFER ); /// The number of ticks of [`ChannelManager::timer_tick_occurred`] until expiry of incomplete MPPs @@ -2983,6 +3077,7 @@ pub struct PhantomRouteHints { pub real_node_pubkey: PublicKey, } +#[rustfmt::skip] macro_rules! handle_error { ($self: ident, $internal: expr, $counterparty_node_id: expr) => { { // In testing, ensure there are no deadlocks where the lock is already held upon @@ -3044,6 +3139,7 @@ macro_rules! handle_error { /// /// Note that this step can be skipped if the channel was never opened (through the creation of a /// [`ChannelMonitor`]/channel funding transaction) to begin with. +#[rustfmt::skip] macro_rules! locked_close_channel { ($self: ident, $peer_state: expr, $channel_context: expr, $shutdown_res_mut: expr) => {{ if let Some((_, funding_txo, _, update)) = $shutdown_res_mut.monitor_update.take() { @@ -3077,6 +3173,7 @@ macro_rules! locked_close_channel { } /// Returns (boolean indicating if we should remove the Channel object from memory, a mapped error) +#[rustfmt::skip] macro_rules! convert_channel_err { ($self: ident, $peer_state: expr, $err: expr, $context: expr, $funding: expr, $channel_id: expr, MANUAL_CHANNEL_UPDATE, $channel_update: expr) => { match $err { @@ -3122,6 +3219,7 @@ macro_rules! convert_channel_err { }; } +#[rustfmt::skip] macro_rules! break_channel_entry { ($self: ident, $peer_state: expr, $res: expr, $entry: expr) => { match $res { @@ -3138,6 +3236,7 @@ macro_rules! break_channel_entry { } } +#[rustfmt::skip] macro_rules! try_channel_entry { ($self: ident, $peer_state: expr, $res: expr, $entry: expr) => { match $res { @@ -3154,6 +3253,7 @@ macro_rules! try_channel_entry { } } +#[rustfmt::skip] macro_rules! remove_channel_entry { ($self: ident, $peer_state: expr, $entry: expr, $shutdown_res_mut: expr) => { { @@ -3199,6 +3299,7 @@ macro_rules! emit_funding_tx_broadcast_safe_event { } } +#[rustfmt::skip] macro_rules! emit_channel_pending_event { ($locked_events: expr, $channel: expr) => { if $channel.context.should_emit_channel_pending_event() { @@ -3215,6 +3316,7 @@ macro_rules! emit_channel_pending_event { } } +#[rustfmt::skip] macro_rules! emit_channel_ready_event { ($locked_events: expr, $channel: expr) => { if $channel.context.should_emit_channel_ready_event() { @@ -3461,6 +3563,7 @@ macro_rules! handle_new_monitor_update { } }; } +#[rustfmt::skip] macro_rules! process_events_body { ($self: expr, $event_to_handle: expr, $handle_event: expr) => { let mut handling_failed = false; @@ -3545,7 +3648,17 @@ macro_rules! process_events_body { } } -impl ChannelManager +impl< + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > ChannelManager where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -3574,6 +3687,7 @@ where /// [`block_connected`]: chain::Listen::block_connected /// [`block_disconnected`]: chain::Listen::block_disconnected /// [`params.best_block.block_hash`]: chain::BestBlock::block_hash + #[rustfmt::skip] pub fn new( fee_est: F, chain_monitor: M, tx_broadcaster: T, router: R, message_router: MR, logger: L, entropy_source: ES, node_signer: NS, signer_provider: SP, config: UserConfig, @@ -3660,6 +3774,7 @@ where self.create_and_insert_outbound_scid_alias() } + #[rustfmt::skip] fn create_and_insert_outbound_scid_alias(&self) -> u64 { let height = self.best_block.read().unwrap().height; let mut outbound_scid_alias = 0; @@ -3711,6 +3826,7 @@ where /// [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id /// [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id /// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id + #[rustfmt::skip] pub fn create_channel(&self, their_network_key: PublicKey, channel_value_satoshis: u64, push_msat: u64, user_channel_id: u128, temporary_channel_id: Option, override_config: Option) -> Result { if channel_value_satoshis < 1000 { return Err(APIError::APIMisuseError { err: format!("Channel value must be at least 1000 satoshis. It was {}", channel_value_satoshis) }); @@ -3772,6 +3888,7 @@ where Ok(temporary_channel_id) } + #[rustfmt::skip] fn list_funded_channels_with_filter)) -> bool + Copy>(&self, f: Fn) -> Vec { // Allocate our best estimate of the number of channels we have in the `res` // Vec. Sadly the `short_to_chan_info` map doesn't cover channels without @@ -3803,6 +3920,7 @@ where /// Gets the list of open channels, in random order. See [`ChannelDetails`] field documentation for /// more information. + #[rustfmt::skip] pub fn list_channels(&self) -> Vec { // Allocate our best estimate of the number of channels we have in the `res` // Vec. Sadly the `short_to_chan_info` map doesn't cover channels without @@ -3842,6 +3960,7 @@ where } /// Gets the list of channels we have with a given counterparty, in random order. + #[rustfmt::skip] pub fn list_channels_with_counterparty(&self, counterparty_node_id: &PublicKey) -> Vec { let best_block_height = self.best_block.read().unwrap().height; let per_peer_state = self.per_peer_state.read().unwrap(); @@ -3872,6 +3991,7 @@ where /// [`Event::PaymentSent`] has not been received, you may consider resending the payment. /// /// [`Event::PaymentSent`]: events::Event::PaymentSent + #[rustfmt::skip] pub fn list_recent_payments(&self) -> Vec { self.pending_outbound_payments.pending_outbound_payments.lock().unwrap().iter() .filter_map(|(payment_id, pending_outbound_payment)| match pending_outbound_payment { @@ -3903,6 +4023,7 @@ where .collect() } + #[rustfmt::skip] fn close_channel_internal(&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, target_feerate_sats_per_1000_weight: Option, override_shutdown_script: Option) -> Result<(), APIError> { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); @@ -3998,7 +4119,9 @@ where /// [`ChannelCloseMinimum`]: crate::chain::chaininterface::ConfirmationTarget::ChannelCloseMinimum /// [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee /// [`SendShutdown`]: MessageSendEvent::SendShutdown - pub fn close_channel(&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey) -> Result<(), APIError> { + pub fn close_channel( + &self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, + ) -> Result<(), APIError> { self.close_channel_internal(channel_id, counterparty_node_id, None, None) } @@ -4031,11 +4154,13 @@ where /// [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis /// [`NonAnchorChannelFee`]: crate::chain::chaininterface::ConfirmationTarget::NonAnchorChannelFee /// [`SendShutdown`]: MessageSendEvent::SendShutdown + #[rustfmt::skip] pub fn close_channel_with_feerate_and_script(&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, target_feerate_sats_per_1000_weight: Option, shutdown_script: Option) -> Result<(), APIError> { self.close_channel_internal(channel_id, counterparty_node_id, target_feerate_sats_per_1000_weight, shutdown_script) } /// Applies a [`ChannelMonitorUpdate`] which may or may not be for a channel which is closed. + #[rustfmt::skip] fn apply_post_close_monitor_update( &self, counterparty_node_id: PublicKey, channel_id: ChannelId, funding_txo: OutPoint, monitor_update: ChannelMonitorUpdate, @@ -4071,6 +4196,7 @@ where /// the channel-closing action, /// (b) this needs to be called without holding any locks (except /// [`ChannelManager::total_consistency_lock`]. + #[rustfmt::skip] fn finish_close_channel(&self, mut shutdown_res: ShutdownResult) { debug_assert_ne!(self.per_peer_state.held_by_thread(), LockHeldState::HeldByThread); #[cfg(debug_assertions)] @@ -4173,6 +4299,7 @@ where /// `peer_msg` should be set when we receive a message from a peer, but not set when the /// user closes, which will be re-exposed as the `ChannelClosed` reason. + #[rustfmt::skip] fn force_close_channel_with_peer(&self, channel_id: &ChannelId, peer_node_id: &PublicKey, peer_msg: Option<&String>, broadcast: bool) -> Result { let per_peer_state = self.per_peer_state.read().unwrap(); @@ -4226,6 +4353,7 @@ where Ok(counterparty_node_id) } + #[rustfmt::skip] fn force_close_sending_error(&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, broadcast: bool, error_message: String) -> Result<(), APIError> { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); @@ -4259,8 +4387,9 @@ where /// /// Fails if `channel_id` is unknown to the manager, or if the `counterparty_node_id` /// isn't the counterparty of the corresponding channel. - pub fn force_close_broadcasting_latest_txn(&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, error_message: String) - -> Result<(), APIError> { + pub fn force_close_broadcasting_latest_txn( + &self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, error_message: String, + ) -> Result<(), APIError> { self.force_close_sending_error(channel_id, counterparty_node_id, true, error_message) } @@ -4274,8 +4403,9 @@ where /// `counterparty_node_id` isn't the counterparty of the corresponding channel. /// You can always broadcast the latest local transaction(s) via /// [`ChannelMonitor::broadcast_latest_holder_commitment_txn`]. - pub fn force_close_without_broadcasting_txn(&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, error_message: String) - -> Result<(), APIError> { + pub fn force_close_without_broadcasting_txn( + &self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, error_message: String, + ) -> Result<(), APIError> { self.force_close_sending_error(channel_id, counterparty_node_id, false, error_message) } @@ -4284,6 +4414,7 @@ where /// /// The provided `error_message` is sent to connected peers for closing channels and should /// be a human-readable description of what went wrong. + #[rustfmt::skip] pub fn force_close_all_channels_broadcasting_latest_txn(&self, error_message: String) { for chan in self.list_channels() { let _ = self.force_close_broadcasting_latest_txn(&chan.channel_id, &chan.counterparty.node_id, error_message.clone()); @@ -4295,6 +4426,7 @@ where /// /// The provided `error_message` is sent to connected peers for closing channels and /// should be a human-readable description of what went wrong. + #[rustfmt::skip] pub fn force_close_all_channels_without_broadcasting_txn(&self, error_message: String) { for chan in self.list_channels() { let _ = self.force_close_without_broadcasting_txn(&chan.channel_id, &chan.counterparty.node_id, error_message.clone()); @@ -4313,6 +4445,7 @@ where /// Includes the witness weight for this input (e.g. P2WPKH_WITNESS_WEIGHT=109 for typical P2WPKH inputs). /// - `locktime`: Optional locktime for the new funding transaction. If None, set to the current block height. #[cfg(splicing)] + #[rustfmt::skip] pub fn splice_channel( &self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, our_funding_contribution_satoshis: i64, our_funding_inputs: Vec<(TxIn, Transaction, Weight)>, @@ -4334,6 +4467,7 @@ where /// See [`splice_channel`] #[cfg(splicing)] + #[rustfmt::skip] fn internal_splice_channel( &self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, our_funding_contribution_satoshis: i64, our_funding_inputs: &Vec<(TxIn, Transaction, Weight)>, @@ -4381,6 +4515,7 @@ where } } + #[rustfmt::skip] fn can_forward_htlc_to_outgoing_channel( &self, chan: &mut FundedChannel, msg: &msgs::UpdateAddHTLC, next_packet: &NextPacketDetails ) -> Result<(), LocalHTLCFailureReason> { @@ -4423,6 +4558,7 @@ where /// Executes a callback `C` that returns some value `X` on the channel found with the given /// `scid`. `None` is returned when the channel is not found. + #[rustfmt::skip] fn do_funded_channel_callback) -> X>( &self, scid: u64, callback: C, ) -> Option { @@ -4443,6 +4579,7 @@ where } } + #[rustfmt::skip] fn can_forward_htlc( &self, msg: &msgs::UpdateAddHTLC, next_packet_details: &NextPacketDetails ) -> Result<(), LocalHTLCFailureReason> { @@ -4475,6 +4612,7 @@ where Ok(()) } + #[rustfmt::skip] fn htlc_failure_from_update_add_err( &self, msg: &msgs::UpdateAddHTLC, counterparty_node_id: &PublicKey, reason: LocalHTLCFailureReason, is_intro_node_blinded_forward: bool, @@ -4527,6 +4665,7 @@ where }) } + #[rustfmt::skip] fn construct_pending_htlc_fail_msg<'a>( &self, msg: &msgs::UpdateAddHTLC, counterparty_node_id: &PublicKey, shared_secret: [u8; 32], inbound_err: InboundHTLCErr @@ -4555,6 +4694,7 @@ where }); } + #[rustfmt::skip] fn get_pending_htlc_info<'a>( &self, msg: &msgs::UpdateAddHTLC, shared_secret: [u8; 32], decoded_hop: onion_utils::Hop, allow_underpay: bool, @@ -4592,6 +4732,7 @@ where /// /// [`channel_update`]: msgs::ChannelUpdate /// [`internal_closing_signed`]: Self::internal_closing_signed + #[rustfmt::skip] fn get_channel_update_for_broadcast(&self, chan: &FundedChannel) -> Result { if !chan.context.should_announce() { return Err(LightningError { @@ -4618,6 +4759,7 @@ where /// /// [`channel_update`]: msgs::ChannelUpdate /// [`internal_closing_signed`]: Self::internal_closing_signed + #[rustfmt::skip] fn get_channel_update_for_unicast(&self, chan: &FundedChannel) -> Result { let logger = WithChannelContext::from(&self.logger, &chan.context, None); log_trace!(logger, "Attempting to generate channel update for channel {}", chan.context.channel_id()); @@ -4657,6 +4799,7 @@ where } #[cfg(any(test, feature = "_externalize_tests"))] + #[rustfmt::skip] pub(crate) fn test_send_payment_along_path(&self, path: &Path, payment_hash: &PaymentHash, recipient_onion: RecipientOnionFields, total_value: u64, cur_height: u32, payment_id: PaymentId, keysend_preimage: &Option, session_priv_bytes: [u8; 32]) -> Result<(), APIError> { let _lck = self.total_consistency_lock.read().unwrap(); self.send_payment_along_path(SendAlongPathArgs { @@ -4665,6 +4808,7 @@ where }) } + #[rustfmt::skip] fn send_payment_along_path(&self, args: SendAlongPathArgs) -> Result<(), APIError> { let SendAlongPathArgs { path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage, @@ -4761,6 +4905,7 @@ where /// /// LDK will not automatically retry this payment, though it may be manually re-sent after an /// [`Event::PaymentFailed`] is generated. + #[rustfmt::skip] pub fn send_payment_with_route( &self, mut route: Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, payment_id: PaymentId @@ -4818,6 +4963,7 @@ where /// [`UpdateHTLCs`]: MessageSendEvent::UpdateHTLCs /// [`PeerManager::process_events`]: crate::ln::peer_handler::PeerManager::process_events /// [`ChannelMonitorUpdateStatus::InProgress`]: crate::chain::ChannelMonitorUpdateStatus::InProgress + #[rustfmt::skip] pub fn send_payment( &self, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry @@ -4832,6 +4978,7 @@ where } #[cfg(any(test, feature = "_externalize_tests"))] + #[rustfmt::skip] pub(super) fn test_send_payment_internal(&self, route: &Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, keysend_preimage: Option, payment_id: PaymentId, recv_value_msat: Option, onion_session_privs: Vec<[u8; 32]>) -> Result<(), PaymentSendFailure> { let best_block_height = self.best_block.read().unwrap().height; let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); @@ -4841,12 +4988,14 @@ where } #[cfg(any(test, feature = "_externalize_tests"))] + #[rustfmt::skip] pub(crate) fn test_add_new_pending_payment(&self, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, payment_id: PaymentId, route: &Route) -> Result, PaymentSendFailure> { let best_block_height = self.best_block.read().unwrap().height; self.pending_outbound_payments.test_add_new_pending_payment(payment_hash, recipient_onion, payment_id, route, None, &self.entropy_source, best_block_height) } #[cfg(all(test, async_payments))] + #[rustfmt::skip] pub(crate) fn test_modify_pending_payment( &self, payment_id: &PaymentId, mut callback: Fn ) where Fn: FnMut(&mut PendingOutboundPayment) { @@ -4858,7 +5007,9 @@ where } #[cfg(test)] - pub(crate) fn test_set_payment_metadata(&self, payment_id: PaymentId, new_payment_metadata: Option>) { + pub(crate) fn test_set_payment_metadata( + &self, payment_id: PaymentId, new_payment_metadata: Option>, + ) { self.pending_outbound_payments.test_set_payment_metadata(payment_id, new_payment_metadata); } @@ -4877,6 +5028,7 @@ where /// # Custom Routing Parameters /// Users can customize routing parameters via [`RouteParametersConfig`]. /// To use default settings, call the function with [`RouteParametersConfig::default`]. + #[rustfmt::skip] pub fn pay_for_bolt11_invoice( &self, invoice: &Bolt11Invoice, payment_id: PaymentId, amount_msats: Option, route_params_config: RouteParametersConfig, retry_strategy: Retry @@ -4936,6 +5088,7 @@ where } } + #[rustfmt::skip] fn send_payment_for_verified_bolt12_invoice(&self, invoice: &Bolt12Invoice, payment_id: PaymentId) -> Result<(), Bolt12PaymentError> { let best_block_height = self.best_block.read().unwrap().height; let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); @@ -4950,6 +5103,7 @@ where } #[cfg(async_payments)] + #[rustfmt::skip] fn initiate_async_payment( &self, invoice: &StaticInvoice, payment_id: PaymentId ) -> Result<(), Bolt12PaymentError> { @@ -4988,6 +5142,7 @@ where } #[cfg(async_payments)] + #[rustfmt::skip] fn send_payment_for_static_invoice( &self, payment_id: PaymentId ) -> Result<(), Bolt12PaymentError> { @@ -5064,6 +5219,7 @@ where /// /// [`send_payment`]: Self::send_payment /// [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend + #[rustfmt::skip] pub fn send_spontaneous_payment( &self, payment_preimage: Option, recipient_onion: RecipientOnionFields, payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry @@ -5079,6 +5235,7 @@ where /// Send a payment that is probing the given route for liquidity. We calculate the /// [`PaymentHash`] of probes based on a static secret and a random [`PaymentId`], which allows /// us to easily discern them from real payments. + #[rustfmt::skip] pub fn send_probe(&self, path: Path) -> Result<(PaymentHash, PaymentId), ProbeSendFailure> { let best_block_height = self.best_block.read().unwrap().height; let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); @@ -5090,7 +5247,9 @@ where /// Returns whether a payment with the given [`PaymentHash`] and [`PaymentId`] is, in fact, a /// payment probe. #[cfg(test)] - pub(crate) fn payment_is_probe(&self, payment_hash: &PaymentHash, payment_id: &PaymentId) -> bool { + pub(crate) fn payment_is_probe( + &self, payment_hash: &PaymentHash, payment_id: &PaymentId, + ) -> bool { outbound_payment::payment_is_probe(payment_hash, payment_id, self.probing_cookie_secret) } @@ -5098,6 +5257,7 @@ where /// amount to the given `node_id`. /// /// See [`ChannelManager::send_preflight_probes`] for more information. + #[rustfmt::skip] pub fn send_spontaneous_preflight_probes( &self, node_id: PublicKey, amount_msat: u64, final_cltv_expiry_delta: u32, liquidity_limit_multiplier: Option, @@ -5206,6 +5366,7 @@ where /// Handles the generation of a funding transaction, optionally (for tests) with a function /// which checks the correctness of the funding transaction given the associated channel. + #[rustfmt::skip] fn funding_transaction_generated_intern) -> Result>( &self, temporary_channel_id: ChannelId, counterparty_node_id: PublicKey, funding_transaction: Transaction, is_batch_funding: bool, mut find_funding_output: FundingOutput, is_manual_broadcast: bool, @@ -5301,6 +5462,7 @@ where } #[cfg(any(test, feature = "_externalize_tests"))] + #[rustfmt::skip] pub(crate) fn funding_transaction_generated_unchecked(&self, temporary_channel_id: ChannelId, counterparty_node_id: PublicKey, funding_transaction: Transaction, output_index: u16) -> Result<(), APIError> { let txid = funding_transaction.compute_txid(); self.funding_transaction_generated_intern(temporary_channel_id, counterparty_node_id, funding_transaction, false, |_| { @@ -5338,11 +5500,11 @@ where /// /// [`Event::FundingGenerationReady`]: crate::events::Event::FundingGenerationReady /// [`Event::ChannelClosed`]: crate::events::Event::ChannelClosed + #[rustfmt::skip] pub fn funding_transaction_generated(&self, temporary_channel_id: ChannelId, counterparty_node_id: PublicKey, funding_transaction: Transaction) -> Result<(), APIError> { self.batch_funding_transaction_generated(&[(&temporary_channel_id, &counterparty_node_id)], funding_transaction) } - /// **Unsafe**: This method does not validate the spent output. It is the caller's /// responsibility to ensure the spent outputs are SegWit, as well as making sure the funding /// transaction has a final absolute locktime, i.e., its locktime is lower than the next block height. @@ -5370,6 +5532,7 @@ where /// [`Event::FundingTxBroadcastSafe`]: crate::events::Event::FundingTxBroadcastSafe /// [`Event::ChannelClosed`]: crate::events::Event::ChannelClosed /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated + #[rustfmt::skip] pub fn unsafe_manual_funding_transaction_generated(&self, temporary_channel_id: ChannelId, counterparty_node_id: PublicKey, funding: OutPoint) -> Result<(), APIError> { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); @@ -5388,11 +5551,13 @@ where /// signature for each channel. /// /// If there is an error, all channels in the batch are to be considered closed. + #[rustfmt::skip] pub fn batch_funding_transaction_generated(&self, temporary_channels: &[(&ChannelId, &PublicKey)], funding_transaction: Transaction) -> Result<(), APIError> { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); self.batch_funding_transaction_generated_intern(temporary_channels, FundingType::Checked(funding_transaction)) } + #[rustfmt::skip] fn batch_funding_transaction_generated_intern(&self, temporary_channels: &[(&ChannelId, &PublicKey)], funding: FundingType) -> Result<(), APIError> { let mut result = Ok(()); if let FundingType::Checked(funding_transaction) = &funding { @@ -5548,6 +5713,7 @@ where /// [`ChannelUpdate`]: msgs::ChannelUpdate /// [`ChannelUnavailable`]: APIError::ChannelUnavailable /// [`APIMisuseError`]: APIError::APIMisuseError + #[rustfmt::skip] pub fn update_partial_channel_config( &self, counterparty_node_id: &PublicKey, channel_ids: &[ChannelId], config_update: &ChannelConfigUpdate, ) -> Result<(), APIError> { @@ -5625,6 +5791,7 @@ where /// [`ChannelUpdate`]: msgs::ChannelUpdate /// [`ChannelUnavailable`]: APIError::ChannelUnavailable /// [`APIMisuseError`]: APIError::APIMisuseError + #[rustfmt::skip] pub fn update_channel_config( &self, counterparty_node_id: &PublicKey, channel_ids: &[ChannelId], config: &ChannelConfig, ) -> Result<(), APIError> { @@ -5656,6 +5823,7 @@ where /// [`HTLCIntercepted::expected_outbound_amount_msat`]: events::Event::HTLCIntercepted::expected_outbound_amount_msat // TODO: when we move to deciding the best outbound channel at forward time, only take // `next_node_id` and not `next_hop_channel_id` + #[rustfmt::skip] pub fn forward_intercepted_htlc(&self, intercept_id: InterceptId, next_hop_channel_id: &ChannelId, next_node_id: PublicKey, amt_to_forward_msat: u64) -> Result<(), APIError> { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); @@ -5730,6 +5898,7 @@ where /// backwards. /// /// [`HTLCIntercepted`]: events::Event::HTLCIntercepted + #[rustfmt::skip] pub fn fail_intercepted_htlc(&self, intercept_id: InterceptId) -> Result<(), APIError> { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); @@ -5760,6 +5929,7 @@ where Ok(()) } + #[rustfmt::skip] pub(crate) fn process_pending_update_add_htlcs(&self) { let mut decode_update_add_htlcs = new_hash_map(); mem::swap(&mut decode_update_add_htlcs, &mut self.decode_update_add_htlcs.lock().unwrap()); @@ -5906,6 +6076,7 @@ where /// /// Should only really ever be called in response to a PendingHTLCsForwardable event. /// Will likely generate further events. + #[rustfmt::skip] pub fn process_pending_htlc_forwards(&self) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); @@ -6518,6 +6689,7 @@ where /// Free the background events, generally called from [`PersistenceNotifierGuard`] constructors. /// /// Expects the caller to have a total_consistency_lock read lock. + #[rustfmt::skip] fn process_background_events(&self) -> NotifyOption { debug_assert_ne!(self.total_consistency_lock.held_by_thread(), LockHeldState::NotHeldByThread); @@ -6565,6 +6737,7 @@ where let _ = self.process_background_events(); } + #[rustfmt::skip] fn update_channel_fee(&self, chan_id: &ChannelId, chan: &mut FundedChannel, new_feerate: u32) -> NotifyOption { if !chan.funding.is_outbound() { return NotifyOption::SkipPersistNoEvents; } @@ -6591,6 +6764,7 @@ where /// timer_tick_occurred, but we can't generate the disabled channel updates as it considers /// these a fuzz failure (as they usually indicate a channel force-close, which is exactly what /// it wants to detect). Thus, we have a variant exposed here for its benefit. + #[rustfmt::skip] pub fn maybe_update_chan_fees(&self) { PersistenceNotifierGuard::optionally_notify(self, || { let mut should_persist = NotifyOption::SkipPersistNoEvents; @@ -6640,6 +6814,7 @@ where /// /// [`ChannelUpdate`]: msgs::ChannelUpdate /// [`ChannelConfig`]: crate::util::config::ChannelConfig + #[rustfmt::skip] pub fn timer_tick_occurred(&self) { PersistenceNotifierGuard::optionally_notify(self, || { let mut should_persist = NotifyOption::SkipPersistNoEvents; @@ -6896,6 +7071,7 @@ where /// [`ChannelManager::claim_funds`]), you should still monitor for /// [`events::Event::PaymentClaimed`] events even for payments you intend to fail, especially on /// startup during which time claims that were in-progress at shutdown may be replayed. + #[rustfmt::skip] pub fn fail_htlc_backwards(&self, payment_hash: &PaymentHash) { self.fail_htlc_backwards_with_reason(payment_hash, FailureCode::IncorrectOrUnknownPaymentDetails); } @@ -6904,6 +7080,7 @@ where /// reason for the failure. /// /// See [`FailureCode`] for valid failure codes. + #[rustfmt::skip] pub fn fail_htlc_backwards_with_reason(&self, payment_hash: &PaymentHash, failure_code: FailureCode) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); @@ -6919,6 +7096,7 @@ where } /// Gets error data to form an [`HTLCFailReason`] given a [`FailureCode`] and [`ClaimableHTLC`]. + #[rustfmt::skip] fn get_htlc_fail_reason_from_failure_code(&self, failure_code: FailureCode, htlc: &ClaimableHTLC) -> HTLCFailReason { match failure_code { FailureCode::TemporaryNodeFailure => HTLCFailReason::from_failure_code(failure_code.into()), @@ -6963,6 +7141,7 @@ where // Fail a list of HTLCs that were just freed from the holding cell. The HTLCs need to be // failed backwards or, if they were one of our outgoing HTLCs, then their failure needs to // be surfaced to the user. + #[rustfmt::skip] fn fail_holding_cell_htlcs( &self, mut htlcs_to_fail: Vec<(HTLCSource, PaymentHash)>, channel_id: ChannelId, counterparty_node_id: &PublicKey @@ -6996,6 +7175,7 @@ where } } + #[rustfmt::skip] fn fail_htlc_backwards_internal(&self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason, destination: HTLCHandlingFailureType) { let push_forward_event = self.fail_htlc_backwards_internal_without_forward_event(source, payment_hash, onion_error, destination); if push_forward_event { self.push_pending_forwards_ev(); } @@ -7003,6 +7183,7 @@ where /// Fails an HTLC backwards to the sender of it to us. /// Note that we do not assume that channels corresponding to failed HTLCs are still available. + #[rustfmt::skip] fn fail_htlc_backwards_internal_without_forward_event(&self, source: &HTLCSource, payment_hash: &PaymentHash, onion_error: &HTLCFailReason, failure_type: HTLCHandlingFailureType) -> bool { // Ensure that no peer state channel storage lock is held when calling this function. // This ensures that future code doesn't introduce a lock-order requirement for @@ -7124,6 +7305,7 @@ where self.claim_payment_internal(payment_preimage, true); } + #[rustfmt::skip] fn claim_payment_internal(&self, payment_preimage: PaymentPreimage, custom_tlvs_known: bool) { let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).to_byte_array()); @@ -7260,7 +7442,10 @@ where } fn claim_funds_from_hop< - ComplFunc: FnOnce(Option, bool) -> (Option, Option) + ComplFunc: FnOnce( + Option, + bool, + ) -> (Option, Option), >( &self, prev_hop: HTLCPreviousHopData, payment_preimage: PaymentPreimage, payment_info: Option, completion_action: ComplFunc, @@ -7279,6 +7464,7 @@ where self.claim_mpp_part(htlc_source, payment_preimage, payment_info, completion_action) } + #[rustfmt::skip] fn claim_mpp_part< ComplFunc: FnOnce(Option, bool) -> (Option, Option) >( @@ -7464,6 +7650,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ self.pending_outbound_payments.finalize_claims(sources, &self.pending_events); } + #[rustfmt::skip] fn claim_funds_internal(&self, source: HTLCSource, payment_preimage: PaymentPreimage, forwarded_htlc_value_msat: Option, skimmed_fee_msat: Option, from_onchain: bool, startup_replay: bool, next_channel_counterparty_node_id: PublicKey, @@ -7545,6 +7732,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ self.our_network_pubkey } + #[rustfmt::skip] fn handle_monitor_update_completion_actions>(&self, actions: I) { debug_assert_ne!(self.pending_events.held_by_thread(), LockHeldState::HeldByThread); debug_assert_ne!(self.claimable_payments.held_by_thread(), LockHeldState::HeldByThread); @@ -7653,6 +7841,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ /// Handles a channel reentering a functional state, either due to reconnect or a monitor /// update completion. + #[rustfmt::skip] fn handle_channel_resumption(&self, pending_msg_events: &mut Vec, channel: &mut FundedChannel, raa: Option, commitment_update: Option, order: RAACommitmentOrder, @@ -7768,6 +7957,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ (htlc_forwards, decode_update_add_htlcs) } + #[rustfmt::skip] fn channel_monitor_updated(&self, channel_id: &ChannelId, highest_applied_update_id: u64, counterparty_node_id: &PublicKey) { debug_assert!(self.total_consistency_lock.try_write().is_err()); // Caller holds read lock @@ -7832,6 +8022,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ /// /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id + #[rustfmt::skip] pub fn accept_inbound_channel(&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, user_channel_id: u128, config_overrides: Option) -> Result<(), APIError> { self.do_accept_inbound_channel(temporary_channel_id, counterparty_node_id, false, user_channel_id, config_overrides) } @@ -7854,11 +8045,13 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ /// /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id + #[rustfmt::skip] pub fn accept_inbound_channel_from_trusted_peer_0conf(&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, user_channel_id: u128, config_overrides: Option) -> Result<(), APIError> { self.do_accept_inbound_channel(temporary_channel_id, counterparty_node_id, true, user_channel_id, config_overrides) } /// TODO(dual_funding): Allow contributions, pass intended amount and inputs + #[rustfmt::skip] fn do_accept_inbound_channel( &self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, accept_0conf: bool, user_channel_id: u128, config_overrides: Option @@ -8014,6 +8207,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ /// /// The filter is called for each peer and provided with the number of unfunded, inbound, and /// non-0-conf channels we have with the peer. + #[rustfmt::skip] fn peers_without_funded_channels(&self, maybe_count_peer: Filter) -> usize where Filter: Fn(&PeerState) -> bool { let mut peers_without_funded_channels = 0; @@ -8032,6 +8226,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ return peers_without_funded_channels; } + #[rustfmt::skip] fn unfunded_channel_count( peer: &PeerState, best_block_height: u32 ) -> usize { @@ -8072,6 +8267,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ num_unfunded_channels + peer.inbound_channel_request_by_id.len() } + #[rustfmt::skip] fn internal_open_channel(&self, counterparty_node_id: &PublicKey, msg: OpenChannelMessageRef<'_>) -> Result<(), MsgHandleErrInternal> { let common_fields = match msg { OpenChannelMessageRef::V1(msg) => &msg.common_fields, @@ -8222,6 +8418,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ Ok(()) } + #[rustfmt::skip] fn internal_accept_channel(&self, counterparty_node_id: &PublicKey, msg: &msgs::AcceptChannel) -> Result<(), MsgHandleErrInternal> { // Note that the ChannelManager is NOT re-persisted on disk after this, so any changes are // likely to be lost on restart! @@ -8260,6 +8457,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ Ok(()) } + #[rustfmt::skip] fn internal_funding_created(&self, counterparty_node_id: &PublicKey, msg: &msgs::FundingCreated) -> Result<(), MsgHandleErrInternal> { let best_block = *self.best_block.read().unwrap(); @@ -8347,6 +8545,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } } + #[rustfmt::skip] fn internal_peer_storage_retrieval(&self, counterparty_node_id: PublicKey, _msg: msgs::PeerStorageRetrieval) -> Result<(), MsgHandleErrInternal> { // TODO: Decrypt and check if have any stale or missing ChannelMonitor. let logger = WithContext::from(&self.logger, Some(counterparty_node_id), None, None); @@ -8358,6 +8557,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ ), ChannelId([0; 32]))) } + #[rustfmt::skip] fn internal_peer_storage(&self, counterparty_node_id: PublicKey, msg: msgs::PeerStorage) -> Result<(), MsgHandleErrInternal> { let per_peer_state = self.per_peer_state.read().unwrap(); let peer_state_mutex = per_peer_state.get(&counterparty_node_id) @@ -8393,6 +8593,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ Ok(()) } + #[rustfmt::skip] fn internal_funding_signed(&self, counterparty_node_id: &PublicKey, msg: &msgs::FundingSigned) -> Result<(), MsgHandleErrInternal> { let best_block = *self.best_block.read().unwrap(); let per_peer_state = self.per_peer_state.read().unwrap(); @@ -8434,6 +8635,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } } + #[rustfmt::skip] fn internal_tx_msg) -> Result>( &self, counterparty_node_id: &PublicKey, channel_id: ChannelId, tx_msg_handler: HandleTxMsgFn ) -> Result<(), MsgHandleErrInternal> { @@ -8468,7 +8670,9 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } } - fn internal_tx_add_input(&self, counterparty_node_id: PublicKey, msg: &msgs::TxAddInput) -> Result<(), MsgHandleErrInternal> { + fn internal_tx_add_input( + &self, counterparty_node_id: PublicKey, msg: &msgs::TxAddInput, + ) -> Result<(), MsgHandleErrInternal> { self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel: &mut Channel| { match channel.as_unfunded_v2_mut() { Some(unfunded_channel) => { @@ -8479,6 +8683,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ }) } + #[rustfmt::skip] fn internal_tx_add_output(&self, counterparty_node_id: PublicKey, msg: &msgs::TxAddOutput) -> Result<(), MsgHandleErrInternal> { self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel: &mut Channel| { match channel.as_unfunded_v2_mut() { @@ -8490,6 +8695,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ }) } + #[rustfmt::skip] fn internal_tx_remove_input(&self, counterparty_node_id: PublicKey, msg: &msgs::TxRemoveInput) -> Result<(), MsgHandleErrInternal> { self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel: &mut Channel| { match channel.as_unfunded_v2_mut() { @@ -8501,6 +8707,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ }) } + #[rustfmt::skip] fn internal_tx_remove_output(&self, counterparty_node_id: PublicKey, msg: &msgs::TxRemoveOutput) -> Result<(), MsgHandleErrInternal> { self.internal_tx_msg(&counterparty_node_id, msg.channel_id, |channel: &mut Channel| { match channel.as_unfunded_v2_mut() { @@ -8512,6 +8719,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ }) } + #[rustfmt::skip] fn internal_tx_complete(&self, counterparty_node_id: PublicKey, msg: &msgs::TxComplete) -> Result<(), MsgHandleErrInternal> { let per_peer_state = self.per_peer_state.read().unwrap(); let peer_state_mutex = per_peer_state.get(&counterparty_node_id) @@ -8567,6 +8775,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } } + #[rustfmt::skip] fn internal_tx_signatures(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxSignatures) -> Result<(), MsgHandleErrInternal> { let per_peer_state = self.per_peer_state.read().unwrap(); @@ -8613,6 +8822,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } } + #[rustfmt::skip] fn internal_tx_abort(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAbort) -> Result<(), MsgHandleErrInternal> { let per_peer_state = self.per_peer_state.read().unwrap(); @@ -8675,6 +8885,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } } + #[rustfmt::skip] fn internal_channel_ready(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReady) -> Result<(), MsgHandleErrInternal> { // Note that the ChannelManager is NOT re-persisted on disk after this (unless we error // closing a channel), so any changes are likely to be lost on restart! @@ -8730,6 +8941,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } } + #[rustfmt::skip] fn internal_shutdown(&self, counterparty_node_id: &PublicKey, msg: &msgs::Shutdown) -> Result<(), MsgHandleErrInternal> { let mut dropped_htlcs: Vec<(HTLCSource, PaymentHash)> = Vec::new(); let mut finish_shutdown = None; @@ -8796,6 +9008,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ Ok(()) } + #[rustfmt::skip] fn internal_closing_signed(&self, counterparty_node_id: &PublicKey, msg: &msgs::ClosingSigned) -> Result<(), MsgHandleErrInternal> { let per_peer_state = self.per_peer_state.read().unwrap(); let peer_state_mutex = per_peer_state.get(counterparty_node_id) @@ -8859,6 +9072,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ Ok(()) } + #[rustfmt::skip] fn internal_update_add_htlc(&self, counterparty_node_id: &PublicKey, msg: &msgs::UpdateAddHTLC) -> Result<(), MsgHandleErrInternal> { //TODO: BOLT 4 points out a specific attack where a peer may re-send an onion packet and //determine the state of the payment based on our response/if we forward anything/the time @@ -8894,6 +9108,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ Ok(()) } + #[rustfmt::skip] fn internal_update_fulfill_htlc(&self, counterparty_node_id: &PublicKey, msg: &msgs::UpdateFulfillHTLC) -> Result<(), MsgHandleErrInternal> { let funding_txo; let next_user_channel_id; @@ -8944,6 +9159,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ Ok(()) } + #[rustfmt::skip] fn internal_update_fail_htlc(&self, counterparty_node_id: &PublicKey, msg: &msgs::UpdateFailHTLC) -> Result<(), MsgHandleErrInternal> { // Note that the ChannelManager is NOT re-persisted on disk after this (unless we error // closing a channel), so any changes are likely to be lost on restart! @@ -8969,6 +9185,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ Ok(()) } + #[rustfmt::skip] fn internal_update_fail_malformed_htlc(&self, counterparty_node_id: &PublicKey, msg: &msgs::UpdateFailMalformedHTLC) -> Result<(), MsgHandleErrInternal> { // Note that the ChannelManager is NOT re-persisted on disk after this (unless we error // closing a channel), so any changes are likely to be lost on restart! @@ -8998,6 +9215,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } } + #[rustfmt::skip] fn internal_commitment_signed(&self, counterparty_node_id: &PublicKey, msg: &msgs::CommitmentSigned) -> Result<(), MsgHandleErrInternal> { let best_block = *self.best_block.read().unwrap(); let per_peer_state = self.per_peer_state.read().unwrap(); @@ -9044,6 +9262,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } } + #[rustfmt::skip] fn internal_commitment_signed_batch(&self, counterparty_node_id: &PublicKey, channel_id: ChannelId, batch: &BTreeMap) -> Result<(), MsgHandleErrInternal> { let per_peer_state = self.per_peer_state.read().unwrap(); let peer_state_mutex = per_peer_state.get(counterparty_node_id) @@ -9076,6 +9295,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } } + #[rustfmt::skip] fn push_decode_update_add_htlcs(&self, mut update_add_htlcs: (u64, Vec)) { let mut push_forward_event = self.forward_htlcs.lock().unwrap().is_empty(); let mut decode_update_add_htlcs = self.decode_update_add_htlcs.lock().unwrap(); @@ -9089,12 +9309,14 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } #[inline] + #[rustfmt::skip] fn forward_htlcs(&self, per_source_pending_forwards: &mut [(u64, Option, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) { let push_forward_event = self.forward_htlcs_without_forward_event(per_source_pending_forwards); if push_forward_event { self.push_pending_forwards_ev() } } #[inline] + #[rustfmt::skip] fn forward_htlcs_without_forward_event(&self, per_source_pending_forwards: &mut [(u64, Option, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)]) -> bool { let mut push_forward_event = false; for &mut (prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint, prev_channel_id, prev_user_channel_id, ref mut pending_forwards) in per_source_pending_forwards { @@ -9189,6 +9411,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ push_forward_event } + #[rustfmt::skip] fn push_pending_forwards_ev(&self) { let mut pending_events = self.pending_events.lock().unwrap(); let is_processing_events = self.pending_events_processor.load(Ordering::Acquire); @@ -9212,6 +9435,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ /// [`msgs::RevokeAndACK`] should be held for the given channel until some other action /// completes. Note that this needs to happen in the same [`PeerState`] mutex as any release of /// the [`ChannelMonitorUpdate`] in question. + #[rustfmt::skip] fn raa_monitor_updates_held(&self, actions_blocking_raa_monitor_updates: &BTreeMap>, channel_funding_outpoint: OutPoint, channel_id: ChannelId, counterparty_node_id: PublicKey @@ -9228,6 +9452,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } #[cfg(any(test, feature = "_test_utils"))] + #[rustfmt::skip] pub(crate) fn test_raa_monitor_updates_held(&self, counterparty_node_id: PublicKey, channel_id: ChannelId ) -> bool { @@ -9244,6 +9469,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ false } + #[rustfmt::skip] fn internal_revoke_and_ack(&self, counterparty_node_id: &PublicKey, msg: &msgs::RevokeAndACK) -> Result<(), MsgHandleErrInternal> { let htlcs_to_fail = { let per_peer_state = self.per_peer_state.read().unwrap(); @@ -9284,6 +9510,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ Ok(()) } + #[rustfmt::skip] fn internal_update_fee(&self, counterparty_node_id: &PublicKey, msg: &msgs::UpdateFee) -> Result<(), MsgHandleErrInternal> { let per_peer_state = self.per_peer_state.read().unwrap(); let peer_state_mutex = per_peer_state.get(counterparty_node_id) @@ -9308,6 +9535,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ Ok(()) } + #[rustfmt::skip] fn internal_stfu(&self, counterparty_node_id: &PublicKey, msg: &msgs::Stfu) -> Result { let per_peer_state = self.per_peer_state.read().unwrap(); let peer_state_mutex = per_peer_state.get(counterparty_node_id).ok_or_else(|| { @@ -9360,6 +9588,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ Ok(sent_stfu) } + #[rustfmt::skip] fn internal_announcement_signatures(&self, counterparty_node_id: &PublicKey, msg: &msgs::AnnouncementSignatures) -> Result<(), MsgHandleErrInternal> { let per_peer_state = self.per_peer_state.read().unwrap(); let peer_state_mutex = per_peer_state.get(counterparty_node_id) @@ -9396,6 +9625,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } /// Returns DoPersist if anything changed, otherwise either SkipPersistNoEvents or an Err. + #[rustfmt::skip] fn internal_channel_update(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelUpdate) -> Result { let (chan_counterparty_node_id, chan_id) = match self.short_to_chan_info.read().unwrap().get(&msg.contents.short_channel_id) { Some((cp_id, chan_id)) => (cp_id.clone(), chan_id.clone()), @@ -9447,6 +9677,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ Ok(NotifyOption::DoPersist) } + #[rustfmt::skip] fn internal_channel_reestablish(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReestablish) -> Result { let need_lnd_workaround = { let per_peer_state = self.per_peer_state.read().unwrap(); @@ -9549,6 +9780,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ /// Handle incoming splice request, transition channel to splice-pending (unless some check fails). #[cfg(splicing)] + #[rustfmt::skip] fn internal_splice_init(&self, counterparty_node_id: &PublicKey, msg: &msgs::SpliceInit) -> Result<(), MsgHandleErrInternal> { let per_peer_state = self.per_peer_state.read().unwrap(); let peer_state_mutex = per_peer_state.get(counterparty_node_id) @@ -9588,6 +9820,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ /// Handle incoming splice request ack, transition channel to splice-pending (unless some check fails). #[cfg(splicing)] + #[rustfmt::skip] fn internal_splice_ack(&self, counterparty_node_id: &PublicKey, msg: &msgs::SpliceAck) -> Result<(), MsgHandleErrInternal> { let per_peer_state = self.per_peer_state.read().unwrap(); let peer_state_mutex = per_peer_state.get(counterparty_node_id) @@ -9623,6 +9856,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } /// Process pending events from the [`chain::Watch`], returning whether any events were processed. + #[rustfmt::skip] fn process_pending_monitor_events(&self) -> bool { debug_assert!(self.total_consistency_lock.try_write().is_err()); // Caller holds read lock @@ -9710,6 +9944,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ /// Check the holding cell in each channel and free any pending HTLCs in them if possible. /// Returns whether there were any updates such as if pending HTLCs were freed or a monitor /// update was applied. + #[rustfmt::skip] fn check_free_holding_cells(&self) -> bool { let mut has_monitor_update = false; let mut failed_htlcs = Vec::new(); @@ -9764,6 +9999,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ /// attempted in every channel, or in the specifically provided channel. /// /// [`ChannelSigner`]: crate::sign::ChannelSigner + #[rustfmt::skip] pub fn signer_unblocked(&self, channel_opt: Option<(PublicKey, ChannelId)>) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); @@ -9886,6 +10122,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ /// Check whether any channels have finished removing all pending updates after a shutdown /// exchange and can now send a closing_signed. /// Returns whether any closing_signed messages were generated. + #[rustfmt::skip] fn maybe_generate_initial_closing_signed(&self) -> bool { let mut handle_errors: Vec<(PublicKey, Result<(), _>)> = Vec::new(); let mut has_update = false; @@ -9954,6 +10191,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ has_update } + #[rustfmt::skip] fn maybe_send_stfu(&self) { let per_peer_state = self.per_peer_state.read().unwrap(); for (counterparty_node_id, peer_state_mutex) in per_peer_state.iter() { @@ -9983,6 +10221,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } #[cfg(any(test, fuzzing))] + #[rustfmt::skip] pub fn maybe_propose_quiescence(&self, counterparty_node_id: &PublicKey, channel_id: &ChannelId) -> Result<(), APIError> { let mut result = Ok(()); PersistenceNotifierGuard::optionally_notify(self, || { @@ -10041,6 +10280,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ } #[cfg(any(test, fuzzing))] + #[rustfmt::skip] pub fn exit_quiescence(&self, counterparty_node_id: &PublicKey, channel_id: &ChannelId) -> Result { let per_peer_state = self.per_peer_state.read().unwrap(); let peer_state_mutex = per_peer_state.get(counterparty_node_id) @@ -10070,6 +10310,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ /// storing any additional state. It achieves this by including a [`PaymentSecret`] in the /// invoice which it uses to verify that the invoice has not expired and the payment amount is /// sufficient, reproducing the [`PaymentPreimage`] if applicable. + #[rustfmt::skip] pub fn create_bolt11_invoice( &self, params: Bolt11InvoiceParameters, ) -> Result> { @@ -10313,7 +10554,17 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => { } } } -impl ChannelManager +impl< + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > ChannelManager where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -10344,6 +10595,7 @@ where /// [`Offer`] plus the returned [`Nonce`], and provide the static invoice to the /// aforementioned always-online node. #[cfg(async_payments)] + #[rustfmt::skip] pub fn create_async_receive_offer_builder( &self, message_paths_to_always_online_node: Vec ) -> Result<(OfferBuilder, Nonce), Bolt12SemanticError> { @@ -10354,6 +10606,7 @@ where /// created via [`Self::create_async_receive_offer_builder`]. If `relative_expiry` is unset, the /// invoice's expiry will default to [`STATIC_INVOICE_DEFAULT_RELATIVE_EXPIRY`]. #[cfg(async_payments)] + #[rustfmt::skip] pub fn create_static_invoice_builder<'a>( &self, offer: &'a Offer, offer_nonce: Nonce, relative_expiry: Option ) -> Result, Bolt12SemanticError> { @@ -10434,6 +10687,7 @@ where /// [`BlindedMessagePath`]: crate::blinded_path::message::BlindedMessagePath /// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths /// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments + #[rustfmt::skip] pub fn pay_for_offer( &self, offer: &Offer, quantity: Option, amount_msats: Option, payer_note: Option, payment_id: PaymentId, retry_strategy: Retry, @@ -10455,6 +10709,7 @@ where }) } + #[rustfmt::skip] fn pay_for_offer_intern Result<(), Bolt12SemanticError>>( &self, offer: &Offer, quantity: Option, amount_msats: Option, payer_note: Option, payment_id: PaymentId, @@ -10518,6 +10773,7 @@ where /// /// [`BlindedPaymentPath`]: crate::blinded_path::payment::BlindedPaymentPath /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice + #[rustfmt::skip] pub fn request_refund_payment( &self, refund: &Refund ) -> Result { @@ -10597,6 +10853,7 @@ where /// [`PaymentFailureReason::UserAbandoned`]: crate::events::PaymentFailureReason::UserAbandoned /// [`PaymentFailureReason::InvoiceRequestRejected`]: crate::events::PaymentFailureReason::InvoiceRequestRejected #[cfg(feature = "dnssec")] + #[rustfmt::skip] pub fn pay_for_offer_from_human_readable_name( &self, name: HumanReadableName, amount_msats: u64, payment_id: PaymentId, payer_note: Option, retry_strategy: Retry, route_params_config: RouteParametersConfig, @@ -10645,6 +10902,7 @@ where /// [`PaymentClaimable::purpose`]: events::Event::PaymentClaimable::purpose /// [`PaymentPurpose::preimage`]: events::PaymentPurpose::preimage /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash + #[rustfmt::skip] pub fn create_inbound_payment(&self, min_value_msat: Option, invoice_expiry_delta_secs: u32, min_final_cltv_expiry_delta: Option) -> Result<(PaymentHash, PaymentSecret), ()> { inbound_payment::create(&self.inbound_payment_key, min_value_msat, invoice_expiry_delta_secs, @@ -10698,6 +10956,7 @@ where /// /// [`create_inbound_payment`]: Self::create_inbound_payment /// [`PaymentClaimable`]: events::Event::PaymentClaimable + #[rustfmt::skip] pub fn create_inbound_payment_for_hash(&self, payment_hash: PaymentHash, min_value_msat: Option, invoice_expiry_delta_secs: u32, min_final_cltv_expiry: Option) -> Result { inbound_payment::create_from_hash(&self.inbound_payment_key, min_value_msat, payment_hash, @@ -10709,11 +10968,13 @@ where /// previously returned from [`create_inbound_payment`]. /// /// [`create_inbound_payment`]: Self::create_inbound_payment + #[rustfmt::skip] pub fn get_payment_preimage(&self, payment_hash: PaymentHash, payment_secret: PaymentSecret) -> Result { inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key) } #[cfg(any(test, async_payments))] + #[rustfmt::skip] pub(super) fn duration_since_epoch(&self) -> Duration { #[cfg(not(feature = "std"))] let now = Duration::from_secs( @@ -10727,6 +10988,7 @@ where now } + #[rustfmt::skip] fn get_peers_for_blinded_path(&self) -> Vec { self.per_peer_state.read().unwrap() .iter() @@ -10747,6 +11009,7 @@ where #[cfg(all(test, async_payments))] /// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to /// [`Router::create_blinded_payment_paths`]. + #[rustfmt::skip] pub(super) fn test_create_blinded_payment_paths( &self, amount_msats: Option, payment_secret: PaymentSecret, payment_context: PaymentContext, relative_expiry_seconds: u32 @@ -10763,6 +11026,7 @@ where /// are used when constructing the phantom invoice's route hints. /// /// [phantom node payments]: crate::sign::PhantomKeysManager + #[rustfmt::skip] pub fn get_phantom_scid(&self) -> u64 { let best_block_height = self.best_block.read().unwrap().height; let short_to_chan_info = self.short_to_chan_info.read().unwrap(); @@ -10793,6 +11057,7 @@ where /// /// Note that this method is not guaranteed to return unique values, you may need to call it a few /// times to get a unique scid. + #[rustfmt::skip] pub fn get_intercept_scid(&self) -> u64 { let best_block_height = self.best_block.read().unwrap().height; let short_to_chan_info = self.short_to_chan_info.read().unwrap(); @@ -10826,6 +11091,7 @@ where } #[cfg(any(test, feature = "_test_utils"))] + #[rustfmt::skip] pub fn get_and_clear_pending_events(&self) -> Vec { let events = core::cell::RefCell::new(Vec::new()); let event_handler = |event: events::Event| Ok(events.borrow_mut().push(event)); @@ -10893,6 +11159,7 @@ where /// [`Event`] being handled) completes, this should be called to restore the channel to normal /// operation. It will double-check that nothing *else* is also blocking the same channel from /// making progress and then let any blocked [`ChannelMonitorUpdate`]s fly. + #[rustfmt::skip] fn handle_monitor_update_release(&self, counterparty_node_id: PublicKey, channel_funding_outpoint: OutPoint, channel_id: ChannelId, mut completed_blocker: Option) { @@ -10953,6 +11220,7 @@ where } } + #[rustfmt::skip] fn handle_post_event_actions(&self, actions: Vec) { for action in actions { match action { @@ -10969,15 +11237,28 @@ where /// using the given event handler. /// /// See the trait-level documentation of [`EventsProvider`] for requirements. - pub async fn process_pending_events_async>, H: Fn(Event) -> Future>( - &self, handler: H + pub async fn process_pending_events_async< + Future: core::future::Future>, + H: Fn(Event) -> Future, + >( + &self, handler: H, ) { let mut ev; process_events_body!(self, ev, { handler(ev).await }); } } -impl BaseMessageHandler for ChannelManager +impl< + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > BaseMessageHandler for ChannelManager where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -10997,6 +11278,7 @@ where provided_init_features(&self.default_configuration) } + #[rustfmt::skip] fn peer_disconnected(&self, counterparty_node_id: PublicKey) { let _persistence_guard = PersistenceNotifierGuard::optionally_notify( self, || NotifyOption::SkipPersistHandleEvents); @@ -11099,6 +11381,7 @@ where } } + #[rustfmt::skip] fn peer_connected(&self, counterparty_node_id: PublicKey, init_msg: &msgs::Init, inbound: bool) -> Result<(), ()> { let logger = WithContext::from(&self.logger, Some(counterparty_node_id), None, None); if !init_msg.features.supports_static_remote_key() { @@ -11266,7 +11549,17 @@ where } } -impl EventsProvider for ChannelManager +impl< + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > EventsProvider for ChannelManager where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -11282,13 +11575,26 @@ where /// /// An [`EventHandler`] may safely call back to the provider in order to handle an event. /// However, it must not call [`Writeable::write`] as doing so would result in a deadlock. - fn process_pending_events(&self, handler: H) where H::Target: EventHandler { + fn process_pending_events(&self, handler: H) + where + H::Target: EventHandler, + { let mut ev; process_events_body!(self, ev, handler.handle_event(ev)); } } -impl chain::Listen for ChannelManager +impl< + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > chain::Listen for ChannelManager where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -11313,6 +11619,7 @@ where self.best_block_updated(header, height); } + #[rustfmt::skip] fn block_disconnected(&self, header: &Header, height: u32) { let _persistence_guard = PersistenceNotifierGuard::optionally_notify_skipping_background_events( @@ -11331,7 +11638,17 @@ where } } -impl chain::Confirm for ChannelManager +impl< + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > chain::Confirm for ChannelManager where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -11343,6 +11660,7 @@ where MR::Target: MessageRouter, L::Target: Logger, { + #[rustfmt::skip] fn transactions_confirmed(&self, header: &Header, txdata: &TransactionData, height: u32) { // Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called // during initialization prior to the chain_monitor being fully configured in some cases. @@ -11364,6 +11682,7 @@ where } } + #[rustfmt::skip] fn best_block_updated(&self, header: &Header, height: u32) { // Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called // during initialization prior to the chain_monitor being fully configured in some cases. @@ -11431,6 +11750,7 @@ where self.flow.best_block_updated(header, height); } + #[rustfmt::skip] fn get_relevant_txids(&self) -> Vec<(Txid, u32, Option)> { let mut res = Vec::with_capacity(self.short_to_chan_info.read().unwrap().len()); for (_cp_id, peer_state_mutex) in self.per_peer_state.read().unwrap().iter() { @@ -11448,6 +11768,7 @@ where res } + #[rustfmt::skip] fn transaction_unconfirmed(&self, txid: &Txid) { let _persistence_guard = PersistenceNotifierGuard::optionally_notify_skipping_background_events( @@ -11462,7 +11783,17 @@ where } } -impl ChannelManager +impl< + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > ChannelManager where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -11477,6 +11808,7 @@ where /// Calls a function which handles an on-chain event (blocks dis/connected, transactions /// un/confirmed, etc) on each channel, handling any resulting errors or messages generated by /// the function. + #[rustfmt::skip] fn do_chain_event) -> Result<(Option, Vec<(HTLCSource, PaymentHash)>, Option), ClosureReason>> (&self, height_opt: Option, f: FN) { // Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called @@ -11745,8 +12077,17 @@ where } } -impl - ChannelMessageHandler for ChannelManager +impl< + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > ChannelMessageHandler for ChannelManager where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -11758,6 +12099,7 @@ where MR::Target: MessageRouter, L::Target: Logger, { + #[rustfmt::skip] fn handle_open_channel(&self, counterparty_node_id: PublicKey, msg: &msgs::OpenChannel) { // Note that we never need to persist the updated ChannelManager for an inbound // open_channel message - pre-funded channels are never written so there should be no @@ -11776,6 +12118,7 @@ where }); } + #[rustfmt::skip] fn handle_open_channel_v2(&self, counterparty_node_id: PublicKey, msg: &msgs::OpenChannelV2) { if !self.init_features().supports_dual_fund() { let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( @@ -11800,6 +12143,7 @@ where }); } + #[rustfmt::skip] fn handle_accept_channel(&self, counterparty_node_id: PublicKey, msg: &msgs::AcceptChannel) { // Note that we never need to persist the updated ChannelManager for an inbound // accept_channel message - pre-funded channels are never written so there should be no @@ -11810,27 +12154,32 @@ where }); } + #[rustfmt::skip] fn handle_accept_channel_v2(&self, counterparty_node_id: PublicKey, msg: &msgs::AcceptChannelV2) { let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( "Dual-funded channels not supported".to_owned(), msg.common_fields.temporary_channel_id.clone())), counterparty_node_id); } + #[rustfmt::skip] fn handle_funding_created(&self, counterparty_node_id: PublicKey, msg: &msgs::FundingCreated) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); let _ = handle_error!(self, self.internal_funding_created(&counterparty_node_id, msg), counterparty_node_id); } + #[rustfmt::skip] fn handle_funding_signed(&self, counterparty_node_id: PublicKey, msg: &msgs::FundingSigned) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); let _ = handle_error!(self, self.internal_funding_signed(&counterparty_node_id, msg), counterparty_node_id); } + #[rustfmt::skip] fn handle_peer_storage(&self, counterparty_node_id: PublicKey, msg: msgs::PeerStorage) { let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || NotifyOption::SkipPersistNoEvents); let _ = handle_error!(self, self.internal_peer_storage(counterparty_node_id, msg), counterparty_node_id); } + #[rustfmt::skip] fn handle_peer_storage_retrieval(&self, counterparty_node_id: PublicKey, msg: msgs::PeerStorageRetrieval) { let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || NotifyOption::SkipPersistNoEvents); let _ = handle_error!(self, self.internal_peer_storage_retrieval(counterparty_node_id, msg), counterparty_node_id); @@ -11852,6 +12201,7 @@ where }); } + #[rustfmt::skip] fn handle_stfu(&self, counterparty_node_id: PublicKey, msg: &msgs::Stfu) { let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || { let res = self.internal_stfu(&counterparty_node_id, msg); @@ -11898,17 +12248,20 @@ where } #[cfg(splicing)] + #[rustfmt::skip] fn handle_splice_locked(&self, counterparty_node_id: PublicKey, msg: &msgs::SpliceLocked) { let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( "Splicing not supported (splice_locked)".to_owned(), msg.channel_id)), counterparty_node_id); } + #[rustfmt::skip] fn handle_shutdown(&self, counterparty_node_id: PublicKey, msg: &msgs::Shutdown) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); let _ = handle_error!(self, self.internal_shutdown(&counterparty_node_id, msg), counterparty_node_id); } + #[rustfmt::skip] fn handle_closing_signed(&self, counterparty_node_id: PublicKey, msg: &msgs::ClosingSigned) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); let _ = handle_error!(self, self.internal_closing_signed(&counterparty_node_id, msg), counterparty_node_id); @@ -11930,6 +12283,7 @@ where }); } + #[rustfmt::skip] fn handle_update_fulfill_htlc(&self, counterparty_node_id: PublicKey, msg: &msgs::UpdateFulfillHTLC) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); let _ = handle_error!(self, self.internal_update_fulfill_htlc(&counterparty_node_id, msg), counterparty_node_id); @@ -11951,7 +12305,9 @@ where }); } - fn handle_update_fail_malformed_htlc(&self, counterparty_node_id: PublicKey, msg: &msgs::UpdateFailMalformedHTLC) { + fn handle_update_fail_malformed_htlc( + &self, counterparty_node_id: PublicKey, msg: &msgs::UpdateFailMalformedHTLC, + ) { // Note that we never need to persist the updated ChannelManager for an inbound // update_fail_malformed_htlc message - the message itself doesn't change our channel state // only the `commitment_signed` message afterwards will. @@ -11967,16 +12323,19 @@ where }); } + #[rustfmt::skip] fn handle_commitment_signed(&self, counterparty_node_id: PublicKey, msg: &msgs::CommitmentSigned) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); let _ = handle_error!(self, self.internal_commitment_signed(&counterparty_node_id, msg), counterparty_node_id); } + #[rustfmt::skip] fn handle_commitment_signed_batch(&self, counterparty_node_id: PublicKey, channel_id: ChannelId, batch: BTreeMap) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); let _ = handle_error!(self, self.internal_commitment_signed_batch(&counterparty_node_id, channel_id, &batch), counterparty_node_id); } + #[rustfmt::skip] fn handle_revoke_and_ack(&self, counterparty_node_id: PublicKey, msg: &msgs::RevokeAndACK) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); let _ = handle_error!(self, self.internal_revoke_and_ack(&counterparty_node_id, msg), counterparty_node_id); @@ -11998,11 +12357,13 @@ where }); } + #[rustfmt::skip] fn handle_announcement_signatures(&self, counterparty_node_id: PublicKey, msg: &msgs::AnnouncementSignatures) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); let _ = handle_error!(self, self.internal_announcement_signatures(&counterparty_node_id, msg), counterparty_node_id); } + #[rustfmt::skip] fn handle_channel_update(&self, counterparty_node_id: PublicKey, msg: &msgs::ChannelUpdate) { PersistenceNotifierGuard::optionally_notify(self, || { if let Ok(persist) = handle_error!(self, self.internal_channel_update(&counterparty_node_id, msg), counterparty_node_id) { @@ -12013,7 +12374,9 @@ where }); } - fn handle_channel_reestablish(&self, counterparty_node_id: PublicKey, msg: &msgs::ChannelReestablish) { + fn handle_channel_reestablish( + &self, counterparty_node_id: PublicKey, msg: &msgs::ChannelReestablish, + ) { let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || { let res = self.internal_channel_reestablish(&counterparty_node_id, msg); let persist = match &res { @@ -12026,6 +12389,7 @@ where }); } + #[rustfmt::skip] fn handle_error(&self, counterparty_node_id: PublicKey, msg: &msgs::ErrorMessage) { match &msg.data as &str { "cannot co-op close channel w/ active htlcs"| @@ -12138,6 +12502,7 @@ where Some(vec![self.chain_hash]) } + #[rustfmt::skip] fn handle_tx_add_input(&self, counterparty_node_id: PublicKey, msg: &msgs::TxAddInput) { // Note that we never need to persist the updated ChannelManager for an inbound // tx_add_input message - interactive transaction construction does not need to @@ -12148,6 +12513,7 @@ where }); } + #[rustfmt::skip] fn handle_tx_add_output(&self, counterparty_node_id: PublicKey, msg: &msgs::TxAddOutput) { // Note that we never need to persist the updated ChannelManager for an inbound // tx_add_output message - interactive transaction construction does not need to @@ -12158,6 +12524,7 @@ where }); } + #[rustfmt::skip] fn handle_tx_remove_input(&self, counterparty_node_id: PublicKey, msg: &msgs::TxRemoveInput) { // Note that we never need to persist the updated ChannelManager for an inbound // tx_remove_input message - interactive transaction construction does not need to @@ -12168,6 +12535,7 @@ where }); } + #[rustfmt::skip] fn handle_tx_remove_output(&self, counterparty_node_id: PublicKey, msg: &msgs::TxRemoveOutput) { // Note that we never need to persist the updated ChannelManager for an inbound // tx_remove_output message - interactive transaction construction does not need to @@ -12178,6 +12546,7 @@ where }); } + #[rustfmt::skip] fn handle_tx_complete(&self, counterparty_node_id: PublicKey, msg: &msgs::TxComplete) { // Note that we never need to persist the updated ChannelManager for an inbound // tx_complete message - interactive transaction construction does not need to @@ -12188,23 +12557,27 @@ where }); } + #[rustfmt::skip] fn handle_tx_signatures(&self, counterparty_node_id: PublicKey, msg: &msgs::TxSignatures) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); let _ = handle_error!(self, self.internal_tx_signatures(&counterparty_node_id, msg), counterparty_node_id); } + #[rustfmt::skip] fn handle_tx_init_rbf(&self, counterparty_node_id: PublicKey, msg: &msgs::TxInitRbf) { let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( "Dual-funded channels not supported".to_owned(), msg.channel_id.clone())), counterparty_node_id); } + #[rustfmt::skip] fn handle_tx_ack_rbf(&self, counterparty_node_id: PublicKey, msg: &msgs::TxAckRbf) { let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( "Dual-funded channels not supported".to_owned(), msg.channel_id.clone())), counterparty_node_id); } + #[rustfmt::skip] fn handle_tx_abort(&self, counterparty_node_id: PublicKey, msg: &msgs::TxAbort) { // Note that we never need to persist the updated ChannelManager for an inbound // tx_abort message - interactive transaction construction does not need to @@ -12215,6 +12588,7 @@ where }); } + #[rustfmt::skip] fn message_received(&self) { for (payment_id, retryable_invoice_request) in self .pending_outbound_payments @@ -12231,8 +12605,17 @@ where } } -impl -OffersMessageHandler for ChannelManager +impl< + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > OffersMessageHandler for ChannelManager where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -12244,6 +12627,7 @@ where MR::Target: MessageRouter, L::Target: Logger, { + #[rustfmt::skip] fn handle_message( &self, message: OffersMessage, context: Option, responder: Option, ) -> Option<(OffersMessage, ResponseInstruction)> { @@ -12400,8 +12784,17 @@ where } } -impl -AsyncPaymentsMessageHandler for ChannelManager +impl< + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > AsyncPaymentsMessageHandler for ChannelManager where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -12413,6 +12806,7 @@ where MR::Target: MessageRouter, L::Target: Logger, { + #[rustfmt::skip] fn handle_held_htlc_available( &self, _message: HeldHtlcAvailable, _context: AsyncPaymentsContext, _responder: Option @@ -12425,6 +12819,7 @@ where return None } + #[rustfmt::skip] fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) { #[cfg(async_payments)] { if let Ok(payment_id) = self.flow.verify_outbound_async_payment_context(_context) { @@ -12443,8 +12838,17 @@ where } #[cfg(feature = "dnssec")] -impl -DNSResolverMessageHandler for ChannelManager +impl< + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > DNSResolverMessageHandler for ChannelManager where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -12462,6 +12866,7 @@ where None } + #[rustfmt::skip] fn handle_dnssec_proof(&self, message: DNSSECProof, context: DNSResolverContext) { let offer_opt = self.flow.hrn_resolver.handle_dnssec_proof_for_offer(message, context); #[cfg_attr(not(feature = "_test_utils"), allow(unused_mut))] @@ -12506,8 +12911,17 @@ where } } -impl -NodeIdLookUp for ChannelManager +impl< + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > NodeIdLookUp for ChannelManager where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -12654,8 +13068,8 @@ impl_writeable_tlv_based!(PendingHTLCInfo, { (10, skimmed_fee_msat, option), }); - impl Writeable for HTLCFailureMsg { + #[rustfmt::skip] fn write(&self, writer: &mut W) -> Result<(), io::Error> { match self { HTLCFailureMsg::Relay(msgs::UpdateFailHTLC { channel_id, htlc_id, reason, attribution_data }) => { @@ -12683,6 +13097,7 @@ impl Writeable for HTLCFailureMsg { } impl Readable for HTLCFailureMsg { + #[rustfmt::skip] fn read(reader: &mut R) -> Result { let id: u8 = Readable::read(reader)?; match id { @@ -12753,6 +13168,7 @@ impl_writeable_tlv_based!(HTLCPreviousHopData, { }); impl Writeable for ClaimableHTLC { + #[rustfmt::skip] fn write(&self, writer: &mut W) -> Result<(), io::Error> { let (payment_data, keysend_preimage) = match &self.onion_payload { OnionPayload::Invoice { _legacy_hop_data } => { @@ -12776,6 +13192,7 @@ impl Writeable for ClaimableHTLC { } impl Readable for ClaimableHTLC { + #[rustfmt::skip] fn read(reader: &mut R) -> Result { _init_and_read_len_prefixed_tlv_fields!(reader, { (0, prev_hop, required), @@ -12825,6 +13242,7 @@ impl Readable for ClaimableHTLC { } impl Readable for HTLCSource { + #[rustfmt::skip] fn read(reader: &mut R) -> Result { let id: u8 = Readable::read(reader)?; match id { @@ -12876,6 +13294,7 @@ impl Readable for HTLCSource { } impl Writeable for HTLCSource { + #[rustfmt::skip] fn write(&self, writer: &mut W) -> Result<(), crate::io::Error> { match self { HTLCSource::OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id, bolt12_invoice } => { @@ -12947,6 +13366,7 @@ impl Writeable for HTLCForwardInfo { } impl Readable for HTLCForwardInfo { + #[rustfmt::skip] fn read(r: &mut R) -> Result { let id: u8 = Readable::read(r)?; Ok(match id { @@ -12991,7 +13411,17 @@ impl_writeable_tlv_based!(PendingInboundPayment, { (8, min_value_msat, required), }); -impl Writeable for ChannelManager +impl< + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > Writeable for ChannelManager where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -13003,6 +13433,7 @@ where MR::Target: MessageRouter, L::Target: Logger, { + #[rustfmt::skip] fn write(&self, writer: &mut W) -> Result<(), io::Error> { let _consistency_lock = self.total_consistency_lock.write().unwrap(); @@ -13234,6 +13665,7 @@ where } impl Writeable for VecDeque<(Event, Option)> { + #[rustfmt::skip] fn write(&self, w: &mut W) -> Result<(), io::Error> { (self.len() as u64).write(w)?; for (event, action) in self.iter() { @@ -13255,6 +13687,7 @@ impl Writeable for VecDeque<(Event, Option)> { } } impl Readable for VecDeque<(Event, Option)> { + #[rustfmt::skip] fn read(reader: &mut R) -> Result { let len: u64 = Readable::read(reader)?; const MAX_ALLOC_SIZE: u64 = 1024 * 16; @@ -13309,8 +13742,18 @@ impl Readable for VecDeque<(Event, Option)> { /// which you've already broadcasted the transaction. /// /// [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor -pub struct ChannelManagerReadArgs<'a, M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref> -where +pub struct ChannelManagerReadArgs< + 'a, + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, +> where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, ES::Target: EntropySource, @@ -13375,11 +13818,22 @@ where /// this struct. /// /// This is not exported to bindings users because we have no HashMap bindings - pub channel_monitors: HashMap::EcdsaSigner>>, + pub channel_monitors: + HashMap::EcdsaSigner>>, } -impl<'a, M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref> - ChannelManagerReadArgs<'a, M, T, ES, NS, SP, F, R, MR, L> +impl< + 'a, + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > ChannelManagerReadArgs<'a, M, T, ES, NS, SP, F, R, MR, L> where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -13394,6 +13848,7 @@ where /// Simple utility function to create a ChannelManagerReadArgs which creates the monitor /// HashMap for you. This is primarily useful for C bindings where it is not practical to /// populate a HashMap directly from C. + #[rustfmt::skip] pub fn new( entropy_source: ES, node_signer: NS, signer_provider: SP, fee_estimator: F, chain_monitor: M, tx_broadcaster: T, router: R, message_router: MR, logger: L, @@ -13412,8 +13867,19 @@ where // Implement ReadableArgs for an Arc'd ChannelManager to make it a bit easier to work with the // SipmleArcChannelManager type: -impl<'a, M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref> - ReadableArgs> for (BlockHash, Arc>) +impl< + 'a, + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > ReadableArgs> + for (BlockHash, Arc>) where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -13425,14 +13891,26 @@ where MR::Target: MessageRouter, L::Target: Logger, { + #[rustfmt::skip] fn read(reader: &mut Reader, args: ChannelManagerReadArgs<'a, M, T, ES, NS, SP, F, R, MR, L>) -> Result { let (blockhash, chan_manager) = <(BlockHash, ChannelManager)>::read(reader, args)?; Ok((blockhash, Arc::new(chan_manager))) } } -impl<'a, M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref> - ReadableArgs> for (BlockHash, ChannelManager) +impl< + 'a, + M: Deref, + T: Deref, + ES: Deref, + NS: Deref, + SP: Deref, + F: Deref, + R: Deref, + MR: Deref, + L: Deref, + > ReadableArgs> + for (BlockHash, ChannelManager) where M::Target: chain::Watch<::EcdsaSigner>, T::Target: BroadcasterInterface, @@ -13444,6 +13922,7 @@ where MR::Target: MessageRouter, L::Target: Logger, { + #[rustfmt::skip] fn read(reader: &mut Reader, mut args: ChannelManagerReadArgs<'a, M, T, ES, NS, SP, F, R, MR, L>) -> Result { let _ver = read_ver_prefix!(reader, SERIALIZATION_VERSION); @@ -14713,27 +15192,34 @@ where #[cfg(test)] mod tests { - use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey}; - use bitcoin::secp256k1::ecdh::SharedSecret; - use core::sync::atomic::Ordering; - use crate::events::{Event, HTLCHandlingFailureType, ClosureReason}; - use crate::ln::onion_utils::AttributionData; - use crate::ln::types::ChannelId; - use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret}; - use crate::ln::channelmanager::{create_recv_pending_htlc_info, inbound_payment, ChannelConfigOverrides, HTLCForwardInfo, InterceptId, PaymentId, RecipientOnionFields}; + use crate::events::{ClosureReason, Event, HTLCHandlingFailureType}; + use crate::ln::channelmanager::{ + create_recv_pending_htlc_info, inbound_payment, ChannelConfigOverrides, HTLCForwardInfo, + InterceptId, PaymentId, RecipientOnionFields, + }; use crate::ln::functional_test_utils::*; - use crate::ln::msgs::{self, BaseMessageHandler, ChannelMessageHandler, AcceptChannel, ErrorAction, MessageSendEvent}; + use crate::ln::msgs::{ + self, AcceptChannel, BaseMessageHandler, ChannelMessageHandler, ErrorAction, + MessageSendEvent, + }; + use crate::ln::onion_utils::AttributionData; use crate::ln::onion_utils::{self, LocalHTLCFailureReason}; use crate::ln::outbound_payment::Retry; + use crate::ln::types::ChannelId; use crate::prelude::*; - use crate::routing::router::{PaymentParameters, RouteParameters, find_route}; + use crate::routing::router::{find_route, PaymentParameters, RouteParameters}; + use crate::sign::EntropySource; + use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret}; + use crate::util::config::{ChannelConfig, ChannelConfigUpdate, ChannelHandshakeConfigUpdate}; use crate::util::errors::APIError; use crate::util::ser::Writeable; use crate::util::test_utils; - use crate::util::config::{ChannelConfig, ChannelConfigUpdate, ChannelHandshakeConfigUpdate}; - use crate::sign::EntropySource; + use bitcoin::secp256k1::ecdh::SharedSecret; + use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey}; + use core::sync::atomic::Ordering; #[test] + #[rustfmt::skip] fn test_notify_limits() { // Check that a few cases which don't require the persistence of a new ChannelManager, // indeed, do not cause the persistence of a new ChannelManager. @@ -14814,6 +15300,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_keysend_dup_hash_partial_mpp() { // Test that a keysend payment with a duplicate hash to an existing partial MPP payment fails as // expected. @@ -14933,6 +15420,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_peer_storage() { let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); @@ -14997,6 +15485,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_keysend_dup_payment_hash() { // (1): Test that a keysend payment with a duplicate payment hash to an existing pending // outbound regular payment fails as expected. @@ -15145,6 +15634,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_keysend_hash_mismatch() { // Test that if we receive a keysend `update_add_htlc` msg, we fail as expected if the keysend // preimage doesn't match the msg's payment hash. @@ -15193,6 +15683,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_multi_hop_missing_secret() { let chanmon_cfgs = create_chanmon_cfgs(4); let node_cfgs = create_node_cfgs(4, &chanmon_cfgs); @@ -15230,6 +15721,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_channel_update_cached() { let chanmon_cfgs = create_chanmon_cfgs(3); let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); @@ -15285,6 +15777,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_drop_disconnected_peers_when_removing_channels() { let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); @@ -15319,6 +15812,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_drop_peers_when_removing_unfunded_channels() { let chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); @@ -15344,6 +15838,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn bad_inbound_payment_hash() { // Add coverage for checking that a user-provided payment hash matches the payment secret. let chanmon_cfgs = create_chanmon_cfgs(2); @@ -15372,16 +15867,20 @@ mod tests { assert!(inbound_payment::verify(payment_hash, &payment_data, nodes[0].node.highest_seen_timestamp.load(Ordering::Acquire) as u64, &nodes[0].node.inbound_payment_key, &nodes[0].logger).is_ok()); } - fn check_not_connected_to_peer_error(res_err: Result, expected_public_key: PublicKey) { + fn check_not_connected_to_peer_error( + res_err: Result, expected_public_key: PublicKey, + ) { let expected_message = format!("Not connected to node: {}", expected_public_key); check_api_error_message(expected_message, res_err) } + #[rustfmt::skip] fn check_unkown_peer_error(res_err: Result, expected_public_key: PublicKey) { let expected_message = format!("Can't find a peer matching the passed counterparty node_id {}", expected_public_key); check_api_error_message(expected_message, res_err) } + #[rustfmt::skip] fn check_channel_unavailable_error(res_err: Result, expected_channel_id: ChannelId, peer_node_id: PublicKey) { let expected_message = format!("Channel with id {} not found for the passed counterparty node_id {}", expected_channel_id, peer_node_id); check_api_error_message(expected_message, res_err) @@ -15406,6 +15905,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_api_calls_with_unkown_counterparty_node() { // Tests that our API functions that expects a `counterparty_node_id` as input, behaves as // expected if the `counterparty_node_id` is an unkown peer in the @@ -15438,6 +15938,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_api_calls_with_unavailable_channel() { // Tests that our API functions that expects a `counterparty_node_id` and a `channel_id` // as input, behaves as expected if the `counterparty_node_id` is a known peer in the @@ -15469,6 +15970,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_connection_limiting() { // Test that we limit un-channel'd peers and un-funded channels properly. let chanmon_cfgs = create_chanmon_cfgs(2); @@ -15584,6 +16086,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_outbound_chans_unlimited() { // Test that we never refuse an outbound channel even if a peer is unfuned-channel-limited let chanmon_cfgs = create_chanmon_cfgs(2); @@ -15619,6 +16122,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_0conf_limiting() { // Tests that we properly limit inbound channels when we have the manual-channel-acceptance // flag set and (sometimes) accept channels as 0conf. @@ -15688,6 +16192,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn reject_excessively_underpaying_htlcs() { let chanmon_cfg = create_chanmon_cfgs(1); let node_cfg = create_node_cfgs(1, &chanmon_cfg); @@ -15742,6 +16247,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_final_incorrect_cltv(){ let chanmon_cfg = create_chanmon_cfgs(1); let node_cfg = create_node_cfgs(1, &chanmon_cfg); @@ -15798,6 +16304,7 @@ mod tests { assert_eq!(accept_message.channel_reserve_satoshis, 2_000); } + #[rustfmt::skip] fn test_inbound_anchors_manual_acceptance_with_override(config_overrides: Option) -> AcceptChannel { // Tests that we properly limit inbound channels when we have the manual-channel-acceptance // flag set and (sometimes) accept channels as 0conf. @@ -15842,6 +16349,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_anchors_zero_fee_htlc_tx_fallback() { // Tests that if both nodes support anchors, but the remote node does not want to accept // anchor channels at the moment, an error it sent to the local node such that it can retry @@ -15880,6 +16388,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_update_channel_config() { let chanmon_cfg = create_chanmon_cfgs(2); let node_cfg = create_node_cfgs(2, &chanmon_cfg); @@ -15957,6 +16466,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_payment_display() { let payment_id = PaymentId([42; 32]); assert_eq!(format!("{}", &payment_id), "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a"); @@ -15967,6 +16477,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_trigger_lnd_force_close() { let chanmon_cfg = create_chanmon_cfgs(2); let node_cfg = create_node_cfgs(2, &chanmon_cfg); @@ -16029,6 +16540,7 @@ mod tests { } #[test] + #[rustfmt::skip] fn test_malformed_forward_htlcs_ser() { // Ensure that `HTLCForwardInfo::FailMalformedHTLC`s are (de)serialized properly. let chanmon_cfg = create_chanmon_cfgs(1); @@ -16092,52 +16604,72 @@ mod tests { #[cfg(ldk_bench)] pub mod bench { - use crate::chain::Listen; use crate::chain::chainmonitor::{ChainMonitor, Persist}; - use crate::sign::{KeysManager, InMemorySigner}; + use crate::chain::Listen; use crate::events::Event; - use crate::ln::channelmanager::{BestBlock, ChainParameters, ChannelManager, PaymentHash, PaymentPreimage, PaymentId, RecipientOnionFields, Retry}; + use crate::ln::channelmanager::{ + BestBlock, ChainParameters, ChannelManager, PaymentHash, PaymentId, PaymentPreimage, + RecipientOnionFields, Retry, + }; use crate::ln::functional_test_utils::*; use crate::ln::msgs::{BaseMessageHandler, ChannelMessageHandler, Init, MessageSendEvent}; use crate::routing::gossip::NetworkGraph; use crate::routing::router::{PaymentParameters, RouteParameters}; + use crate::sign::{InMemorySigner, KeysManager}; + use crate::util::config::{MaxDustHTLCExposure, UserConfig}; use crate::util::test_utils; - use crate::util::config::{UserConfig, MaxDustHTLCExposure}; use bitcoin::amount::Amount; - use bitcoin::locktime::absolute::LockTime; - use bitcoin::hashes::Hash; use bitcoin::hashes::sha256::Hash as Sha256; - use bitcoin::{Transaction, TxOut}; + use bitcoin::hashes::Hash; + use bitcoin::locktime::absolute::LockTime; use bitcoin::transaction::Version; + use bitcoin::{Transaction, TxOut}; use crate::sync::{Arc, RwLock}; use criterion::Criterion; type Manager<'a, P> = ChannelManager< - &'a ChainMonitor, - &'a test_utils::TestBroadcaster, &'a KeysManager, &'a KeysManager, &'a KeysManager, - &'a test_utils::TestFeeEstimator, &'a test_utils::TestRouter<'a>, - &'a test_utils::TestMessageRouter<'a>, &'a test_utils::TestLogger>; + &'a ChainMonitor< + InMemorySigner, + &'a test_utils::TestChainSource, + &'a test_utils::TestBroadcaster, + &'a test_utils::TestFeeEstimator, + &'a test_utils::TestLogger, + &'a P, + >, + &'a test_utils::TestBroadcaster, + &'a KeysManager, + &'a KeysManager, + &'a KeysManager, + &'a test_utils::TestFeeEstimator, + &'a test_utils::TestRouter<'a>, + &'a test_utils::TestMessageRouter<'a>, + &'a test_utils::TestLogger, + >; struct ANodeHolder<'node_cfg, 'chan_mon_cfg: 'node_cfg, P: Persist> { node: &'node_cfg Manager<'chan_mon_cfg, P>, } - impl<'node_cfg, 'chan_mon_cfg: 'node_cfg, P: Persist> NodeHolder for ANodeHolder<'node_cfg, 'chan_mon_cfg, P> { + impl<'node_cfg, 'chan_mon_cfg: 'node_cfg, P: Persist> NodeHolder + for ANodeHolder<'node_cfg, 'chan_mon_cfg, P> + { type CM = Manager<'chan_mon_cfg, P>; #[inline] + #[rustfmt::skip] fn node(&self) -> &Manager<'chan_mon_cfg, P> { self.node } #[inline] + #[rustfmt::skip] fn chain_monitor(&self) -> Option<&test_utils::TestChainMonitor> { None } } + #[rustfmt::skip] pub fn bench_sends(bench: &mut Criterion) { bench_two_sends(bench, "bench_sends", test_utils::TestPersister::new(), test_utils::TestPersister::new()); } + #[rustfmt::skip] pub fn bench_two_sends>(bench: &mut Criterion, bench_name: &str, persister_a: P, persister_b: P) { // Do a simple benchmark of sending a payment back and forth between two nodes. // Note that this is unrealistic as each payment send will require at least two fsync