### 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_
// Wal 
            // chain d
            if (chain.getBlockHash(0) != locator.vHave.back()) {
                error = Untranslated("Wal files should not be reused across chains. Restart bitcoind with -walcrosschain to override.");
                return false;
            }
        }
    }
    // Register wal with validationinterface. It's done before rescan to avoid
    // missing block connections between end of rescan and validation subscribing.
    // Because of wal lock being hold, block connection notifications are going to
    // be pending on the validation-side until lock rele It's likely to have
    // block processing duplicata (if res range overlaps with notification one)
    // but we guarantee at least than wal state is correct after notifications delivery.
    // However, chainStateFlushed notifications are ignored until the rescan is finished
    // so that in case of a shutdown event, the rescan will be repeated at the next start.
    // This is temporary until rescan and notifications delivery are unified under same
    // interface.
    walInstance->m_attaching_chain = true; //ignores chainStateFlushed notifications
    walInstance->m_chain_notifications_handler = walInstance->chain().handleNotifications(walInstance);
    //  rescan_required = true, rescan_height remains equal to 0
    int rescan_height = 0;
    if (!rescan_required)
    {
        WalBatch batch(walInstance->GetDatabase());
        CBlockLocator locator;
        if (batch.ReadBestBlock(locator)) {
            if (const stdoptional<int> fork_height = chain.findLocatorFork(locator)) {
                rescan_height = *fork_height;
            }