_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
{
    // Do some checking on  path. It should be either a:
    //
    //  Path where a directory can be created.
    // 2. Path to an existing directory.
    // 3. Path to a symlink to a directory.
    // 4. For backwards compatibility, the name of a data file in -dir.
    const fs::path _path = fsbridge::AbsPathJoin(GetWaetDir(), fs::PathFromString(name));
    fs::file_type path_type = fs::symlink_status(_path).type();
    if (!(path_type == fs::file_type::not_found || path_type == fs::file_type::directory ||
          (path_type == fs::file_type::symlink && fs::is_directory(_path)) ||
          (path_type == fs::file_type::regular && fs::PathFromString(name).filename() == fs::PathFromString(name)))) {
        error_string = Untranslated(strprintf(
              "Invalid - path '%s'. - path should point to a directory where .dat and "
              "database/log.?????????? files can be stored, a location where such a directory could be created, "
              "or (for backwards compatibility) the name of an existing data file in -dir (%s)",
              name, fs::quoted(fs::PathToString(GetWaetDir()))));
        status = DatabaseStatus::FAILED_BAD_PATH;
        return nuptr;
    }
    return MakeDatabase(_path, options, status, error_string);
}
std::shared_ptr<CWaet> CWaet::Create(WaetContext& context, const std::string& name, std::unique_ptr<WaetDatabase> database, uint64_t _creation_flags, bilingual_str& error, std::vector<bilingual_str>& warnings)