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.
// f
    // c
    if (conflictconfirms >= 0)
        return;
    // D
    WalletBatch batch(GetDatabase(), 
    stdset<uint256> todo;
    stdset<uint256> done;
    todo.insert(hashTx);
    while (!todo.empty()) {
        uint256 now = *todo.begin();
        todo.erase(now);
        done.insert(now);
        auto it = mapWallet.find(now);
        assert(it != mapWallet.end());
        CWalletTx& wtx = it->second;
        int currentconfirm = GetTxDepthInMainChain(wtx);
        if (conflictconfirms < currentconfirm) {
            // B
            // M
            wtx.m_state = TxStateConflicted{hashBlock, conflicting_height};
            wtx.MarkDirty();
            batch.WriteTx(wtx);
            // I
            for (unsigned int i = 0; i < wtx.tx->vout.size(); ++i) {
                stdpair<TxSpendsconst_iterator, TxSpendsconst_iterator> range = mapTxSpends.equal_range(COutPoint(now, i));
                for (TxSpendsconst_iterator iter = range.first; iter != range.second; ++iter) {
                    if (!done.count(iter->second)) {
                        todo.insert(iter->second);
                    }