X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Fevents.rs;h=ef0c619b02e9f7a1b03cd6dd14b439e7799264dc;hb=168b3a51ae024e3abf73112c2acf9f60523c5674;hp=c86df5dff693f540baca838ca77fafc05e379b99;hpb=edd4babb1cf886654259ecad8594661e829a0680;p=rust-lightning diff --git a/lightning/src/util/events.rs b/lightning/src/util/events.rs index c86df5df..ef0c619b 100644 --- a/lightning/src/util/events.rs +++ b/lightning/src/util/events.rs @@ -17,6 +17,7 @@ use chain::keysinterface::SpendableOutputDescriptor; use ln::channelmanager::PaymentId; use ln::channel::FUNDING_CONF_DEADLINE_BLOCKS; +use ln::features::ChannelTypeFeatures; use ln::msgs; use ln::msgs::DecodeError; use ln::{PaymentPreimage, PaymentHash, PaymentSecret}; @@ -28,7 +29,7 @@ use bitcoin::Transaction; use bitcoin::blockdata::script::Script; use bitcoin::hashes::Hash; use bitcoin::hashes::sha256::Hash as Sha256; -use bitcoin::secp256k1::key::PublicKey; +use bitcoin::secp256k1::PublicKey; use io; use prelude::*; use core::time::Duration; @@ -99,12 +100,11 @@ pub enum ClosureReason { /// A developer-readable error message which we generated. err: String, }, - /// The `PeerManager` informed us that we've disconnected from the peer. We close channels - /// if the `PeerManager` informed us that it is unlikely we'll be able to connect to the - /// peer again in the future or if the peer disconnected before we finished negotiating - /// the channel open. The first case may be caused by incompatible features which our - /// counterparty, or we, require. - //TODO: split between PeerUnconnectable/PeerDisconnected ? + /// The peer disconnected prior to funding completing. In this case the spec mandates that we + /// forget the channel entirely - we can attempt again if the peer reconnects. + /// + /// In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the + /// peer because of mutual incompatibility between us and our channel counterparty. DisconnectedPeer, /// Closure generated from `ChannelManager::read` if the ChannelMonitor is newer than /// the ChannelManager deserialized. @@ -161,8 +161,15 @@ pub enum Event { /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated FundingGenerationReady { /// The random channel_id we picked which you'll need to pass into - /// ChannelManager::funding_transaction_generated. + /// [`ChannelManager::funding_transaction_generated`]. + /// + /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated temporary_channel_id: [u8; 32], + /// The counterparty's node_id, which you'll need to pass back into + /// [`ChannelManager::funding_transaction_generated`]. + /// + /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated + counterparty_node_id: PublicKey, /// The value, in satoshis, that the output should have. channel_value_satoshis: u64, /// The script which should be used in the transaction output. @@ -229,6 +236,47 @@ pub enum Event { /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees fee_paid_msat: Option, }, + /// Indicates an outbound payment failed. Individual [`Event::PaymentPathFailed`] events + /// provide failure information for each MPP part in the payment. + /// + /// This event is provided once there are no further pending HTLCs for the payment and the + /// payment is no longer retryable, either due to a several-block timeout or because + /// [`ChannelManager::abandon_payment`] was previously called for the corresponding payment. + /// + /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment + PaymentFailed { + /// The id returned by [`ChannelManager::send_payment`] and used with + /// [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`]. + /// + /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment + /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment + payment_id: PaymentId, + /// The hash that was given to [`ChannelManager::send_payment`]. + /// + /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + payment_hash: PaymentHash, + }, + /// Indicates that a path for an outbound payment was successful. + /// + /// Always generated after [`Event::PaymentSent`] and thus useful for scoring channels. See + /// [`Event::PaymentSent`] for obtaining the payment preimage. + PaymentPathSuccessful { + /// The id returned by [`ChannelManager::send_payment`] and used with + /// [`ChannelManager::retry_payment`]. + /// + /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment + payment_id: PaymentId, + /// The hash that was given to [`ChannelManager::send_payment`]. + /// + /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + payment_hash: Option, + /// The payment path that was successful. + /// + /// May contain a closed channel if the HTLC sent along the path was fulfilled on chain. + path: Vec, + }, /// Indicates an outbound HTLC we sent failed. Probably some intermediary node dropped /// something. You may wish to retry with a different route. /// @@ -298,27 +346,6 @@ pub enum Event { #[cfg(test)] error_data: Option>, }, - /// Indicates an outbound payment failed. Individual [`Event::PaymentPathFailed`] events - /// provide failure information for each MPP part in the payment. - /// - /// This event is provided once there are no further pending HTLCs for the payment and the - /// payment is no longer retryable, either due to a several-block timeout or because - /// [`ChannelManager::abandon_payment`] was previously called for the corresponding payment. - /// - /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment - PaymentFailed { - /// The id returned by [`ChannelManager::send_payment`] and used with - /// [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`]. - /// - /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment - /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment - /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment - payment_id: PaymentId, - /// The hash that was given to [`ChannelManager::send_payment`]. - /// - /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment - payment_hash: PaymentHash, - }, /// Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at /// a time in the future. /// @@ -342,6 +369,12 @@ pub enum Event { /// This event is generated when a payment has been successfully forwarded through us and a /// forwarding fee earned. PaymentForwarded { + /// The incoming channel between the previous node and us. This is only `None` for events + /// generated or serialized by versions prior to 0.0.107. + prev_channel_id: Option<[u8; 32]>, + /// The outgoing channel between the next node and us. This is only `None` for events + /// generated or serialized by versions prior to 0.0.107. + next_channel_id: Option<[u8; 32]>, /// The fee, in milli-satoshis, which was earned as a result of the payment. /// /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC @@ -386,26 +419,6 @@ pub enum Event { /// The full transaction received from the user transaction: Transaction }, - /// Indicates that a path for an outbound payment was successful. - /// - /// Always generated after [`Event::PaymentSent`] and thus useful for scoring channels. See - /// [`Event::PaymentSent`] for obtaining the payment preimage. - PaymentPathSuccessful { - /// The id returned by [`ChannelManager::send_payment`] and used with - /// [`ChannelManager::retry_payment`]. - /// - /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment - /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment - payment_id: PaymentId, - /// The hash that was given to [`ChannelManager::send_payment`]. - /// - /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment - payment_hash: Option, - /// The payment path that was successful. - /// - /// May contain a closed channel if the HTLC sent along the path was fulfilled on chain. - path: Vec, - }, /// Indicates a request to open a new channel by a peer. /// /// To accept the request, call [`ChannelManager::accept_inbound_channel`]. To reject the @@ -421,18 +434,36 @@ pub enum Event { /// The temporary channel ID of the channel requested to be opened. /// /// When responding to the request, the `temporary_channel_id` should be passed - /// back to the ChannelManager with [`ChannelManager::accept_inbound_channel`] to accept, - /// or to [`ChannelManager::force_close_channel`] to reject. + /// back to the ChannelManager through [`ChannelManager::accept_inbound_channel`] to accept, + /// or through [`ChannelManager::force_close_channel`] to reject. /// /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel temporary_channel_id: [u8; 32], /// The node_id of the counterparty requesting to open the channel. + /// + /// When responding to the request, the `counterparty_node_id` should be passed + /// back to the `ChannelManager` through [`ChannelManager::accept_inbound_channel`] to + /// accept the request, or through [`ChannelManager::force_close_channel`] to reject the + /// request. + /// + /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel + /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel counterparty_node_id: PublicKey, /// The channel value of the requested channel. funding_satoshis: u64, /// Our starting balance in the channel if the request is accepted, in milli-satoshi. push_msat: u64, + /// The features that this channel will operate with. If you reject the channel, a + /// well-behaved counterparty may automatically re-attempt the channel with a new set of + /// feature flags. + /// + /// Note that if [`ChannelTypeFeatures::supports_scid_privacy`] returns true on this type, + /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to + /// 0.0.106. + /// + /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager + channel_type: ChannelTypeFeatures, }, } @@ -509,11 +540,13 @@ impl Writeable for Event { (0, VecWriteWrapper(outputs), required), }); }, - &Event::PaymentForwarded { fee_earned_msat, claim_from_onchain_tx } => { + &Event::PaymentForwarded { fee_earned_msat, prev_channel_id, claim_from_onchain_tx, next_channel_id } => { 7u8.write(writer)?; write_tlv_fields!(writer, { (0, fee_earned_msat, option), + (1, prev_channel_id, option), (2, claim_from_onchain_tx, required), + (3, next_channel_id, option), }); }, &Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason } => { @@ -673,12 +706,16 @@ impl MaybeReadable for Event { 7u8 => { let f = || { let mut fee_earned_msat = None; + let mut prev_channel_id = None; let mut claim_from_onchain_tx = false; + let mut next_channel_id = None; read_tlv_fields!(reader, { (0, fee_earned_msat, option), + (1, prev_channel_id, option), (2, claim_from_onchain_tx, required), + (3, next_channel_id, option), }); - Ok(Some(Event::PaymentForwarded { fee_earned_msat, claim_from_onchain_tx })) + Ok(Some(Event::PaymentForwarded { fee_earned_msat, prev_channel_id, claim_from_onchain_tx, next_channel_id })) }; f() },