Right now to recover from a backup with an encrypted HD wallet the user must do something like unlock the wallet with a really long time out and manually trigger a rescan,  otherwise they risk missing some keys when auto-topup cannot run.
if (m_attaching_chain) {
        return;
    }
    WalletBatch batch(GetDatabase());
    batch.WriteBestBlock(loc);
}
void CWalletSetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in)
{
    LOCK(cs_);
    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;
    }
}
stdset<uint256> CWalletGetConflicts(const uint256& txid) const
{
    stdset<uint256> result;
    AssertLockHeld(cs_);
    const auto it = mapWallet.find(txid);
    if (it == mapWallet.end())
        return result;
    const CWalletTx& wtx = it->second;
    stdpair<TxSpendsconst_iterator, TxSpendsconst_iterator> range;