Skip to content

Track inbound payments by PaymentId - #948

Open
tnull wants to merge 7 commits into
lightningdevkit:mainfrom
tnull:2026-06-payment-id-prefactors
Open

Track inbound payments by PaymentId#948
tnull wants to merge 7 commits into
lightningdevkit:mainfrom
tnull:2026-06-payment-id-prefactors

Conversation

@tnull

@tnull tnull commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Closes #298.

This finally switches our inbound payments over to be fully tracked by payment id, and decouples payment IDs from payment hashes.

@ldk-reviews-bot

ldk-reviews-bot commented Jun 24, 2026

Copy link
Copy Markdown

👋 Thanks for assigning @tankyleo as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@tnull
tnull force-pushed the 2026-06-payment-id-prefactors branch from 51dba72 to ff3345d Compare June 24, 2026 15:21
@tnull
tnull marked this pull request as draft June 24, 2026 15:22
@tnull
tnull force-pushed the 2026-06-payment-id-prefactors branch from ff3345d to 544e100 Compare June 24, 2026 15:23
Comment thread src/payment/bolt11.rs
@tnull
tnull force-pushed the 2026-06-payment-id-prefactors branch from 544e100 to 4c3f2e4 Compare July 2, 2026 13:45
@tnull
tnull marked this pull request as ready for review July 2, 2026 13:46
@ldk-reviews-bot
ldk-reviews-bot requested a review from tankyleo July 2, 2026 13:47
@tnull
tnull removed the request for review from tankyleo July 2, 2026 13:50
@tnull
tnull marked this pull request as draft July 2, 2026 13:50
@tnull
tnull force-pushed the 2026-06-payment-id-prefactors branch from 4c3f2e4 to 4a24ee7 Compare July 2, 2026 14:08
@tnull
tnull requested a review from tankyleo July 2, 2026 14:09
@tnull
tnull marked this pull request as ready for review July 2, 2026 14:09
Comment thread src/payment/bolt11.rs Outdated
Comment thread src/payment/bolt11.rs Outdated
Comment thread src/event.rs Outdated
Comment thread src/payment/bolt11.rs
@tnull
tnull force-pushed the 2026-06-payment-id-prefactors branch from 4a24ee7 to d1b5ffb Compare July 7, 2026 14:58
@tnull

tnull commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased without further changes for now.

@tnull
tnull force-pushed the 2026-06-payment-id-prefactors branch from d1b5ffb to b1f6564 Compare July 7, 2026 15:27
@tnull

tnull commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

Force-pushed some fixes:

> git diff-tree -U2  d1b5ffb3 b1f65649
diff --git a/bindings/python/src/ldk_node/test_ldk_node.py b/bindings/python/src/ldk_node/test_ldk_node.py
index 304caf9c..063c95f7 100644
--- a/bindings/python/src/ldk_node/test_ldk_node.py
+++ b/bindings/python/src/ldk_node/test_ldk_node.py
@@ -236,5 +236,5 @@ class TestLdkNode(unittest.TestCase):

         sender_payment = node_1.payment(keysend_payment_id)
-        receiver_payment = node_2.payment(keysend_payment_id)
+        receiver_payment = node_2.payment(received_event.payment_id)

         self.assertIsNotNone(sender_payment)
