Skip to content

Commit 1d29fcc

Browse files
committed
f Use claim-height pending expiry
Keep manual BOLT11 invoice reservations time-based until the claimable event arrives, then prune by the HTLC claim deadline height so cleanup cannot run before the claim window closes. Co-Authored-By: HAL 9000
1 parent ccd8971 commit 1d29fcc

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/event.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use crate::payment::asynchronous::static_invoice_store::StaticInvoiceStore;
5252
use crate::payment::store::{
5353
PaymentDetails, PaymentDetailsUpdate, PaymentDirection, PaymentKind, PaymentStatus,
5454
};
55-
use crate::payment::{PaymentMetadata, PendingPaymentDetails};
55+
use crate::payment::{PaymentMetadata, PendingPaymentDetails, PendingPaymentExpiry};
5656
use crate::probing::Prober;
5757
use crate::runtime::Runtime;
5858
use crate::types::{
@@ -617,9 +617,10 @@ where
617617

618618
async fn prune_expired_pending_payments(&self) -> Result<(), ReplayEvent> {
619619
let now = Self::current_time_secs();
620+
let current_height = self.channel_manager.current_best_block().height;
620621
let expired_payment_ids = self
621622
.pending_payment_store
622-
.list_filter(|payment| payment.has_expired(now))
623+
.list_filter(|payment| payment.has_expired(now, current_height))
623624
.into_iter()
624625
.map(|payment| payment.details.id)
625626
.collect::<Vec<_>>();
@@ -932,7 +933,8 @@ where
932933
}
933934

934935
let mut pending_payment = pending_payment.clone();
935-
pending_payment.expires_at = None;
936+
pending_payment.expiry =
937+
claim_deadline.map(|height| PendingPaymentExpiry::Height { height });
936938
if let Err(e) =
937939
self.pending_payment_store.insert_or_update(pending_payment).await
938940
{

src/payment/bolt11.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::payment::store::{
3636
LSPS2Parameters, PaymentDetails, PaymentDetailsUpdate, PaymentDirection, PaymentKind,
3737
PaymentStatus,
3838
};
39-
use crate::payment::PendingPaymentDetails;
39+
use crate::payment::{PendingPaymentDetails, PendingPaymentExpiry};
4040
use crate::peer_store::{PeerInfo, PeerStore};
4141
use crate::runtime::Runtime;
4242
use crate::types::{ChannelManager, PaymentStore, PendingPaymentStore};
@@ -109,9 +109,10 @@ impl Bolt11Payment {
109109

110110
fn prune_expired_pending_payments(&self) -> Result<(), Error> {
111111
let now = Self::current_time_secs();
112+
let current_height = self.channel_manager.current_best_block().height;
112113
let expired_payment_ids = self
113114
.pending_payment_store
114-
.list_filter(|payment| payment.has_expired(now))
115+
.list_filter(|payment| payment.has_expired(now, current_height))
115116
.into_iter()
116117
.map(|payment| payment.details.id)
117118
.collect::<Vec<_>>();
@@ -138,8 +139,9 @@ impl Bolt11Payment {
138139
PaymentDirection::Inbound,
139140
PaymentStatus::Pending,
140141
);
141-
let expires_at = Some(Self::current_time_secs().saturating_add(expiry_secs as u64));
142-
PendingPaymentDetails::new_with_expiry(payment, Vec::new(), expires_at)
142+
let timestamp = Self::current_time_secs().saturating_add(expiry_secs as u64);
143+
let expiry = Some(PendingPaymentExpiry::Time { timestamp });
144+
PendingPaymentDetails::new_with_expiry(payment, Vec::new(), expiry)
143145
}
144146

145147
fn reserve_manual_claim_invoice(

src/payment/pending_payment_store.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,11 @@ mod tests {
474474
PaymentDirection::Inbound,
475475
PaymentStatus::Pending,
476476
);
477-
PendingPaymentDetails::new_with_expiry(details, Vec::new(), Some(1_000_000))
477+
PendingPaymentDetails::new_with_expiry(
478+
details,
479+
Vec::new(),
480+
Some(PendingPaymentExpiry::Time { timestamp: 1_000_000 }),
481+
)
478482
}
479483

480484
#[tokio::test]

0 commit comments

Comments
 (0)