Skip to content

Commit cfd0980

Browse files
committed
Don't include HMAC in Refund paths
Refunds are typically communicated via QR code, where a smaller size is desirable. Make the HMAC in OutboundPayment data optional such that it is elided from blinded paths used in refunds. This prevents abandoning refunds if the reader sends an invoice_error instead of an invoice message. However, this use case isn't necessary as the corresponding outbound payment will either timeout when the refund expires or can be explicitly abandoned by the creator.
1 parent fbaf093 commit cfd0980

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lightning/src/blinded_path/message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub enum OffersContext {
153153
/// used with an [`InvoiceError`].
154154
///
155155
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
156-
hmac: Hmac<Sha256>,
156+
hmac: Option<Hmac<Sha256>>,
157157
},
158158
/// Context used by a [`BlindedPath`] as a reply path for a [`Bolt12Invoice`].
159159
///
@@ -181,7 +181,7 @@ impl_writeable_tlv_based_enum!(OffersContext,
181181
(1, OutboundPayment) => {
182182
(0, payment_id, required),
183183
(1, nonce, required),
184-
(2, hmac, required),
184+
(2, hmac, option),
185185
},
186186
(2, InboundPayment) => {
187187
(0, payment_hash, required),

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8891,8 +8891,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
88918891
let secp_ctx = &$self.secp_ctx;
88928892

88938893
let nonce = Nonce::from_entropy_source(entropy);
8894-
let hmac = signer::hmac_for_payment_id(payment_id, nonce, expanded_key);
8895-
let context = OffersContext::OutboundPayment { payment_id, nonce, hmac };
8894+
let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: None };
88968895
let path = $self.create_blinded_paths_using_absolute_expiry(context, Some(absolute_expiry))
88978896
.and_then(|paths| paths.into_iter().next().ok_or(()))
88988897
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
@@ -9028,7 +9027,7 @@ where
90289027
let invoice_request = builder.build_and_sign()?;
90299028

90309029
let hmac = signer::hmac_for_payment_id(payment_id, nonce, expanded_key);
9031-
let context = OffersContext::OutboundPayment { payment_id, nonce, hmac };
9030+
let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) };
90329031
let reply_paths = self.create_blinded_paths(context)
90339032
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
90349033

@@ -10916,7 +10915,7 @@ where
1091610915
log_trace!(logger, "Received invoice_error: {}", invoice_error);
1091710916

1091810917
match context {
10919-
Some(OffersContext::OutboundPayment { payment_id, nonce, hmac }) => {
10918+
Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => {
1092010919
if signer::verify_payment_id(payment_id, hmac, nonce, expanded_key) {
1092110920
self.abandon_payment_with_reason(
1092210921
payment_id, PaymentFailureReason::RecipientRejected,

0 commit comments

Comments
 (0)