From 5c7817743da713aa809671ac7a089d6be662d88a Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Thu, 19 Nov 2026 11:33:16 +0100 Subject: [PATCH 1/2] Persist wallet birthday checkpoint at build When creating a new on-chain wallet, we insert a first checkpoint as its birthday, but never persisted it explicitly. It only reached the store because filling the address pool later in the build happens to flush the wallet's staged changes. Without that side effect, a node restarted before its first sync would reload the wallet at genesis and try to rescan the whole chain, which never succeeds against a pruned bitcoind. We now persist the wallet right after applying the checkpoint, failing the build if that doesn't succeed, so the birthday no longer depends on unrelated wallet persistence. Reported-by: vnprclanker Co-Authored-By: HAL 9000 --- src/builder.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/builder.rs b/src/builder.rs index a8cba83db3..9195f744fc 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1958,6 +1958,12 @@ fn build_with_store_internal( log_error!(logger, "Failed to apply checkpoint during wallet setup: {}", e); BuildError::WalletSetupFailed })?; + // Persist the checkpoint right away, as the wallet would otherwise reload at + // genesis if we're restarted before its first sync. + runtime.block_on(wallet.persist_async(&mut wallet_persister)).map_err(|e| { + log_error!(logger, "Failed to persist checkpoint during wallet setup: {}", e); + BuildError::WalletSetupFailed + })?; } wallet }, From 1eaaa384fb27e493fe7cd7699719eaf6966bd136 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Thu, 19 Nov 2026 11:33:16 +0100 Subject: [PATCH 2/2] Test wallet birthday survives early restart Nothing covered that a node restarted between its first build and its first wallet sync keeps the wallet birthday rather than rescanning from genesis. We add an integration test that builds a fresh node against bitcoind, drops it before it syncs, and checks that the rebuilt node doesn't pick up a payment confirmed before its birthday. Co-Authored-By: HAL 9000 --- tests/integration_tests_rust.rs | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/integration_tests_rust.rs b/tests/integration_tests_rust.rs index c831c98ade..75de49e482 100644 --- a/tests/integration_tests_rust.rs +++ b/tests/integration_tests_rust.rs @@ -9863,3 +9863,48 @@ async fn lsps2_service_funding_fee_does_not_spend_anchor_reserve() { client_node.stop().unwrap(); payer_node.stop().unwrap(); } + +#[tokio::test(flavor = "multi_thread", worker_threads = 1)] +async fn wallet_birthday_survives_restart_before_first_sync() { + let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + let chain_source = TestChainSource::BitcoindRpcSync(&bitcoind); + + // Learn one of the wallet's addresses via a throwaway node sharing the entropy. + let helper_config = random_config(); + let node_entropy = helper_config.node_entropy; + let helper_node = setup_node(&chain_source, helper_config); + let addr = helper_node.onchain_payment().new_address().unwrap(); + helper_node.stop().unwrap(); + + // Pay to the address before the node under test is first built, i.e., before its birthday. + let premine_amount_sat = 100_000; + premine_and_distribute_funds( + &bitcoind.client, + &electrsd.client, + vec![addr], + Amount::from_sat(premine_amount_sat), + ) + .await; + generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6).await; + + let mut config = random_config(); + config.node_entropy = node_entropy; + let build_node = || { + setup_builder!(builder, config.node_config); + configure_chain_source(&chain_source, &mut builder, &config); + builder.build(config.node_entropy.into()).unwrap() + }; + + // Build the node for the first time, but drop it before it ever syncs. + drop(build_node()); + + generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 1).await; + + let node = build_node(); + node.start().unwrap(); + node.sync_wallets().unwrap(); + + // A wallet that kept its birthday doesn't see the earlier payment. + assert_eq!(node.list_balances().total_onchain_balance_sats, 0); + node.stop().unwrap(); +}