Here in the function AttachChain there is block of code:

    // 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;

I've seen the CBlockLocator contructor and with no argument, it does nothing so the vHave member of locator is always empty. So next if statement will never execute because:

batch.ReadBestBlock(locator) && locator.vHave.size() > 0 && chain.getHeight()

Is alway false. I think I'm missing something here, because if I'm correct the if statement is like if(0) and so it's not useful.

1 Answer 1


ReadBestBlock doesn't look at the locator it is given, rather it reads a specific record from the wallet database and loads the data into the provided locator. locator is used as an output parameter.

ReadBestBlock returns true when it successfully finds a record and reads it, and it returns false if there is an error. So this code checks that the reading of the best block record was successful and that the read locator has data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.