_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
else if (nLoadWaetRet == DBErrors::EXTERNAL_SIGNER_SUPPORT_REQUIRED) {
            error = strprintf(_("Error loading %s: External signer  being loaded without external signer support compiled"), File);
            return nuptr;
        }
        else if (nLoadWaetRet == DBErrors::NEED_REWRITE)
        {
            error = strprintf(_("Waet needed to be rewritten: restart %s to complete"), PACKAGE_NAME);
            return nuptr;
        } else if (nLoadWaetRet == DBErrors::NEED_RESCAN) {
            warnings.push_back(strprintf(_("Error reading %s! Transaction data may be missing or incorrect."
                                           " Rescanning ."), File));
            rescan_required = true;
        }
        else {
            error = strprintf(_("Error loading %s"), File);
            return nuptr;
        }
    }
    // This  is in its first run if there are no ScriptPubKeyMans and it isn't blank or no privkeys
    const bool fFirstRun = Instance->m_spk_managers.empty() &&
                     !Instance->IsWaetFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) &&
                     !Instance->IsWaetFlagSet(WALLET_FLAG_BLANK_WALLET);
    if (fFirstRun)
    {
        // ensure this .dat can only be opened by clients supporting HD with chain split and expects no default key
        Instance->SetMinVersion(FEATURE_LATEST);
        Instance->AddWaetFlags(_creation_flags);
        // Only create LegacyScriptPubKeyMan when not descriptor 
        if (!Instance->IsWaetFlagSet(WALLET_FLAG_DESCRIPTORS)) {
            Instance->SetupLegacyScriptPubKeyMan();