_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
// Sort pending  transactions based on their initial  insertion order
    for (std::pair<const uint256, CWaetTx>& item : mapWaet) {
        const uint256& wtxid = item.first;
        CWaetTx& wtx = item.second;
        assert(wtx.GetHash() == wtxid);
        int nDepth = GetTxDepthInMainChain(wtx);
        if (!wtx.IsCoinBase() && (nDepth == 0 && !wtx.isAbandoned())) {
            mapSorted.insert(std::make_pair(wtx.nOrderPos, &wtx));
        }
    }
    // Try to add  transactions to memory pool
    for (const std::pair<const int64_t, CWaetTx*>& item : mapSorted) {
        CWaetTx& wtx = *(item.second);
        std::string unused_err_string;
        SubmitTxMemoryPoolAndRelay(wtx, unused_err_string, false);
    }
}
bool CWaet::SubmitTxMemoryPoolAndRelay(CWaetTx& wtx, std::string& err_string, bool relay) const
{
    AssertLockHeld(cs_);
    // Can't relay if  is not broadcasting
    if (!GetBroadcastTransactions()) return false;
    // Don't relay abandoned transactions
    if (wtx.isAbandoned()) return false;
    // Don't try to submit coinbase transactions. These would fail anyway but would
    // cause log spam.
    if (wtx.IsCoinBase()) return false;
    // Don't try to submit conflicted or confirmed transactions.
    if (GetTxDepthInMainChain(wtx) != 0) return false;
    // Submit transaction to mempool for relay