) -> Result<(), Bolt12PaymentError> {
let mut res = Ok(());
PersistenceNotifierGuard::optionally_notify(self, || {
+ let best_block_height = self.best_block.read().unwrap().height;
let features = self.bolt12_invoice_features();
let outbound_pmts_res = self.pending_outbound_payments.static_invoice_received(
- invoice, payment_id, features, &*self.entropy_source, &self.pending_events
+ invoice, payment_id, features, best_block_height, &*self.entropy_source,
+ &self.pending_events
);
let payment_release_secret = match outbound_pmts_res {
Ok(secret) => secret,
#[cfg(async_payments)]
pub(super) fn static_invoice_received<ES: Deref>(
&self, invoice: &StaticInvoice, payment_id: PaymentId, features: Bolt12InvoiceFeatures,
- entropy_source: ES,
+ best_block_height: u32, entropy_source: ES,
pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>
) -> Result<[u8; 32], Bolt12PaymentError> where ES::Target: EntropySource {
macro_rules! abandon_with_entry {
let pay_params = PaymentParameters::from_static_invoice(invoice);
let mut route_params = RouteParameters::from_payment_params_and_value(pay_params, amount_msat);
route_params.max_total_routing_fee_msat = *max_total_routing_fee_msat;
+
+ if let Err(()) = onion_utils::set_max_path_length(
+ &mut route_params, &RecipientOnionFields::spontaneous_empty(), Some(keysend_preimage),
+ best_block_height
+ ) {
+ abandon_with_entry!(entry, PaymentFailureReason::RouteNotFound);
+ return Err(Bolt12PaymentError::SendingFailed(RetryableSendFailure::OnionPacketSizeExceeded))
+ }
+
*entry.into_mut() = PendingOutboundPayment::StaticInvoiceReceived {
payment_hash,
keysend_preimage,