-
Notifications
You must be signed in to change notification settings - Fork 158
Track inbound payments by PaymentId
#948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tnull
wants to merge
13
commits into
lightningdevkit:main
Choose a base branch
from
tnull:2026-06-payment-id-prefactors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4431b84
Make `payment_id` a required field in `Event`s
tnull 8302b2c
Add pending payment expiry metadata
tnull 64802f3
f Avoid cloning pending payment ids
tnull 59e9707
f Assert unique manual payment hashes
tnull d4e67d1
f Use enum pending expiries
tnull 4ef9c03
Add pending payment batch removal
tnull 4a62c03
Track manual BOLT11 invoices
tnull da39b52
f Reserve manual invoice hashes first
tnull ccd8971
f Batch-prune expired pending payments
tnull 1d29fcc
f Use claim-height pending expiry
tnull 16f33f1
f Keep pending index consistent on prune fail
tnull bf7aadb
Use payment IDs for BOLT11 payments
tnull 452c643
f Queue claim events before cleanup
tnull File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,11 +112,29 @@ where | |
| } | ||
|
|
||
| pub(crate) async fn remove(&self, id: &SO::Id) -> Result<(), Error> { | ||
| self.remove_batch(std::slice::from_ref(id)).await?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub(crate) async fn remove_batch(&self, ids: &[SO::Id]) -> Result<Vec<SO>, Error> { | ||
| let (removed_objects, result) = self.remove_batch_with_partial_result(ids).await; | ||
| result?; | ||
| Ok(removed_objects) | ||
| } | ||
|
|
||
| pub(crate) async fn remove_batch_with_partial_result( | ||
| &self, ids: &[SO::Id], | ||
| ) -> (Vec<SO>, Result<(), Error>) { | ||
| let _guard = self.mutation_lock.lock().await; | ||
| let should_remove = { self.objects.lock().expect("lock").contains_key(id) }; | ||
| if should_remove { | ||
| let mut removed_objects = Vec::new(); | ||
| for id in ids { | ||
| let should_remove = { self.objects.lock().expect("lock").contains_key(id) }; | ||
| if !should_remove { | ||
| continue; | ||
| } | ||
|
|
||
| let store_key = id.encode_to_hex_str(); | ||
| KVStore::remove( | ||
| let remove_result = KVStore::remove( | ||
| &*self.kv_store, | ||
| &self.primary_namespace, | ||
| &self.secondary_namespace, | ||
|
|
@@ -134,10 +152,16 @@ where | |
| e | ||
| ); | ||
| Error::PersistenceFailed | ||
| })?; | ||
| self.objects.lock().expect("lock").remove(id); | ||
| }); | ||
| if let Err(e) = remove_result { | ||
| return (removed_objects, Err(e)); | ||
| } | ||
|
|
||
| if let Some(object) = self.objects.lock().expect("lock").remove(id) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are here can we expect this to be |
||
| removed_objects.push(object); | ||
| } | ||
| } | ||
| Ok(()) | ||
| (removed_objects, Ok(())) | ||
| } | ||
|
|
||
| /// Returns the current in-memory object for `id`. | ||
|
|
@@ -422,6 +446,45 @@ mod tests { | |
| assert!(data_store.get(&new_id).is_none()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn batch_remove_removes_persisted_objects() { | ||
| let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new())); | ||
| let logger = Arc::new(TestLogger::new()); | ||
| let primary_namespace = "datastore_batch_remove_test_primary".to_string(); | ||
| let secondary_namespace = "datastore_batch_remove_test_secondary".to_string(); | ||
| let data_store: DataStore<TestObject, Arc<TestLogger>> = DataStore::new( | ||
| Vec::new(), | ||
| primary_namespace.clone(), | ||
| secondary_namespace.clone(), | ||
| Arc::clone(&store), | ||
| logger, | ||
| ); | ||
|
|
||
| let first = TestObject { id: TestObjectId { id: [1u8; 4] }, data: [23u8; 3] }; | ||
| let second = TestObject { id: TestObjectId { id: [2u8; 4] }, data: [42u8; 3] }; | ||
| let missing_id = TestObjectId { id: [3u8; 4] }; | ||
| assert_eq!(Ok(false), data_store.insert(first).await); | ||
| assert_eq!(Ok(false), data_store.insert(second).await); | ||
|
|
||
| assert_eq!( | ||
| Ok(vec![first, second]), | ||
| data_store.remove_batch(&[first.id, missing_id, second.id]).await | ||
| ); | ||
| assert_eq!(None, data_store.get(&first.id)); | ||
| assert_eq!(None, data_store.get(&second.id)); | ||
|
|
||
| for id in [first.id, second.id] { | ||
| assert!(KVStore::read( | ||
| &*store, | ||
| &primary_namespace, | ||
| &secondary_namespace, | ||
| &id.encode_to_hex_str() | ||
| ) | ||
| .await | ||
| .is_err()); | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn insert_does_not_mutate_memory_if_persist_fails() { | ||
| let id = TestObjectId { id: [42u8; 4] }; | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove_batchis really only used in tests at the moment, andfn removeabove, should we delete it and have justfn removeandfn remove_batch_with_partial_result?