Skip to content

feat(wallet): add RestoreOptions to tune Wallet::restore batching#1923

Open
Forte11Cuba wants to merge 2 commits into
cashubtc:mainfrom
Forte11Cuba:feat/restore-options
Open

feat(wallet): add RestoreOptions to tune Wallet::restore batching#1923
Forte11Cuba wants to merge 2 commits into
cashubtc:mainfrom
Forte11Cuba:feat/restore-options

Conversation

@Forte11Cuba
Copy link
Copy Markdown
Contributor

Description

Makes Wallet::restore()'s batch size and gap limit configurable via a new RestoreOptions struct, as requested by @thesimplekid in the thread on #1914. Defaults match the NUT-13 spec recommendation (100 / 3), so existing callers see no behavior change.

Partial fix for #1914


Notes to the reviewers


Suggested CHANGELOG Updates

CHANGED

  • nostr_backup::RestoreOptions (feature nostr) renamed to BackupRestoreOptions to free the RestoreOptions name for the main wallet API.
  • Wallet::restore() is now a thin wrapper over the new Wallet::restore_with_opts(RestoreOptions::default()).

ADDED

  • cdk::wallet::RestoreOptions (re-exported from cdk_common::wallet) with tunable batch_size and max_gap.
  • Wallet::restore_with_opts(opts) for callers that want to override the NUT-13 defaults.

REMOVED

FIXED

  • Callers can now shrink batch_size to be gentler on rate-limited mints while the wallet is being restored.

Checklist

  • I followed the code style guidelines
  • I ran just quick-check before committing
  • If the Wallet API was modified (added/removed/changed), I have reflected those changes in the FFI bindings (crates/cdk-ffi)

@github-project-automation github-project-automation Bot moved this to Backlog in CDK Apr 22, 2026
Copy link
Copy Markdown
Collaborator

@thesimplekid thesimplekid left a comment

Choose a reason for hiding this comment

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

Think this is a useful addition just a few comments.

Comment thread crates/cdk-common/src/wallet/mod.rs Outdated
Comment on lines +315 to +320
///
/// Degenerate configurations (`batch_size == 0` and/or `max_gap == 0`) do
/// not panic but produce a scan that terminates without recovering proofs:
/// `max_gap == 0` skips the scan entirely, and `batch_size == 0` sends
/// empty requests until `max_gap` is reached. Both are configuration
/// errors; callers should use `Default` or positive values.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
///
/// Degenerate configurations (`batch_size == 0` and/or `max_gap == 0`) do
/// not panic but produce a scan that terminates without recovering proofs:
/// `max_gap == 0` skips the scan entirely, and `batch_size == 0` sends
/// empty requests until `max_gap` is reached. Both are configuration
/// errors; callers should use `Default` or positive values.

Comment thread crates/cdk-common/src/wallet/mod.rs Outdated
/// empty requests until `max_gap` is reached. Both are configuration
/// errors; callers should use `Default` or positive values.
#[derive(Debug, Clone)]
pub struct RestoreOptions {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe just call this NUT13Options so we don't have to rename the nostr at least in this PR?

Comment thread crates/cdk/src/wallet/mod.rs Outdated
Comment on lines +534 to +535
#[instrument(skip(self))]
pub async fn restore_with_opts(&self, opts: RestoreOptions) -> Result<Restored, Error> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We need to add new fns to the Wallet trait and then expose them in ffi as well.

@github-project-automation github-project-automation Bot moved this from Backlog to In progress in CDK Apr 22, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 72.36842% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.17%. Comparing base (8ce06b1) to head (9713d1c).

Files with missing lines Patch % Lines
crates/cdk-ffi/src/types/wallet.rs 0.00% 15 Missing ⚠️
crates/cdk-ffi/src/wallet.rs 0.00% 4 Missing ⚠️
crates/cdk-ffi/src/wallet_trait.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1923   +/-   ##
=======================================
  Coverage   65.16%   65.17%           
=======================================
  Files         330      330           
  Lines       56742    56818   +76     
=======================================
+ Hits        36976    37031   +55     
- Misses      19766    19787   +21     

☔ 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.

@thesimplekid thesimplekid force-pushed the feat/restore-options branch from 3c2c4ef to b729ad1 Compare May 13, 2026 12:44
@thesimplekid thesimplekid force-pushed the feat/restore-options branch 2 times, most recently from 2b1783f to 54276e4 Compare May 13, 2026 14:20
@thesimplekid thesimplekid force-pushed the feat/restore-options branch from 54276e4 to 9713d1c Compare May 14, 2026 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants