Skip to content

Commit 8ab04dc

Browse files
Remove payment_release_secret from async payments messages.
This field isn't necessary because we already authenticate the messages via the blinded reply paths payment_id, nonce and HMAC.
1 parent ed96df7 commit 8ab04dc

File tree

4 files changed

+21
-49
lines changed

4 files changed

+21
-49
lines changed

fuzz/src/onion_message.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,7 @@ impl AsyncPaymentsMessageHandler for TestAsyncPaymentsMessageHandler {
126126
Some(resp) => resp,
127127
None => return None,
128128
};
129-
Some((
130-
ReleaseHeldHtlc { payment_release_secret: message.payment_release_secret },
131-
responder.respond(),
132-
))
129+
Some((ReleaseHeldHtlc {}, responder.respond()))
133130
}
134131
fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {}
135132
}

lightning/src/ln/channelmanager.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -4359,8 +4359,8 @@ where
43594359
invoice, payment_id, features, best_block_height, &*self.entropy_source,
43604360
&self.pending_events
43614361
);
4362-
let payment_release_secret = match outbound_pmts_res {
4363-
Ok(secret) => secret,
4362+
match outbound_pmts_res {
4363+
Ok(()) => {},
43644364
Err(Bolt12PaymentError::UnexpectedInvoice) | Err(Bolt12PaymentError::DuplicateInvoice) => {
43654365
res = outbound_pmts_res.map(|_| ());
43664366
return NotifyOption::SkipPersistNoEvents
@@ -4397,9 +4397,7 @@ where
43974397
destination: Destination::BlindedPath(invoice_path.clone()),
43984398
reply_path: reply_path.clone(),
43994399
};
4400-
let message = AsyncPaymentsMessage::HeldHtlcAvailable(
4401-
HeldHtlcAvailable { payment_release_secret }
4402-
);
4400+
let message = AsyncPaymentsMessage::HeldHtlcAvailable(HeldHtlcAvailable {});
44034401
pending_async_payments_messages.push((message, instructions));
44044402
});
44054403

@@ -4411,16 +4409,15 @@ where
44114409

