Skip to content

Commit bd0c1a0

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 8d9d78b commit bd0c1a0

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lightning/src/blinded_path/message.rs

+15-1
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};
@@ -137,6 +137,17 @@ pub enum OffersContext {
137137
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
138138
payment_id: PaymentId
139139
},
140+
/// Context used by a [`BlindedPath`] for replying to a [`Bolt12Invoice`] with an
141+
/// [`InvoiceError`].
142+
///
143+
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
144+
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
145+
InboundPayment {
146+
/// The same payment hash as [`Bolt12Invoice::payment_hash`].
147+
///
148+
/// [`Bolt12Invoice::payment_hash`]: crate::offers::invoice::Bolt12Invoice::payment_hash
149+
payment_hash: PaymentHash,
150+
},
140151
}
141152

142153
impl_writeable_tlv_based_enum!(MessageContext, ;
@@ -152,6 +163,9 @@ impl_writeable_tlv_based_enum!(OffersContext,
152163
(2, OutboundPayment) => {
153164
(0, payment_id, required),
154165
},
166+
(3, InboundPayment) => {
167+
(0, payment_hash, required),
168+
},
155169
;);
156170

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

lightning/src/ln/channelmanager.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -10680,8 +10680,14 @@ where
1068010680
}
1068110681
},
1068210682
OffersMessage::InvoiceError(invoice_error) => {
10683+
let payment_hash = match context {
10684+
OffersContext::InboundPayment { payment_hash } => Some(payment_hash),
10685+
_ => None,
10686+
};
10687+
let logger = WithContext::from(&self.logger, None, None, payment_hash);
10688+
log_trace!(logger, "Received invoice_error: {}", invoice_error);
10689+
1068310690
abandon_if_payment(context);
10684-
log_trace!(self.logger, "Received invoice_error: {}", invoice_error);
1068510691
ResponseInstruction::NoResponse
1068610692
},
1068710693
}

0 commit comments

Comments
 (0)