X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fevents%2Fmod.rs;h=b9fb955a5a2e5d0beb0df60b950466ac6d387d46;hb=6fd13d7b22c315d845f1df167719bc9869c02580;hp=76a7f884ad27ceb3a1550e1b7235bf7dc8795f6d;hpb=6aca7e1c4db17f43b79504fd44b942b4bc08db9d;p=rust-lightning diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index 76a7f884..b9fb955a 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -14,10 +14,8 @@ //! future, as well as generate and broadcast funding transactions handle payment preimages and a //! few other things. -#[cfg(anchors)] pub mod bump_transaction; -#[cfg(anchors)] pub use bump_transaction::BumpTransactionEvent; use crate::sign::SpendableOutputDescriptor; @@ -33,8 +31,6 @@ use crate::util::string::UntrustedString; use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters}; use bitcoin::{PackedLockTime, Transaction, OutPoint}; -#[cfg(anchors)] -use bitcoin::{Txid, TxIn, TxOut, Witness}; use bitcoin::blockdata::script::Script; use bitcoin::hashes::Hash; use bitcoin::hashes::sha256::Hash as Sha256; @@ -387,8 +383,25 @@ pub enum Event { /// /// Payments received on LDK versions prior to 0.0.115 will have this field unset. onion_fields: Option, - /// The value, in thousandths of a satoshi, that this payment is for. + /// The value, in thousandths of a satoshi, that this payment is claimable for. May be greater + /// than the invoice amount. + /// + /// May be less than the invoice amount if [`ChannelConfig::accept_underpaying_htlcs`] is set + /// and the previous hop took an extra fee. + /// + /// # Note + /// If [`ChannelConfig::accept_underpaying_htlcs`] is set and you claim without verifying this + /// field, you may lose money! + /// + /// [`ChannelConfig::accept_underpaying_htlcs`]: crate::util::config::ChannelConfig::accept_underpaying_htlcs amount_msat: u64, + /// The value, in thousands of a satoshi, that was skimmed off of this payment as an extra fee + /// taken by our channel counterparty. + /// + /// Will always be 0 unless [`ChannelConfig::accept_underpaying_htlcs`] is set. + /// + /// [`ChannelConfig::accept_underpaying_htlcs`]: crate::util::config::ChannelConfig::accept_underpaying_htlcs + counterparty_skimmed_fee_msat: u64, /// Information for claiming this received payment, based on whether the purpose of the /// payment is to pay an invoice or to send a spontaneous payment. purpose: PaymentPurpose, @@ -430,7 +443,8 @@ pub enum Event { /// The payment hash of the claimed payment. Note that LDK will not stop you from /// registering duplicate payment hashes for inbound payments. payment_hash: PaymentHash, - /// The value, in thousandths of a satoshi, that this payment is for. + /// The value, in thousandths of a satoshi, that this payment is for. May be greater than the + /// invoice amount. amount_msat: u64, /// The purpose of the claimed payment, i.e. whether the payment was for an invoice or a /// spontaneous payment. @@ -623,6 +637,7 @@ pub enum Event { inbound_amount_msat: u64, /// How many msats the payer intended to route to the next node. Depending on the reason you are /// intercepting this payment, you might take a fee by forwarding less than this amount. + /// Forwarding less than this amount may break compatibility with LDK versions prior to 0.0.116. /// /// Note that LDK will NOT check that expected fees were factored into this value. You MUST /// check that whatever fee you want has been included here or subtract it as required. Further, @@ -815,7 +830,6 @@ pub enum Event { /// Destination of the HTLC that failed to be processed. failed_next_destination: HTLCDestination, }, - #[cfg(anchors)] /// Indicates that a transaction originating from LDK needs to have its fee bumped. This event /// requires confirmed external funds to be readily available to spend. /// @@ -832,8 +846,8 @@ impl Writeable for Event { // We never write out FundingGenerationReady events as, upon disconnection, peers // drop any channels which have not yet exchanged funding_signed. }, - &Event::PaymentClaimable { ref payment_hash, ref amount_msat, ref purpose, - ref receiver_node_id, ref via_channel_id, ref via_user_channel_id, + &Event::PaymentClaimable { ref payment_hash, ref amount_msat, counterparty_skimmed_fee_msat, + ref purpose, ref receiver_node_id, ref via_channel_id, ref via_user_channel_id, ref claim_deadline, ref onion_fields } => { 1u8.write(writer)?; @@ -848,6 +862,8 @@ impl Writeable for Event { payment_preimage = Some(*preimage); } } + let skimmed_fee_opt = if counterparty_skimmed_fee_msat == 0 { None } + else { Some(counterparty_skimmed_fee_msat) }; write_tlv_fields!(writer, { (0, payment_hash, required), (1, receiver_node_id, option), @@ -855,10 +871,11 @@ impl Writeable for Event { (3, via_channel_id, option), (4, amount_msat, required), (5, via_user_channel_id, option), - (6, 0u64, required), // user_payment_id required for compatibility with 0.0.103 and earlier + // Type 6 was `user_payment_id` on 0.0.103 and earlier (7, claim_deadline, option), (8, payment_preimage, option), (9, onion_fields, option), + (10, skimmed_fee_opt, option), }); }, &Event::PaymentSent { ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat } => { @@ -1009,7 +1026,6 @@ impl Writeable for Event { (2, failed_next_destination, required), }) }, - #[cfg(anchors)] &Event::BumpTransaction(ref event)=> { 27u8.write(writer)?; match event { @@ -1058,8 +1074,9 @@ impl MaybeReadable for Event { let mut payment_preimage = None; let mut payment_secret = None; let mut amount_msat = 0; + let mut counterparty_skimmed_fee_msat_opt = None; let mut receiver_node_id = None; - let mut _user_payment_id = None::; // For compatibility with 0.0.103 and earlier + let mut _user_payment_id = None::; // Used in 0.0.103 and earlier, no longer written in 0.0.116+. let mut via_channel_id = None; let mut claim_deadline = None; let mut via_user_channel_id = None; @@ -1075,6 +1092,7 @@ impl MaybeReadable for Event { (7, claim_deadline, option), (8, payment_preimage, option), (9, onion_fields, option), + (10, counterparty_skimmed_fee_msat_opt, option), }); let purpose = match payment_secret { Some(secret) => PaymentPurpose::InvoicePayment { @@ -1088,6 +1106,7 @@ impl MaybeReadable for Event { receiver_node_id, payment_hash, amount_msat, + counterparty_skimmed_fee_msat: counterparty_skimmed_fee_msat_opt.unwrap_or(0), purpose, via_channel_id, via_user_channel_id,