Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,12 @@ impl Wallet {
let genesis_hash = params
.genesis_hash
.unwrap_or(genesis_block(network).block_hash());
let (chain, chain_changeset) = LocalChain::from_genesis_hash(genesis_hash);
let (mut chain, chain_changeset) = LocalChain::from_genesis_hash(genesis_hash);
if let Some(birthday) = params.birthday {
Copy link
Contributor

Choose a reason for hiding this comment

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

How will this interact with Esplora or Electrum syncing? I do wonder if we could at least limit how far we go back in full-scan syncing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this should have no effect. Both sources are based on script pub keys and I am under the impression the different between sync and full scan should only be a matter of how many scripts are queried. I may be wrong but perhaps @oleonardolima knows more precisely.

chain
.apply_update(CheckPoint::new(birthday))
.expect("wallet birthday overrides genesis hash.");
}

let (descriptor, mut descriptor_keymap) = (params.descriptor)(&secp, network_kind)?;
check_wallet_descriptor(&descriptor)?;
Expand Down
13 changes: 12 additions & 1 deletion src/wallet/params.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloc::boxed::Box;

use bdk_chain::keychain_txout::DEFAULT_LOOKAHEAD;
use bdk_chain::{keychain_txout::DEFAULT_LOOKAHEAD, BlockId};
use bitcoin::{BlockHash, Network, NetworkKind};
use miniscript::descriptor::KeyMap;

Expand Down Expand Up @@ -65,6 +65,7 @@ pub struct CreateParams {
pub(crate) change_descriptor_keymap: KeyMap,
pub(crate) network: Network,
pub(crate) genesis_hash: Option<BlockHash>,
pub(crate) birthday: Option<BlockId>,
pub(crate) lookahead: u32,
pub(crate) use_spk_cache: bool,
}
Expand All @@ -88,6 +89,7 @@ impl CreateParams {
change_descriptor_keymap: KeyMap::default(),
network: Network::Bitcoin,
genesis_hash: None,
birthday: None,
lookahead: DEFAULT_LOOKAHEAD,
use_spk_cache: false,
}
Expand All @@ -110,6 +112,7 @@ impl CreateParams {
change_descriptor_keymap: KeyMap::default(),
network: Network::Bitcoin,
genesis_hash: None,
birthday: None,
lookahead: DEFAULT_LOOKAHEAD,
use_spk_cache: false,
}
Expand All @@ -135,6 +138,7 @@ impl CreateParams {
change_descriptor_keymap: KeyMap::default(),
network: Network::Bitcoin,
genesis_hash: None,
birthday: None,
lookahead: DEFAULT_LOOKAHEAD,
use_spk_cache: false,
}
Expand Down Expand Up @@ -162,6 +166,13 @@ impl CreateParams {
self
}

/// Begin wallet scanning from the specified birthday. Particularly useful for block-based
/// scanning sources.
pub fn birthday(mut self, birthday: BlockId) -> Self {
self.birthday = Some(birthday);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, it's kind of odd to having to always having to remember the birthday outside of the wallet and setting it on CreateParams. Shouldn't the wallet itself also remember its birthday, and would it need to be persisted as part of the ChangeSet?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that it's a better idea to persist the birthday in the ChangeSet, but that'd make it a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One can either immediately persist the change using take_staged, in which case they would use LoadParams next time they interact with the wallet, or they can wait for a sync result, in which case they persist and would also use LoadParams. The birthday is no longer required as long as the persistence succeeds.

self
}

/// Use a custom `lookahead` value.
///
/// The `lookahead` defines a number of script pubkeys to derive over and above the last
Expand Down
Loading