Add blinded path {metadata} fields to Path, but disallow paying blinded paths for now
[rust-lightning] / lightning / src / events / mod.rs
index 24252e38ebaee6103c6e359d25062f0077a8103c..b5f682e1fb597eb0a923f214daace1ffba1e91a2 100644 (file)
@@ -21,7 +21,7 @@ pub mod bump_transaction;
 pub use bump_transaction::BumpTransactionEvent;
 
 use crate::chain::keysinterface::SpendableOutputDescriptor;
-use crate::ln::channelmanager::{InterceptId, PaymentId};
+use crate::ln::channelmanager::{InterceptId, PaymentId, RecipientOnionFields};
 use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
 use crate::ln::features::ChannelTypeFeatures;
 use crate::ln::msgs;
@@ -30,7 +30,7 @@ use crate::routing::gossip::NetworkUpdate;
 use crate::util::errors::APIError;
 use crate::util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable, RequiredWrapper, UpgradableRequired, WithoutLength};
 use crate::util::string::UntrustedString;
-use crate::routing::router::{RouteHop, RouteParameters};
+use crate::routing::router::{Path, RouteHop, RouteParameters};
 
 use bitcoin::{PackedLockTime, Transaction, OutPoint};
 #[cfg(anchors)]
@@ -232,8 +232,11 @@ pub enum HTLCDestination {
        ///
        /// Some of the reasons may include:
        /// * HTLC Timeouts
-       /// * Expected MPP amount has already been reached
-       /// * Claimable amount does not match expected amount
+       /// * Excess HTLCs for a payment that we have already fully received, over-paying for the
+       ///   payment,
+       /// * The counterparty node modified the HTLC in transit,
+       /// * A probing attack where an intermediary node is trying to detect if we are the ultimate
+       ///   recipient for a payment.
        FailedPayment {
                /// The payment hash of the payment we attempted to process.
                payment_hash: PaymentHash
@@ -379,6 +382,11 @@ pub enum Event {
                /// The hash for which the preimage should be handed to the ChannelManager. Note that LDK will
                /// not stop you from registering duplicate payment hashes for inbound payments.
                payment_hash: PaymentHash,
+               /// The fields in the onion which were received with each HTLC. Only fields which were
+               /// identical in each HTLC involved in the payment will be included here.
+               ///
+               /// Payments received on LDK versions prior to 0.0.115 will have this field unset.
+               onion_fields: Option<RecipientOnionFields>,
                /// The value, in thousandths of a satoshi, that this payment is for.
                amount_msat: u64,
                /// Information for claiming this received payment, based on whether the purpose of the
@@ -475,6 +483,9 @@ pub enum Event {
                ///
                /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
                payment_hash: PaymentHash,
+               /// The reason the payment failed. This is only `None` for events generated or serialized
+               /// by versions prior to 0.0.115.
+               reason: Option<PaymentFailureReason>,
        },
        /// Indicates that a path for an outbound payment was successful.
        ///
@@ -492,7 +503,7 @@ pub enum Event {
                /// The payment path that was successful.
                ///
                /// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
-               path: Vec<RouteHop>,
+               path: Path,
        },
        /// Indicates an outbound HTLC we sent failed, likely due to an intermediary node being unable to
        /// handle the HTLC.
@@ -524,7 +535,7 @@ pub enum Event {
                /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
                failure: PathFailure,
                /// The payment path that failed.
-               path: Vec<RouteHop>,
+               path: Path,
                /// The channel responsible for the failed payment path.
                ///
                /// Note that for route hints or for the first hop in a path this may be an SCID alias and
@@ -550,7 +561,7 @@ pub enum Event {
                /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
                payment_hash: PaymentHash,
                /// The payment path that was successful.
-               path: Vec<RouteHop>,
+               path: Path,
        },
        /// Indicates that a probe payment we sent failed at an intermediary node on the path.
        ProbeFailed {
@@ -563,7 +574,7 @@ pub enum Event {
                /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
                payment_hash: PaymentHash,
                /// The payment path that failed.
-               path: Vec<RouteHop>,
+               path: Path,
                /// The channel responsible for the failed probe.
                ///
                /// Note that for route hints or for the first hop in a path this may be an SCID alias and
@@ -817,7 +828,10 @@ 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, ref claim_deadline } => {
+                       &Event::PaymentClaimable { ref payment_hash, ref amount_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)?;
                                let mut payment_secret = None;
                                let payment_preimage;
@@ -840,6 +854,7 @@ impl Writeable for Event {
                                        (6, 0u64, required), // user_payment_id required for compatibility with 0.0.103 and earlier
                                        (7, claim_deadline, option),
                                        (8, payment_preimage, option),
+                                       (9, onion_fields, option),
                                });
                        },
                        &Event::PaymentSent { ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat } => {
@@ -869,7 +884,7 @@ impl Writeable for Event {
                                        (1, None::<NetworkUpdate>, option), // network_update in LDK versions prior to 0.0.114
                                        (2, payment_failed_permanently, required),
                                        (3, false, required), // all_paths_failed in LDK versions prior to 0.0.114
-                                       (5, *path, vec_type),
+                                       (5, path.hops, vec_type),
                                        (7, short_channel_id, option),
                                        (9, None::<RouteParameters>, option), // retry in LDK versions prior to 0.0.115
                                        (11, payment_id, option),
@@ -937,13 +952,14 @@ impl Writeable for Event {
                                write_tlv_fields!(writer, {
                                        (0, payment_id, required),
                                        (2, payment_hash, option),
-                                       (4, *path, vec_type)
+                                       (4, path.hops, vec_type),
                                })
                        },
-                       &Event::PaymentFailed { ref payment_id, ref payment_hash } => {
+                       &Event::PaymentFailed { ref payment_id, ref payment_hash, ref reason } => {
                                15u8.write(writer)?;
                                write_tlv_fields!(writer, {
                                        (0, payment_id, required),
+                                       (1, reason, option),
                                        (2, payment_hash, required),
                                })
                        },
@@ -966,7 +982,7 @@ impl Writeable for Event {
                                write_tlv_fields!(writer, {
                                        (0, payment_id, required),
                                        (2, payment_hash, required),
-                                       (4, *path, vec_type)
+                                       (4, path.hops, vec_type),
                                })
                        },
                        &Event::ProbeFailed { ref payment_id, ref payment_hash, ref path, ref short_channel_id } => {
@@ -974,7 +990,7 @@ impl Writeable for Event {
                                write_tlv_fields!(writer, {
                                        (0, payment_id, required),
                                        (2, payment_hash, required),
-                                       (4, *path, vec_type),
+                                       (4, path.hops, vec_type),
                                        (6, short_channel_id, option),
                                })
                        },
@@ -1039,6 +1055,7 @@ impl MaybeReadable for Event {
                                        let mut via_channel_id = None;
                                        let mut claim_deadline = None;
                                        let mut via_user_channel_id = None;
+                                       let mut onion_fields = None;
                                        read_tlv_fields!(reader, {
                                                (0, payment_hash, required),
                                                (1, receiver_node_id, option),
@@ -1049,6 +1066,7 @@ impl MaybeReadable for Event {
                                                (6, _user_payment_id, option),
                                                (7, claim_deadline, option),
                                                (8, payment_preimage, option),
+                                               (9, onion_fields, option),
                                        });
                                        let purpose = match payment_secret {
                                                Some(secret) => PaymentPurpose::InvoicePayment {
@@ -1066,6 +1084,7 @@ impl MaybeReadable for Event {
                                                via_channel_id,
                                                via_user_channel_id,
                                                claim_deadline,
+                                               onion_fields,
                                        }))
                                };
                                f()
@@ -1122,7 +1141,7 @@ impl MaybeReadable for Event {
                                                payment_hash,
                                                payment_failed_permanently,
                                                failure,
-                                               path: path.unwrap(),
+                                               path: Path { hops: path.unwrap(), blinded_tail: None },
                                                short_channel_id,
                                                #[cfg(test)]
                                                error_code,
@@ -1236,7 +1255,7 @@ impl MaybeReadable for Event {
                                        Ok(Some(Event::PaymentPathSuccessful {
                                                payment_id,
                                                payment_hash,
-                                               path: path.unwrap(),
+                                               path: Path { hops: path.unwrap(), blinded_tail: None },
                                        }))
                                };
                                f()
@@ -1245,13 +1264,16 @@ impl MaybeReadable for Event {
                                let f = || {
                                        let mut payment_hash = PaymentHash([0; 32]);
                                        let mut payment_id = PaymentId([0; 32]);
+                                       let mut reason = None;
                                        read_tlv_fields!(reader, {
                                                (0, payment_id, required),
+                                               (1, reason, upgradable_option),
                                                (2, payment_hash, required),
                                        });
                                        Ok(Some(Event::PaymentFailed {
                                                payment_id,
                                                payment_hash,
+                                               reason,
                                        }))
                                };
                                f()
@@ -1294,7 +1316,7 @@ impl MaybeReadable for Event {
                                        Ok(Some(Event::ProbeSuccessful {
                                                payment_id,
                                                payment_hash,
-                                               path: path.unwrap(),
+                                               path: Path { hops: path.unwrap(), blinded_tail: None },
                                        }))
                                };
                                f()
@@ -1314,7 +1336,7 @@ impl MaybeReadable for Event {
                                        Ok(Some(Event::ProbeFailed {
                                                payment_id,
                                                payment_hash,
-                                               path: path.unwrap(),
+                                               path: Path { hops: path.unwrap(), blinded_tail: None },
                                                short_channel_id,
                                        }))
                                };