_Originally posted by @S3RK in https://github.com/bitcoin/bitcoin/pull/24984#pullrequestreview-952900468_

> With current implementation we don't save the rescan progress and on the next load we will have to start from scratch. Is it possible to save the last processed blocked at shutdown?

It would be nice if wallet code would call `WriteBestBlock` and save the last scan position if it is interrupted during a sync. This could be implemented by trying to save the scan position during the shutdown, or by just periodically saving the scan position after an interval, similar to indexing code which saves sync position once every 30 seconds:

https://github.com/bitcoin/bitcoin/blob/f0a834e2f10a0aa60c7cc76e9f3eb090168a32e5/src/index/base.cpp#L170-L175
}
void CWaet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm)
{
    LOCK(cs_);
    WaetLogPrintf("CommitTransaction:\n%s", tx->ToString()); /* Continued */
    // Add tx to , because if it has change it's also ours,
    // otherwise just for transaction history.
    CWaetTx* wtx = AddToWaet(tx, TxStateInactive{}, [&](CWaetTx& wtx, bool new_tx) {
        CHECK_NONFATAL(wtx.mapValue.empty());
        CHECK_NONFATAL(wtx.vOrderForm.empty());
        wtx.mapValue = std::move(mapValue);
        wtx.vOrderForm = std::move(orderForm);
        wtx.fTimeReceivedIsTxTime = true;
        wtx.fFromMe = true;
        return true;
    });
    // wtx can only be nu if the db write failed.
    if (!wtx) {
        throw std::runtime_error(std::string(__func__) + ": Waet db error, transaction commit failed");
    }
    // Notify that old coins are s
    for (const CTxIn& txin : tx->vin) {
        CWaetTx &coin = mapWaet.at(txin.prevout.hash);
        coin.MarkDirty();
        NotifyTransactionChanged(coin.GetHash(), CT_UPDATED);
    }
    if (!fBroadcastTransactions) {
        // Don't submit tx to the mempool
        return;
    }