diff --git a/tests/integration_tests_migration.rs b/tests/integration_tests_migration.rs
index c4e63451..59621476 100644
--- a/tests/integration_tests_migration.rs
+++ b/tests/integration_tests_migration.rs
@@ -204,5 +204,5 @@ async fn migrate_node_across_all_backends() {
 	let invoice = node_b.bolt11_payment().receive(10_000, &description.into(), 3600).unwrap();
 	let ln_send_id = node.bolt11_payment().send(&invoice, None).unwrap();
-	expect_payment_successful_event!(node, Some(ln_send_id), None);
+	expect_payment_successful_event!(node, ln_send_id, None);
 	expect_payment_received_event!(node_b, 10_000);

@@ -212,5 +212,5 @@ async fn migrate_node_across_all_backends() {
 	let invoice = node.bolt11_payment().receive(5_000, &description.into(), 3600).unwrap();
 	let ln_receive_id = node_b.bolt11_payment().send(&invoice, None).unwrap();
-	expect_payment_successful_event!(node_b, Some(ln_receive_id), None);
+	expect_payment_successful_event!(node_b, ln_receive_id, None);
 	expect_payment_received_event!(node, 5_000);

Comment thread src/payment/bolt11.rs Outdated
Comment thread src/payment/pending_payment_store.rs Outdated
Comment thread src/payment/pending_payment_store.rs Outdated
Comment thread src/event.rs Outdated
Comment thread src/event.rs Outdated
Comment thread src/payment/bolt11.rs Outdated
Comment thread src/event.rs
@tnull
tnull force-pushed the 2026-06-payment-id-prefactors branch 3 times, most recently from 046355b to 452c643 Compare July 15, 2026 13:19
@tnull
tnull requested a review from tankyleo July 15, 2026 13:19
@joostjager

Copy link
Copy Markdown
Contributor

Looking at this through the lens of self-imposed versus intrinsic complexity, I think this PR again makes the cost of our current architecture clear. LDK and ldk-node persist related state independently, without a consistent commit boundary, so we have to recover consistency through careful ordering, replay, cleanup, and expiry logic.

@tankyleo tankyleo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits feel free to squash will take a better pass tomorrow

Comment thread src/payment/pending_payment_store.rs Outdated
Comment thread src/data_store.rs Outdated
Comment thread src/data_store.rs Outdated
Comment thread src/event.rs Outdated
Comment thread src/data_store.rs Outdated
Comment thread src/data_store.rs Outdated
Comment thread src/event.rs Outdated
Comment thread src/event.rs
The switch to tracking payments by ID happened with LDK Node v0.3.0,
which is >1.5 years old by now. We can be pretty certain that nobody is
upgrading from an older version to the upcoming v0.8.

Here we hence make the `payment_id` fields in `Event` required which is
a nice API simplification that will also be utilized in the next commit.

Co-Authored-By: HAL 9000
@tnull
tnull force-pushed the 2026-06-payment-id-prefactors branch from 452c643 to f96d289 Compare July 28, 2026 12:47
@tnull
tnull requested a review from tankyleo July 28, 2026 12:48
Gate manual claiming for unknown custom-hash BOLT11 payments
behind a config flag.

Nodes that do not opt in fail these payments back without storing or
queueing user events.

Co-Authored-By: HAL 9000
@tnull
tnull force-pushed the 2026-06-payment-id-prefactors branch from f96d289 to 748143c Compare July 28, 2026 13:20
Comment thread CHANGELOG.md
Comment thread src/payment/bolt11.rs
Comment thread src/config.rs
Comment thread src/config.rs Outdated
Comment thread src/event.rs Outdated
Comment thread src/event.rs
claim_deadline,
custom_records,
};
match self.event_queue.add_event(event).await {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also noted in the CHANGELOG.md, we could still reach this point with manually_claim_unknown_bolt11_payments = false if the user used the for_hash variants prior to upgrading past this commit.

Comment thread src/event.rs
@@ -1145,11 +1364,23 @@
// be the result of a replayed event.
),
Ok(DataStoreUpdateResult::NotFound) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a bug if we land here ? Or are we guarding against a possible crash before the persistence completes on PaymentClaimable ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note we also expose Node::remove_payment so we could always hit a case where the user for one reason or another prunes payment entries from their payment store.

tnull added 5 commits July 29, 2026 11:15
Use a name that reflects both possible user actions for unknown
BOLT11 payments: either claim them with a preimage or fail them back.

Co-Authored-By: HAL 9000
Create inbound BOLT11 records from claimable and claimed events so
inbound payments can be tracked by the IDs emitted by LDK.

Generate outbound BOLT11 IDs from KeysManager entropy instead of
deriving them from the payment hash.

Co-Authored-By: HAL 9000
Keep outbound BOLT11 payments keyed by payment hash so repeated

attempts to pay the same invoice can still return DuplicatePayment.

Co-Authored-By: HAL 9000
Clarify that v0.7-or-earlier for-hash invoices can still emit
PaymentClaimable after upgrade regardless of the new config flag.

Co-Authored-By: HAL 9000
Cover manually claiming and failing BOLT11 for-hash invoices that
were created before upgrading, so the new ID-based APIs keep
handling legacy payment-hash IDs.

Co-Authored-By: HAL 9000
@tnull
tnull force-pushed the 2026-06-payment-id-prefactors branch from 748143c to 97b27d4 Compare July 29, 2026 10:00
@tnull
tnull requested a review from tankyleo July 29, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Track inbound payments by also unique payment IDs

4 participants