Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 479
add expiry_time to PendingOutboundPayment::StaticInvoiceReceived#3918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
valentinewallace
merged 1 commit into
lightningdevkit:main
from
a-mpch:2025-07-expiry-time-static-invoice-receivedJul 18, 2025
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -54,6 +54,15 @@ use crate::sync::Mutex; | ||
| /// [`ChannelManager::timer_tick_occurred`]: crate::ln::channelmanager::ChannelManager::timer_tick_occurred | ||
| pub(crate) const IDEMPOTENCY_TIMEOUT_TICKS: u8 = 7; | ||
| #[cfg(async_payments)] | ||
| /// The default relative expiration to wait for a pending outbound HTLC to a often-offline | ||
| /// payee to fulfill. | ||
| const ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24 * 7); | ||
| #[cfg(all(async_payments, test))] | ||
| pub(crate) const TEST_ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY: Duration = | ||
| ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY; | ||
| /// Stores the session_priv for each part of a payment that is still pending. For versions 0.0.102 | ||
| /// and later, also stores information for retrying the payment. | ||
| pub(crate) enum PendingOutboundPayment { | ||
| @@ -98,6 +107,11 @@ pub(crate) enum PendingOutboundPayment { | ||
| route_params: RouteParameters, | ||
| invoice_request: InvoiceRequest, | ||
| static_invoice: StaticInvoice, | ||
| // The deadline as duration since the Unix epoch for the async recipient to come online, | ||
| // after which we'll fail the payment. | ||
| // | ||
| // Defaults to [`ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY`]. | ||
| expiry_time: Duration, | ||
| }, | ||
| Retryable { | ||
| retry_strategy: Option<Retry>, | ||
| @@ -1164,6 +1178,7 @@ impl OutboundPayments { | ||
| abandon_with_entry!(entry, PaymentFailureReason::RouteNotFound); | ||
| return Err(Bolt12PaymentError::SendingFailed(RetryableSendFailure::OnionPacketSizeExceeded)) | ||
| } | ||
| let absolute_expiry = duration_since_epoch.saturating_add(ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY); | ||
| *entry.into_mut() = PendingOutboundPayment::StaticInvoiceReceived { | ||
| payment_hash, | ||
| @@ -1176,6 +1191,7 @@ impl OutboundPayments { | ||
| .ok_or(Bolt12PaymentError::UnexpectedInvoice)? | ||
| .invoice_request, | ||
| static_invoice: invoice.clone(), | ||
| expiry_time: absolute_expiry, | ||
| }; | ||
| return Ok(()) | ||
| }, | ||
| @@ -2278,11 +2294,12 @@ impl OutboundPayments { | ||
| true | ||
| } | ||
| }, | ||
| PendingOutboundPayment::StaticInvoiceReceived { route_params, payment_hash, .. } => { | ||
| let is_stale = | ||
| PendingOutboundPayment::StaticInvoiceReceived { route_params, payment_hash, expiry_time, .. } => { | ||
| let is_stale = *expiry_time < duration_since_epoch; | ||
| let is_static_invoice_stale = | ||
| route_params.payment_params.expiry_time.unwrap_or(u64::MAX) < | ||
| duration_since_epoch.as_secs(); | ||
| if is_stale { | ||
| if is_stale || is_static_invoice_stale { | ||
| let fail_ev = events::Event::PaymentFailed { | ||
| payment_id: *payment_id, | ||
| payment_hash: Some(*payment_hash), | ||
| @@ -2697,6 +2714,9 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment, | ||
| (6, route_params, required), | ||
| (8, invoice_request, required), | ||
| (10, static_invoice, required), | ||
| // Added in 0.2. Prior versions would have this TLV type defaulted to 0, which is safe because | ||
| // the type is not used. | ||
| (11, expiry_time, (default_value, Duration::from_secs(0))), | ||
a-mpch marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }, | ||
| // Added in 0.1. Prior versions will drop these outbounds on downgrade, which is safe because | ||
| // no HTLCs are in-flight. | ||
| @@ -3347,6 +3367,7 @@ mod tests { | ||
| route_params, | ||
| invoice_request: dummy_invoice_request(), | ||
| static_invoice: dummy_static_invoice(), | ||
| expiry_time: Duration::from_secs(absolute_expiry + 2), | ||
| }; | ||
| outbounds.insert(payment_id, outbound); | ||
| core::mem::drop(outbounds); | ||
| @@ -3396,6 +3417,7 @@ mod tests { | ||
| route_params, | ||
| invoice_request: dummy_invoice_request(), | ||
| static_invoice: dummy_static_invoice(), | ||
| expiry_time: now(), | ||
| }; | ||
| outbounds.insert(payment_id, outbound); | ||
| core::mem::drop(outbounds); | ||
4 changes: 4 additions & 0 deletions
4 pending_changelog/3918-expiry-time-when-waiting-often-offline-peer-asyncpayment.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| ## API Updates (0.2) | ||
| * Upgrading to v0.2.0 will timeout any pending async payment waiting for the often offline peer | ||
| come online. |
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.