Skip to content
Open
7 changes: 7 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,13 @@ fn build_with_store_internal(
Arc::clone(&pending_payment_store),
));

// Fill the address pool up front so LDK's sync `SignerProvider` callbacks can hand out
// pre-persisted addresses without waiting on wallet persistence.
runtime.block_on(wallet.initialize_address_pool()).map_err(|e| {

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 parallelize the reads on startup.

IMO it would also preferable to keep up the pre-existing patterns of doing the read_ methods here in parallel, and then hand that in to initialize via an AddressPool::new or so rather than doing all/obfuscating in an initialize_ method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🤖 Done. The record read now runs in the tokio::join! with the other startup reads, its result is handed to Wallet::new, which validates it in AddressPool::new, and the builder only blocks on the initial pool top-up. One side effect: a failed read now fails the build with ReadFailed rather than WalletSetupFailed.

log_error!(logger, "Failed to initialize the wallet's address pool: {}", e);
BuildError::WalletSetupFailed
})?;

tx_broadcaster.set_wallet(Arc::downgrade(&wallet));

// Initialize the KeysManager
Expand Down
5 changes: 5 additions & 0 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ pub(crate) const BDK_WALLET_INDEXER_PRIMARY_NAMESPACE: &str = "bdk_wallet";
pub(crate) const BDK_WALLET_INDEXER_SECONDARY_NAMESPACE: &str = "";
pub(crate) const BDK_WALLET_INDEXER_KEY: &str = "indexer";

/// The derivation indices of the wallet's address pool will be persisted under this key.
pub(crate) const BDK_WALLET_ADDRESS_POOL_PRIMARY_NAMESPACE: &str = "bdk_wallet";
pub(crate) const BDK_WALLET_ADDRESS_POOL_SECONDARY_NAMESPACE: &str = "";
pub(crate) const BDK_WALLET_ADDRESS_POOL_KEY: &str = "address_pool";

/// [`StaticInvoice`]s will be persisted under this key.
///
/// [`StaticInvoice`]: lightning::offers::static_invoice::StaticInvoice
Expand Down
Loading