]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Include payment hash when logging InvoiceError
authorJeffrey Czyz <jkczyz@gmail.com>
Wed, 3 Jul 2024 16:02:08 +0000 (11:02 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Tue, 30 Jul 2024 21:06:24 +0000 (16:06 -0500)
By including the payment hash from the invoice in an onion message's
reply path, it can be used when logging errors as additional context.

lightning/src/blinded_path/message.rs
lightning/src/ln/channelmanager.rs

index 15bf1a9494058ba02961b365593ffbc0947ba1cf..2ff799d0ebd5a1baf45b3fe96a953c55ba3c260a 100644 (file)
@@ -21,7 +21,7 @@ use crate::blinded_path::utils;
 use crate::io;
 use crate::io::Cursor;
 use crate::ln::channelmanager::PaymentId;
-use crate::ln::onion_utils;
+use crate::ln::{PaymentHash, onion_utils};
 use crate::offers::nonce::Nonce;
 use crate::onion_message::packet::ControlTlvs;
 use crate::sign::{NodeSigner, Recipient};
@@ -152,6 +152,18 @@ pub enum OffersContext {
                /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
                nonce: Nonce,
        },
+       /// Context used by a [`BlindedPath`] as a reply path for a [`Bolt12Invoice`].
+       ///
+       /// This variant is intended to be received when handling an [`InvoiceError`].
+       ///
+       /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
+       /// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
+       InboundPayment {
+               /// The same payment hash as [`Bolt12Invoice::payment_hash`].
+               ///
+               /// [`Bolt12Invoice::payment_hash`]: crate::offers::invoice::Bolt12Invoice::payment_hash
+               payment_hash: PaymentHash,
+       },
 }
 
 impl_writeable_tlv_based_enum!(MessageContext,
@@ -168,6 +180,9 @@ impl_writeable_tlv_based_enum!(OffersContext,
                (0, payment_id, required),
                (1, nonce, required),
        },
+       (3, InboundPayment) => {
+               (0, payment_hash, required),
+       },
 );
 
 /// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`.
index 10c010e8989c698a621a28954e8cb0e5828900f7..16c06e8deb1cda266084f3743bb21ce1ca299bae 100644 (file)
@@ -10879,8 +10879,14 @@ where
                                }
                        },
                        OffersMessage::InvoiceError(invoice_error) => {
+                               let payment_hash = match context {
+                                       OffersContext::InboundPayment { payment_hash } => Some(payment_hash),
+                                       _ => None,
+                               };
+                               let logger = WithContext::from(&self.logger, None, None, payment_hash);
+                               log_trace!(logger, "Received invoice_error: {}", invoice_error);
+
                                abandon_if_payment(context);
-                               log_trace!(self.logger, "Received invoice_error: {}", invoice_error);
                                ResponseInstruction::NoResponse
                        },
                }