Skip to content

Commit 78cd2a5

Browse files
committed
f: use a default value on StaleExpiration
1 parent 58b51a5 commit 78cd2a5

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

lightning/src/ln/async_payments_tests.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ use crate::ln::msgs::{
2323
};
2424
use crate::ln::offers_tests;
2525
use crate::ln::onion_utils::LocalHTLCFailureReason;
26-
use crate::ln::outbound_payment::{PendingOutboundPayment, Retry, TEST_ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY};
26+
use crate::ln::outbound_payment::{
27+
PendingOutboundPayment, Retry, TEST_ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY,
28+
};
2729
use crate::offers::async_receive_offer_cache::{
2830
TEST_MAX_CACHED_OFFERS_TARGET, TEST_MAX_UPDATE_ATTEMPTS,
2931
TEST_MIN_OFFER_PATHS_RELATIVE_EXPIRY_SECS, TEST_OFFER_REFRESH_THRESHOLD,
@@ -696,7 +698,8 @@ fn timeout_unreleased_payment() {
696698
let recipient = &nodes[2];
697699

698700
let recipient_id = vec![42; 32];
699-
let inv_server_paths = server.node.blinded_paths_for_async_recipient(recipient_id.clone(), None).unwrap();
701+
let inv_server_paths =
702+
server.node.blinded_paths_for_async_recipient(recipient_id.clone(), None).unwrap();
700703
recipient.node.set_paths_to_static_invoice_server(inv_server_paths).unwrap();
701704

702705
let static_invoice =
@@ -711,10 +714,8 @@ fn timeout_unreleased_payment() {
711714
.pay_for_offer(&offer, None, Some(amt_msat), None, payment_id, Retry::Attempts(0), params)
712715
.unwrap();
713716

714-
let invreq_om = sender
715-
.onion_messenger
716-
.next_onion_message_for_peer(server.node.get_our_node_id())
717-
.unwrap();
717+
let invreq_om =
718+
sender.onion_messenger.next_onion_message_for_peer(server.node.get_our_node_id()).unwrap();
718719
server.onion_messenger.handle_onion_message(sender.node.get_our_node_id(), &invreq_om);
719720

720721
let mut events = server.node.get_and_clear_pending_events();
@@ -725,21 +726,17 @@ fn timeout_unreleased_payment() {
725726
};
726727

727728
server.node.send_static_invoice(static_invoice.clone(), reply_path).unwrap();
728-
let static_invoice_om = server
729-
.onion_messenger
730-
.next_onion_message_for_peer(sender.node.get_our_node_id())
731-
.unwrap();
729+
let static_invoice_om =
730+
server.onion_messenger.next_onion_message_for_peer(sender.node.get_our_node_id()).unwrap();
732731

733732
// We handle the static invoice to held the pending HTLC
734-
sender
735-
.onion_messenger
736-
.handle_onion_message(sender.node.get_our_node_id(), &static_invoice_om);
733+
sender.onion_messenger.handle_onion_message(sender.node.get_our_node_id(), &static_invoice_om);
737734

738735
// We advance enough time to expire the payment.
739736
// We add 2 hours as is the margin added to remove stale payments in non-std implementation.
740737
let timeout_time_expiry = TEST_ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY
741-
+ Duration::from_secs(7200)
742-
+ Duration::from_secs(1);
738+
+ Duration::from_secs(7200)
739+
+ Duration::from_secs(1);
743740
advance_time_by(timeout_time_expiry, sender);
744741
sender.node.timer_tick_occurred();
745742
let events = sender.node.get_and_clear_pending_events();

lightning/src/ln/outbound_payment.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ pub(crate) const IDEMPOTENCY_TIMEOUT_TICKS: u8 = 7;
6060
const ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24 * 7);
6161

6262
#[cfg(all(async_payments, test))]
63-
pub(crate) const TEST_ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY: Duration = ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY;
63+
pub(crate) const TEST_ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY: Duration =
64+
ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY;
6465

6566
/// Stores the session_priv for each part of a payment that is still pending. For versions 0.0.102
6667
/// and later, also stores information for retrying the payment.
@@ -107,6 +108,7 @@ pub(crate) enum PendingOutboundPayment {
107108
invoice_request: InvoiceRequest,
108109
static_invoice: StaticInvoice,
109110
// Stale time expiration of how much time we will wait to the payment to fulfill.
111+
//
110112
// Defaults to [`ASYNC_PAYMENT_TIMEOUT_RELATIVE_EXPIRY`].
111113
expiry_time: StaleExpiration,
112114
},
@@ -2687,7 +2689,9 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
26872689
(6, route_params, required),
26882690
(8, invoice_request, required),
26892691
(10, static_invoice, required),
2690-
(12, expiry_time, required),
2692+
// Added in 0.2. Prior versions would have this TLV type defaulted to 0, which is safe because
2693+
// the type is not used.
2694+
(11, expiry_time, (default_value, StaleExpiration::AbsoluteTimeout(Duration::from_secs(0)))),
26912695
},
26922696
// Added in 0.1. Prior versions will drop these outbounds on downgrade, which is safe because
26932697
// no HTLCs are in-flight.

0 commit comments

Comments
 (0)