44124410
#[cfg(async_payments)]
44134411
fn send_payment_for_static_invoice(
4414-
&self, payment_id: PaymentId, payment_release_secret: [u8; 32]
4412+
&self, payment_id: PaymentId
44154413
) -> Result<(), Bolt12PaymentError> {
44164414
let best_block_height = self.best_block.read().unwrap().height;
44174415
let mut res = Ok(());
44184416
PersistenceNotifierGuard::optionally_notify(self, || {
44194417
let outbound_pmts_res = self.pending_outbound_payments.send_payment_for_static_invoice(
4420-
payment_id, payment_release_secret, &self.router, self.list_usable_channels(),
4421-
|| self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, &self,
4422-
&self.secp_ctx, best_block_height, &self.logger, &self.pending_events,
4423-
|args| self.send_payment_along_path(args)
4418+
payment_id, &self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
4419+
&self.entropy_source, &self.node_signer, &self, &self.secp_ctx, best_block_height,
4420+
&self.logger, &self.pending_events, |args| self.send_payment_along_path(args)
44244421
);
44254422
match outbound_pmts_res {
44264423
Err(Bolt12PaymentError::UnexpectedInvoice) | Err(Bolt12PaymentError::DuplicateInvoice) => {
@@ -11239,10 +11236,9 @@ where
1123911236
#[cfg(async_payments)] {
1124011237
let AsyncPaymentsContext::OutboundPayment { payment_id, hmac, nonce } = _context;
1124111238
if payment_id.verify_for_async_payment(hmac, nonce, &self.inbound_payment_key).is_err() { return }
11242-
if let Err(e) = self.send_payment_for_static_invoice(payment_id, _message.payment_release_secret) {
11239+
if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
1124311240
log_trace!(
11244-
self.logger, "Failed to release held HTLC with payment id {} and release secret {:02x?}: {:?}",
11245-
payment_id, _message.payment_release_secret, e
11241+
self.logger, "Failed to release held HTLC with payment id {}: {:?}", payment_id, e
1124611242
);
1124711243
}
1124811244
}

lightning/src/ln/outbound_payment.rs

+7-17
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ pub(crate) enum PendingOutboundPayment {
8282
payment_hash: PaymentHash,
8383
keysend_preimage: PaymentPreimage,
8484
retry_strategy: Retry,
85-
payment_release_secret: [u8; 32],
8685
route_params: RouteParameters,
8786
},
8887
Retryable {
@@ -984,7 +983,7 @@ impl OutboundPayments {
984983
&self, invoice: &StaticInvoice, payment_id: PaymentId, features: Bolt12InvoiceFeatures,
985984
best_block_height: u32, entropy_source: ES,
986985
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>
987-
) -> Result<[u8; 32], Bolt12PaymentError> where ES::Target: EntropySource {
986+
) -> Result<(), Bolt12PaymentError> where ES::Target: EntropySource {
988987
macro_rules! abandon_with_entry {
989988
($payment: expr, $reason: expr) => {
990989
$payment.get_mut().mark_abandoned($reason);
@@ -1029,7 +1028,6 @@ impl OutboundPayments {
10291028
};
10301029
let keysend_preimage = PaymentPreimage(entropy_source.get_secure_random_bytes());
10311030
let payment_hash = PaymentHash(Sha256::hash(&keysend_preimage.0).to_byte_array());
1032-
let payment_release_secret = entropy_source.get_secure_random_bytes();
10331031
let pay_params = PaymentParameters::from_static_invoice(invoice);
10341032
let mut route_params = RouteParameters::from_payment_params_and_value(pay_params, amount_msat);
10351033
route_params.max_total_routing_fee_msat = *max_total_routing_fee_msat;
@@ -1046,10 +1044,9 @@ impl OutboundPayments {
10461044
payment_hash,
10471045
keysend_preimage,
10481046
retry_strategy: *retry_strategy,
1049-
payment_release_secret,
10501047
route_params,
10511048
};
1052-
return Ok(payment_release_secret)
1049+
return Ok(())
10531050
},
10541051
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
10551052
},
@@ -1061,9 +1058,9 @@ impl OutboundPayments {
10611058
pub(super) fn send_payment_for_static_invoice<
10621059
R: Deref, ES: Deref, NS: Deref, NL: Deref, IH, SP, L: Deref
10631060
>(
1064-
&self, payment_id: PaymentId, payment_release_secret: [u8; 32], router: &R,
1065-
first_hops: Vec<ChannelDetails>, inflight_htlcs: IH, entropy_source: &ES, node_signer: &NS,
1066-
node_id_lookup: &NL, secp_ctx: &Secp256k1<secp256k1::All>, best_block_height: u32, logger: &L,
1061+
&self, payment_id: PaymentId, router: &R, first_hops: Vec<ChannelDetails>, inflight_htlcs: IH,
1062+
entropy_source: &ES, node_signer: &NS, node_id_lookup: &NL,
1063+
secp_ctx: &Secp256k1<secp256k1::All>, best_block_height: u32, logger: &L,
10671064
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>,
10681065
send_payment_along_path: SP,
10691066
) -> Result<(), Bolt12PaymentError>
@@ -1080,12 +1077,8 @@ impl OutboundPayments {
10801077
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
10811078
hash_map::Entry::Occupied(entry) => match entry.get() {
10821079
PendingOutboundPayment::StaticInvoiceReceived {
1083-
payment_hash, payment_release_secret: release_secret, route_params, retry_strategy,
1084-
keysend_preimage, ..
1080+
payment_hash, route_params, retry_strategy, keysend_preimage, ..
10851081
} => {
1086-
if payment_release_secret != *release_secret {
1087-
return Err(Bolt12PaymentError::UnexpectedInvoice)
1088-
}
10891082
(*payment_hash, *keysend_preimage, route_params.clone(), *retry_strategy)
10901083
},
10911084
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
@@ -2196,8 +2189,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
21962189
(0, payment_hash, required),
21972190
(2, keysend_preimage, required),
21982191
(4, retry_strategy, required),
2199-
(6, payment_release_secret, required),
2200-
(8, route_params, required),
2192+
(6, route_params, required),
22012193
},
22022194
);
22032195

@@ -2785,7 +2777,6 @@ mod tests {
27852777
payment_hash,
27862778
keysend_preimage: PaymentPreimage([0; 32]),
27872779
retry_strategy: Retry::Attempts(0),
2788-
payment_release_secret: [0; 32],
27892780
route_params,
27902781
};
27912782
outbounds.insert(payment_id, outbound);
@@ -2832,7 +2823,6 @@ mod tests {
28322823
payment_hash,
28332824
keysend_preimage: PaymentPreimage([0; 32]),
28342825
retry_strategy: Retry::Attempts(0),
2835-
payment_release_secret: [0; 32],
28362826
route_params,
28372827
};
28382828
outbounds.insert(payment_id, outbound);

lightning/src/onion_message/async_payments.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,11 @@ pub enum AsyncPaymentsMessage {
6161
/// accompanying this onion message should be used to send a [`ReleaseHeldHtlc`] response, which
6262
/// will cause the upstream HTLC to be released.
6363
#[derive(Clone, Debug)]
64-
pub struct HeldHtlcAvailable {
65-
/// The secret that will be used by the recipient of this message to release the held HTLC.
66-
pub payment_release_secret: [u8; 32],
67-
}
64+
pub struct HeldHtlcAvailable {}
6865

6966
/// Releases the HTLC corresponding to an inbound [`HeldHtlcAvailable`] message.
7067
#[derive(Clone, Debug)]
71-
pub struct ReleaseHeldHtlc {
72-
/// Used to release the HTLC held upstream if it matches the corresponding
73-
/// [`HeldHtlcAvailable::payment_release_secret`].
74-
pub payment_release_secret: [u8; 32],
75-
}
68+
pub struct ReleaseHeldHtlc {}
7669

7770
impl OnionMessageContents for ReleaseHeldHtlc {
7871
fn tlv_type(&self) -> u64 {
@@ -88,13 +81,9 @@ impl OnionMessageContents for ReleaseHeldHtlc {
8881
}
8982
}
9083

91-
impl_writeable_tlv_based!(HeldHtlcAvailable, {
92-
(0, payment_release_secret, required),
93-
});
84+
impl_writeable_tlv_based!(HeldHtlcAvailable, {});
9485

95-
impl_writeable_tlv_based!(ReleaseHeldHtlc, {
96-
(0, payment_release_secret, required),
97-
});
86+
impl_writeable_tlv_based!(ReleaseHeldHtlc, {});
9887

9988
impl AsyncPaymentsMessage {
10089
/// Returns whether `tlv_type` corresponds to a TLV record for async payment messages.

0 commit comments

Comments
 (0)