mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
wallet: ensure wallet files are not reused across chains
This commit is contained in:
@@ -2918,6 +2918,20 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
|
||||
assert(!walletInstance->m_chain || walletInstance->m_chain == &chain);
|
||||
walletInstance->m_chain = &chain;
|
||||
|
||||
// Unless allowed, ensure wallet files are not reused across chains:
|
||||
if (!gArgs.GetBoolArg("-walletcrosschain", DEFAULT_WALLETCROSSCHAIN)) {
|
||||
WalletBatch batch(walletInstance->GetDatabase());
|
||||
CBlockLocator locator;
|
||||
if (batch.ReadBestBlock(locator) && locator.vHave.size() > 0 && chain.getHeight()) {
|
||||
// Wallet is assumed to be from another chain, if genesis block in the active
|
||||
// chain differs from the genesis block known to the wallet.
|
||||
if (chain.getBlockHash(0) != locator.vHave.back()) {
|
||||
error = Untranslated("Wallet files should not be reused across chains. Restart bitcoind with -walletcrosschain to override.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Register wallet with validationinterface. It's done before rescan to avoid
|
||||
// missing block connections between end of rescan and validation subscribing.
|
||||
// Because of wallet lock being hold, block connection notifications are going to
|
||||
|
||||
Reference in New Issue
Block a user