Skip to content

Commit d3de51b

Browse files
Set max path len on receipt of static invoice.
We don't want to wait until we actually go to send HTLCs to do this check, since that could be days later.
1 parent a006308 commit d3de51b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4292,9 +4292,11 @@ where
42924292
) -> Result<(), Bolt12PaymentError> {
42934293
let mut res = Ok(());
42944294
PersistenceNotifierGuard::optionally_notify(self, || {
4295+
let best_block_height = self.best_block.read().unwrap().height;
42954296
let features = self.bolt12_invoice_features();
42964297
let outbound_pmts_res = self.pending_outbound_payments.static_invoice_received(
4297-
invoice, payment_id, features, &*self.entropy_source, &self.pending_events
4298+
invoice, payment_id, features, best_block_height, &*self.entropy_source,
4299+
&self.pending_events
42984300
);
42994301
let payment_release_secret = match outbound_pmts_res {
43004302
Ok(secret) => secret,

lightning/src/ln/outbound_payment.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ impl OutboundPayments {
919919
#[cfg(async_payments)]
920920
pub(super) fn static_invoice_received<ES: Deref>(
921921
&self, invoice: &StaticInvoice, payment_id: PaymentId, features: Bolt12InvoiceFeatures,
922-
entropy_source: ES,
922+
best_block_height: u32, entropy_source: ES,
923923
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>
924924
) -> Result<[u8; 32], Bolt12PaymentError> where ES::Target: EntropySource {
925925
macro_rules! abandon_with_entry {
@@ -961,7 +961,16 @@ impl OutboundPayments {
961961
let payment_hash = PaymentHash(Sha256::hash(&keysend_preimage.0).to_byte_array());
962962
let payment_release_secret = entropy_source.get_secure_random_bytes();
963963
let pay_params = PaymentParameters::from_static_invoice(invoice);
964-
let route_params = RouteParameters::from_payment_params_and_value(pay_params, amount_msat);
964+
let mut route_params = RouteParameters::from_payment_params_and_value(pay_params, amount_msat);
965+
966+
if let Err(()) = onion_utils::set_max_path_length(
967+
&mut route_params, &RecipientOnionFields::spontaneous_empty(), Some(keysend_preimage),
968+
best_block_height
969+
) {
970+
abandon_with_entry!(entry, PaymentFailureReason::UnexpectedError);
971+
return Err(Bolt12PaymentError::SendingFailed(RetryableSendFailure::OnionPacketSizeExceeded))
972+
}
973+
965974
*entry.into_mut() = PendingOutboundPayment::StaticInvoiceReceived {
966975
payment_hash,
967976
keysend_preimage,

0 commit comments

Comments
 (0)