Skip to content

Conversation

@benthecarman
Copy link
Contributor

Allows for a paginated KV store for more efficient listing of keys so you don't need to fetch all at once. Uses monotonic counter or timestamp to track the order of keys and allow for pagination. The traits are largely just copy-pasted from ldk-server.

This also adds a PaginatedKVStoreSyncAdapter/PaginatedKVStoreAdapter so you can use a paginated kv store in contexts that expect a regular key value store.

Adds some basic tests that were generated using claude code.

@benthecarman benthecarman requested a review from tnull January 26, 2026 15:00
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Jan 26, 2026

👋 Thanks for assigning @tnull 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.

@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 64.42308% with 74 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.04%. Comparing base (3fee76b) to head (5160a11).

Files with missing lines Patch % Lines
lightning/src/util/persist.rs 51.33% 72 Missing and 1 partial ⚠️
lightning/src/util/test_utils.rs 98.27% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4347      +/-   ##
==========================================
- Coverage   86.08%   86.04%   -0.05%     
==========================================
  Files         156      156              
  Lines      102416   102624     +208     
  Branches   102416   102624     +208     
==========================================
+ Hits        88165    88298     +133     
- Misses      11759    11830      +71     
- Partials     2492     2496       +4     
Flag Coverage Δ
tests 86.04% <64.42%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


/// A token that can be used to retrieve the next set of keys.
/// The `String` is the last key from the current page and the `i64` is
/// the associated `time` used for ordering.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think most DBs are going to support this? "sort by the last-changed as of time X" isn't possible without storing what the last-updated time was prior to X when something is updated after X.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ldk-server does it based on creation_at not updated_at, will update the docs to make that more clear

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, do all of our backend storage things have a created-at time? I guess if you want it time-ordered you have to do it that way but it adds quite a requirement :/

Allows for a paginated KV store for more efficient listing of keys so
you don't need to fetch all at once. Uses monotonic counter or timestamp
to track the order of keys and allow for pagination. The traits are
largely just copy-pasted from ldk-server.

This also adds a PaginatedKVStoreSyncAdapter/PaginatedKVStoreAdapter so
you can use a paginated kv store in contexts that expect a regular key value store.

Adds some basic tests that were generated using claude code.
pub keys: Vec<String>,

/// A token that can be used to retrieve the next set of keys.
/// The `String` is the last key from the current page and the `i64` is
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure I understand why this field is here, honestly. This doc indicates that the first element is just repeating an entry from keys (why can't I just call keys.last()?) and the second element doesn't seem super useful either (is there some DB where we need it for some reason?)

/// when dealing with a large number of keys that cannot be efficiently retrieved all at once.
///
/// For an asynchronous version of this trait, see [`PaginatedKVStore`].
pub trait PaginatedKVStoreSync: Send + Sync {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why doesn't this just extend KVStoreSync? Seems weird to duplicate the interface.

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.

3 participants