Repository: bitcoin/bitcoin
File: src/wallet/wallet.cpp (C++)

Code before:

        CKeyingMaterial plain_master_key;
        for (auto& [master_key_id, master_key] : mapMasterKeys)
        {
            if (!DecryptMasterKey(strOldWalletPassphrase, master_key, plain_master_key)) {
                return false;
            }
            if (Unlock(plain_master_key))
            {
                if (!EncryptMasterKey(strNewWalletPassphrase, plain_master_key, master_key)) {
                    return false;
                }
                WalletLogPrintf("Wallet passphrase changed to an nDeriveIterations of %i\n", master_key.nDeriveIterations);

                WalletBatch(GetDatabase()).WriteMasterKey(master_key_id, master_key);
                if (fWasLocked)
                    Lock();
                return true;
            }
        }
    }

    return false;
}

void CWallet::chainStateFlushed(ChainstateRole role, const CBlockLocator& loc)
{
    // Don't update the best block until the chain is attached so that in case of a shutdown,
    // the rescan will be restarted at next startup.
    if (m_attaching_chain || role == ChainstateRole::BACKGROUND) {
        return;
    }
    WalletBatch batch(GetDatabase());
    batch.WriteBestBlock(loc);
}

void CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in)
{
    LOCK(cs_wallet);
    if (nWalletVersion >= nVersion)
        return;
    WalletLogPrintf("Setting minversion to %d\n", nVersion);
    nWalletVersion = nVersion;

    {
        WalletBatch* batch = batch_in ? batch_in : new WalletBatch(GetDatabase());
        if (nWalletVersion > 40000)
            batch->WriteMinVersion(nWalletVersion);
        if (!batch_in)
            delete batch;
    }

Review comment (suggestion):
eecaca12f6979aefed51c7b19f886c9d7d4e9be4: Two calls to `chainStateFlushed` are left, in `MigrateLegacyToDescriptor` and `bench/wallet_migration.cpp`

Code after:
        Lock();

        CKeyingMaterial plain_master_key;
        for (auto& [master_key_id, master_key] : mapMasterKeys)
        {
            if (!DecryptMasterKey(strOldWalletPassphrase, master_key, plain_master_key)) {
                return false;
            }
            if (Unlock(plain_master_key))
            {
                if (!EncryptMasterKey(strNewWalletPassphrase, plain_master_key, master_key)) {
                    return false;
                }
                WalletLogPrintf("Wallet passphrase changed to an nDeriveIterations of %i\n", master_key.nDeriveIterations);

                WalletBatch(GetDatabase()).WriteMasterKey(master_key_id, master_key);
                if (fWasLocked)
                    Lock();
                return true;
            }
        }
    }

    return false;
}

void CWallet::SetLastBlockProcessedInMem(int block_height, uint256 block_hash)
{
    AssertLockHeld(cs_wallet);

    m_last_block_processed = block_hash;
    m_last_block_processed_height = block_height;
}

void CWallet::SetLastBlockProcessed(int block_height, uint256 block_hash)
{
    AssertLockHeld(cs_wallet);

    SetLastBlockProcessedInMem(block_height, block_hash);
    WriteBestBlock();
}

void CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in)
{
    LOCK(cs_wallet);
    if (nWalletVersion >= nVersion)
        return;
    WalletLogPrintf("Setting minversion to %d\n", nVersion);
    nWalletVersion = nVersion;

    {