Skip to content

Commit 1f7562a

Browse files
committed
Include payment hash when logging InvoiceError
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.
1 parent 1b4e0da commit 1f7562a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lightning/src/blinded_path/message.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::blinded_path::utils;
2121
use crate::io;
2222
use crate::io::Cursor;
2323
use crate::ln::channelmanager::PaymentId;
24-
use crate::ln::onion_utils;
24+
use crate::ln::{PaymentHash, onion_utils};
2525
use crate::offers::nonce::Nonce;
2626
use crate::onion_message::packet::ControlTlvs;
2727
use crate::sign::{NodeSigner, Recipient};
@@ -144,6 +144,17 @@ pub enum OffersContext {
144144
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
145145
payment_id: PaymentId
146146
},
147+
/// Context used by a [`BlindedPath`] for replying to a [`Bolt12Invoice`] with an
148+
/// [`InvoiceError`].
149+
///
150+
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
151+
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
152+
InboundPayment {
153+
/// The same payment hash as [`Bolt12Invoice::payment_hash`].
154+
///
155+
/// [`Bolt12Invoice::payment_hash`]: crate::offers::invoice::Bolt12Invoice::payment_hash
156+
payment_hash: PaymentHash,
157+
},
147158
}
148159

149160
impl_writeable_tlv_based_enum!(MessageContext, ;
@@ -159,6 +170,9 @@ impl_writeable_tlv_based_enum!(OffersContext,
159170
(2, OutboundPayment) => {
160171
(0, payment_id, required),
161172
},
173+
(3, InboundPayment) => {
174+
(0, payment_hash, required),
175+
},
162176
;);
163177

164178
/// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`.

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10682,8 +10682,14 @@ where
1068210682
}
1068310683
},
1068410684
OffersMessage::InvoiceError(invoice_error) => {
10685+
let payment_hash = match context {
10686+
OffersContext::InboundPayment { payment_hash } => Some(payment_hash),
10687+
_ => None,
10688+
};
10689+
let logger = WithContext::from(&self.logger, None, None, payment_hash);
10690+
log_trace!(logger, "Received invoice_error: {}", invoice_error);
10691+
1068510692
abandon_if_payment(context);
10686-
log_trace!(self.logger, "Received invoice_error: {}", invoice_error);
1068710693
ResponseInstruction::NoResponse
1068810694
},
1068910695
}

0 commit comments

Comments
 (0)