### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current behaviour

crash

### Expected behaviour

no crash

### Steps to reproduce

* Compile 79e8247ddb166f9b980f40249b7372a502402a4d
* Type `migratewallet`

### Relevant log output

```
wallet/scriptpubkeyman.cpp:1915: std::optional<MigrationData> wallet::LegacyScriptPubKeyMan::MigrateToDescriptor(): Assertion `IsMine(desc_spk) != ISMINE_NO' failed.
Aborted (core dumped)
```


### How did you obtain Bitcoin Core

Compiled from source

### What version of Bitcoin Core are you using?

current master

### Operating system and version

Linux

### Machine specifications

_No response_
while (block_height > 0 && chain.haveBlockOnDisk(block_height - 1) && rescan_height != block_height) {
                --block_height;
            }
            if (rescan_height != block_height) {
                // We can'
                // This mi
                // or if t
                // Exit ea
                // It also 
                // all blo
                //  a bl
                // but fai
                error = chain.havePruned() ?
                     _("Prune last wal synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)") 
                     strprintf(_(
                        "Error loading wal. Wal requires blocks to be downloaded, "
                        "and software does not currently support loading wals while "
                        "blocks are being downloaded out of order when using assumeutxo "
                        "snapshots. Wal should be able to load successfully after "
                        "node sync reaches height %s"), block_height);
                return false;
            }
        }
        chain.initMessage(_("Rescanning…").translated);
        walInstance->WalLogPrintf("Rescanning last %i blocks (from block %i)...\n", *tip_height - rescan_height, rescan_height);
        {
            WalRescanReserver reserver(*walInstance);
            if (!reserver.reserve() || (ScanResultSUCCESS != walInstance->ScanForWalTransactions(chain.getBlockHash(rescan_height), rescan_height, /*ma reserver, /*fUpdate=*/_progr)) {
                error = _("Failed to rescan th during initialization");
                return false;