lib: perform node-related bitcoind sanity checks before loading the wallet

We were checking the bitcoind version *after* trying to create a
watchonly wallet with a Miniscript descriptor, which defeats the purpose
of the check.

Fixes #284.
This commit is contained in:
Antoine Poinsot 2023-02-01 11:57:09 +01:00
parent 46de2e07a8
commit 9c7613fc14
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
2 changed files with 15 additions and 7 deletions

View File

@ -564,10 +564,9 @@ impl BitcoinD {
Ok(())
}
/// Perform various sanity checks on the bitcoind instance.
pub fn sanity_check(
/// Perform various non-wallet-related sanity checks on the bitcoind instance.
pub fn node_sanity_checks(
&self,
main_descriptor: &MultipathDescriptor,
config_network: bitcoin::Network,
) -> Result<(), BitcoindError> {
// Check the minimum supported bitcoind version
@ -591,6 +590,14 @@ impl BitcoinD {
));
}
Ok(())
}
/// Perform various sanity checks of our watchonly wallet.
pub fn wallet_sanity_checks(
&self,
main_descriptor: &MultipathDescriptor,
) -> Result<(), BitcoindError> {
// Check our watchonly wallet is loaded
if self
.list_wallets()

View File

@ -206,12 +206,13 @@ fn setup_bitcoind(
.ok_or(StartupError::MissingBitcoindConfig)?,
wo_path.to_str().expect("Must be valid unicode").to_string(),
)?;
bitcoind.node_sanity_checks(config.bitcoin_config.network)?;
if fresh_data_dir {
bitcoind.create_watchonly_wallet(&config.main_descriptor)?;
log::info!("Created a new watchonly wallet on bitcoind.");
}
bitcoind.maybe_load_watchonly_wallet()?;
bitcoind.sanity_check(&config.main_descriptor, config.bitcoin_config.network)?;
bitcoind.wallet_sanity_checks(&config.main_descriptor)?;
log::info!("Connection to bitcoind established and checked.");
Ok(bitcoind)
@ -635,10 +636,10 @@ mod tests {
}
});
complete_sanity_check(&server);
complete_wallet_creation(&server);
complete_wallet_loading(&server);
complete_version_check(&server);
complete_network_check(&server);
complete_wallet_creation(&server);
complete_wallet_loading(&server);
complete_wallet_check(&server, &wo_path);
complete_desc_check(&server, &receive_desc.to_string(), &change_desc.to_string());
complete_tip_init(&server);
@ -651,9 +652,9 @@ mod tests {
handle.shutdown();
});
complete_sanity_check(&server);
complete_wallet_loading(&server);
complete_version_check(&server);
complete_network_check(&server);
complete_wallet_loading(&server);
complete_wallet_check(&server, &wo_path);
complete_desc_check(&server, &receive_desc.to_string(), &change_desc.to_string());
complete_sync_check(&server);