Skip to content

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

WIP, needs bitcoindevkit/bdk#2097

This PR adds a birthday to the wallet, as a BlockId. Block-by-Block and CBF scanning can use this as a hint to only scan from the birthday onwards, saving time and bandwidth on full-scans where the birthday is previously known.

Client code should be updated to automatically set the birthday when performing a full-scan.

TODO

  • Add new bitcoind_rpc example that uses the birthday as the start_height

@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 from 527a8d4 to 77e2d88 Compare January 16, 2026 23:13
@luisschwab luisschwab force-pushed the feat/wallet-birthday branch 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.

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.

3 participants