Skip to content

Comments

feat!: add wallet birthday#368

Draft
luisschwab wants to merge 1 commit intobitcoindevkit:masterfrom
luisschwab:feat/wallet-birthday
Draft

feat!: add wallet birthday#368
luisschwab wants to merge 1 commit intobitcoindevkit:masterfrom
luisschwab:feat/wallet-birthday

Conversation

@luisschwab
Copy link
Member

@luisschwab luisschwab commented Jan 16, 2026

Closes #110.

TBD

@luisschwab luisschwab self-assigned this Jan 16, 2026
@luisschwab luisschwab moved this to In Progress in BDK Wallet Jan 16, 2026
@luisschwab luisschwab marked this pull request as draft January 16, 2026 22:53
@luisschwab luisschwab force-pushed the feat/wallet-birthday branch 2 times, most recently from 77e2d88 to 8ea292f Compare January 17, 2026 15:46
@luisschwab luisschwab added this to the Wallet 3.0.0 milestone Jan 18, 2026
@luisschwab luisschwab added the new feature New feature or request label Jan 18, 2026
@luisschwab luisschwab mentioned this pull request Jan 19, 2026
9 tasks
Comment on lines 170 to 178
/// Set the [`Wallet`]'s birthday, as a [`BlockId`].
///
/// The birthday can be used to limit how far back a chain oracle is queried,
/// saving up time and data bandwidth in full-scans.
pub fn birthday(mut self, birthday: BlockId) -> Self {
self.birthday = Some(birthday);
self
}

Copy link
Member Author

@luisschwab luisschwab Jan 21, 2026

Choose a reason for hiding this comment

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

I wonder if this should be public. It gives the user the freedom to set whatever value he wants, even if they're incorrect. @ValuedMammal or @evanlinjin can you shed some light on what would happen if I create a CheckPoint with a height+hash pair that doesn't exist on the chain, and then synched from genesis?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good question and probably requires testing before going ahead with this feature. The hope is that the bad block will be "reorged out" of the wallet, but that'll depend on which block IDs the chain source decides to return.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the best approach would be to not allow manually setting the birthday, and instead rely on the result of a full-scan to define it.

@ValuedMammal
Copy link
Collaborator

I was more in favor of the approach in #348 which provided an option on CreateParams to simply add a checkpoint to the local chain during Wallet creation.

@luisschwab
Copy link
Member Author

I was more in favor of the approach in #348 which provided an option on CreateParams to simply add a checkpoint to the local chain during Wallet creation.

Indeed, this would be a better flow, but may conflict with a possibly inexistent BlockId set during wallet creation. I need to do some testing to see what would happen.

@evanlinjin
Copy link
Member

I was more in favor of the approach in #348 which provided an option on CreateParams to simply add a checkpoint to the local chain during Wallet creation.

Indeed, this would be a better flow, but may conflict with a possibly inexistent BlockId set during wallet creation. I need to do some testing to see what would happen.

Some thoughts:

  • Birthdays are only useful for block-based chain sources.
  • bitcoind_rpc emitters trace back from a no-longer-existing-block to a block that is currently in chain (which is the correct behavior) - so no conflict at all!

The only fear is if the chain source has never even seen the no-longer-existing-block - in which case, the chain source starts syncing from genesis (as that would be the closest checkpoint that connects).

So if the user creates a wallet just before a reorg, that would be non-ideal.

My suggestion:

bitcoind_rpc::Emitter::new has a start_height parameter. This is used in the case the closest block that connects is below the start_height. So if the tip is reorged out, and we only have tip + genesis, we will start from start_height instead. To convey the wallet birthday with the checkpoint tip, while still taking into account reorgs, we can use tip_height - FINAL_DEPTH as the start_height parameter. FINAL_DEPTH can be as conservative as you want.

bitcoind_rpc::FilterIter::new does not have such a parameter. We can add it?

Then we provide docs as how to convey the wallet's birthday to the chain source using the checkpoint tip.

@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

❌ Patch coverage is 86.32479% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.98%. Comparing base (c1f052e) to head (41e5b65).

Files with missing lines Patch % Lines
src/wallet/error.rs 0.00% 8 Missing ⚠️
src/wallet/persisted.rs 0.00% 4 Missing ⚠️
src/wallet/changeset.rs 92.10% 3 Missing ⚠️
src/wallet/mod.rs 96.55% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #368      +/-   ##
==========================================
- Coverage   86.99%   86.98%   -0.02%     
==========================================
  Files          25       25              
  Lines        8860     8973     +113     
==========================================
+ Hits         7708     7805      +97     
- Misses       1152     1168      +16     
Flag Coverage Δ
rust 86.98% <86.32%> (-0.02%) ⬇️

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature New feature or request

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Add birthday to the wallet database

3 participants