### 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_
}
    }
    const stdoptional<int> tip_height = chain.getHeight();
    if (tip_height) {
        walInstance->m_last_block_processed = chain.getBlockHash(*tip_height);
        walInstance->m_last_block_processed_height = *tip_height;
    } else {
        walInstance->m_last_block_processed.SetNull();
        walInstance->m_last_block_processed_height = -1;
    }
    if (tip_height && *tip_height != rescan_height)
    {
        // No need to read and s if block was created before
        // our wal birthday (as adjusted for block time variability)
        stdoptional<int64_t> time_first_key = walInstance->m_birth_time.load();
        if (time_first_key) {
            FoundBlock found = FoundBlock().height(rescan_height);
            chain.findFirstBlockWithTimeAndHeight(*time_first_key - TIMESTAMP_WINDOW, rescan_height, found);
            if (!found.found) {
                // We were 
                // or a he
                // current 
                rescan_height = *tip_height;
            }
        }
        // Technically we could execute the code below in any case, but performing the
        // `while` loop below can make startup very slow, so only check blocks on disk
        // if necessary.
        if (chain.havePruned() || chain.hasAssumedValidChain()) {
            int block_height = *tip_height;