_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
bool CanGetAddresses(bool internal = false) const;
    /**
     * Blocks until the wallet state is up-to-date to /at least/ the current
     * chain at the time this function is entered
     * Obviously holding cs_main/cs_wallet when going into this call may cause
     * deadlock
     */
    void BlockUntilSyncedToCurrentChain() const LOCKS_EXCLUDED(::cs_main) EXCLUSIVE_LOCKS_REQUIRED(!cs_wallet);
    
    void SetWalletFlag(uint64_t flags);
    
    void UnsetWalletFlag(uint64_t flag);
    
    bool IsWalletFlagSet(uint64_t flag) const override;
    /** overwrite all flags by the given uint64_t
       returns false if unknown, non-tolerable flags are present */
    bool AddWalletFlags(uint64_t flags);
    
    bool LoadWalletFlags(uint64_t flags);
    
    bool IsLegacy() const;
    
    const std::string GetDisplayName() const override {
        std::string wallet_name = GetName().length() == 0 ? "default wallet" : GetName();
        return strprintf("[%s]", wallet_name);
    };
    
    template<typename... Params>
    void WalletLogPrintf(std::string fmt, Params... parameters) const {