mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
Merge bitcoin/bitcoin#18554: wallet: ensure wallet files are not reused across chains
5f213213cbtests: add tests for cross-chain wallet use prevention (Seibart Nedor)968765973bwallet: ensure wallet files are not reused across chains (Seibart Nedor) Pull request description: This implements a proposal in #12805 and is a rebase of #14533. This seems to be a working approach, but I'm not sure why the `p2p_segwit.py` functional test needed a change, so I'll look into it more. ACKs for top commit: achow101: ACK5f213213cbdongcarl: Code Review ACK5f213213cb[deleted]: tACK5f213213cbTree-SHA512: 2c934300f113e772fc31c16ef5588526300bbc36e4dcef7d77bd0760c5c8f0ec77f766b1bed5503eb0157fa26dc900ed54d2ad1b41863c1f736ce5c1f3b67bec
This commit is contained in:
@@ -2939,6 +2939,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