Skip to content

Commit d3f7855

Browse files
committed
Use BDK events in update_payment_store instead of scanning all transactions
Replace the full transaction list scan in `update_payment_store` with handling of BDK's `WalletEvent` stream during sync. This leverages the new events in BDK 2.2, reduces redundant work, and prepares the foundation for reliable RBF/CPFP tracking via `WalletEvent::TxReplaced`.
1 parent 121dadb commit d3f7855

File tree

4 files changed

+312
-75
lines changed

4 files changed

+312
-75
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ interface ClosureReason {
420420

421421
[Enum]
422422
interface PaymentKind {
423-
Onchain(Txid txid, ConfirmationStatus status);
423+
Onchain(Txid txid, ConfirmationStatus status, sequence<Txid> conflicting_txids);
424424
Bolt11(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret);
425425
Bolt11Jit(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret, u64? counterparty_skimmed_fee_msat, LSPFeeLimits lsp_fee_limits);
426426
Bolt12Offer(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, OfferId offer_id, UntrustedString? payer_note, u64? quantity);

src/payment/store.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,15 @@ impl StorableObject for PaymentDetails {
291291
}
292292
}
293293

294+
if let Some(conflicting_txids_opt) = &update.conflicting_txids {
295+
match self.kind {
296+
PaymentKind::Onchain { ref mut conflicting_txids, .. } => {
297+
update_if_necessary!(*conflicting_txids, conflicting_txids_opt.to_vec());
298+
},
299+
_ => {},
300+
}
301+
}
302+
294303
if updated {
295304
self.latest_update_timestamp = SystemTime::now()
296305
.duration_since(UNIX_EPOCH)
@@ -351,6 +360,8 @@ pub enum PaymentKind {
351360
txid: Txid,
352361
/// The confirmation status of this payment.
353362
status: ConfirmationStatus,
363+
/// Transaction IDs that have replaced or conflict with this payment.
364+
conflicting_txids: Vec<Txid>,
354365
},
355366
/// A [BOLT 11] payment.
356367
///
@@ -448,6 +459,7 @@ pub enum PaymentKind {
448459
impl_writeable_tlv_based_enum!(PaymentKind,
449460
(0, Onchain) => {
450461
(0, txid, required),
462+
(1, conflicting_txids, optional_vec),
451463
(2, status, required),
452464
},
453465
(2, Bolt11) => {
@@ -540,6 +552,7 @@ pub(crate) struct PaymentDetailsUpdate {
540552
pub direction: Option<PaymentDirection>,
541553
pub status: Option<PaymentStatus>,
542554
pub confirmation_status: Option<ConfirmationStatus>,
555+
pub conflicting_txids: Option<Vec<Txid>>,
543556
}
544557

545558
impl PaymentDetailsUpdate {
@@ -555,6 +568,7 @@ impl PaymentDetailsUpdate {
555568
direction: None,
556569
status: None,
557570
confirmation_status: None,
571+
conflicting_txids: None,
558572
}
559573
}
560574
}
@@ -570,9 +584,11 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
570584
_ => (None, None, None),
571585
};
572586

573-
let confirmation_status = match value.kind {
574-
PaymentKind::Onchain { status, .. } => Some(status),
575-
_ => None,
587+
let (confirmation_status, conflicting_txids) = match &value.kind {
588+
PaymentKind::Onchain { status, conflicting_txids, .. } => {
589+
(Some(*status), conflicting_txids.clone())
590+
},
591+
_ => (None, Vec::new()),
576592
};
577593

578594
let counterparty_skimmed_fee_msat = match value.kind {
@@ -593,6 +609,7 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
593609
direction: Some(value.direction),
594610
status: Some(value.status),
595611
confirmation_status,
612+
conflicting_txids: Some(conflicting_txids),
596613
}
597614
}
598615
}

0 commit comments

Comments
 (0)