Skip to content

Commit 8947331

Browse files
committed
Stop pre-creating PaymentStore entries in Bolt11Payment receive methods
Remove the eager `PaymentStore` insertions from `receive_inner` and `receive_via_jit_channel_inner`. Inbound payment entries will instead be created on demand by the `EventHandler` when the corresponding LDK events arrive. Outbound payment entries (created by `send` / `send_using_amount`) are kept as before so the sender always has a store record immediately after initiating a payment. Generated with the assistance of AI tools. Co-Authored-By: HAL 9000
1 parent 7843a8d commit 8947331

File tree

1 file changed

+1
-53
lines changed

1 file changed

+1
-53
lines changed

src/payment/bolt11.rs

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -512,36 +512,6 @@ impl Bolt11Payment {
512512
}
513513
};
514514

515-
let payment_hash = invoice.payment_hash();
516-
let payment_secret = invoice.payment_secret();
517-
let id = PaymentId(payment_hash.0);
518-
let preimage = if manual_claim_payment_hash.is_none() {
519-
// If the user hasn't registered a custom payment hash, we're positive ChannelManager
520-
// will know the preimage at this point.
521-
let res = self
522-
.channel_manager
523-
.get_payment_preimage(payment_hash, payment_secret.clone())
524-
.ok();
525-
debug_assert!(res.is_some(), "We just let ChannelManager create an inbound payment, it can't have forgotten the preimage by now.");
526-
res
527-
} else {
528-
None
529-
};
530-
let kind = PaymentKind::Bolt11 {
531-
hash: payment_hash,
532-
preimage,
533-
secret: Some(payment_secret.clone()),
534-
};
535-
let payment = PaymentDetails::new(
536-
id,
537-
kind,
538-
amount_msat,
539-
None,
540-
PaymentDirection::Inbound,
541-
PaymentStatus::Pending,
542-
);
543-
self.payment_store.insert(payment)?;
544-
545515
Ok(invoice)
546516
}
547517

@@ -729,16 +699,13 @@ impl Bolt11Payment {
729699
}
730700
})?;
731701

732-
// Register payment in payment store.
702+
// Store LSP fee limits in the metadata store.
733703
let payment_hash = invoice.payment_hash();
734-
let payment_secret = invoice.payment_secret();
735704
let lsp_fee_limits = LSPFeeLimits {
736705
max_total_opening_fee_msat: lsp_total_opening_fee,
737706
max_proportional_opening_fee_ppm_msat: lsp_prop_opening_fee,
738707
};
739708
let id = PaymentId(payment_hash.0);
740-
741-
// Store LSP fee limits in the metadata store.
742709
let metadata_id = MetadataId { id: self.keys_manager.get_secure_random_bytes() };
743710
let metadata_entry = PaymentMetadataEntry {
744711
id: metadata_id,
@@ -747,25 +714,6 @@ impl Bolt11Payment {
747714
};
748715
self.payment_metadata_store.insert(metadata_entry)?;
749716

750-
let preimage =
751-
self.channel_manager.get_payment_preimage(payment_hash, payment_secret.clone()).ok();
752-
let kind = PaymentKind::Bolt11Jit {
753-
hash: payment_hash,
754-
preimage,
755-
secret: Some(payment_secret.clone()),
756-
counterparty_skimmed_fee_msat: None,
757-
lsp_fee_limits,
758-
};
759-
let payment = PaymentDetails::new(
760-
id,
761-
kind,
762-
amount_msat,
763-
None,
764-
PaymentDirection::Inbound,
765-
PaymentStatus::Pending,
766-
);
767-
self.payment_store.insert(payment)?;
768-
769717
// Persist LSP peer to make sure we reconnect on restart.
770718
self.peer_store.add_peer(peer_info)?;
771719

0 commit comments

Comments
 (0)