### 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_
{
    m_best_block_time = GetTime();
}
void CWalBlockUntilSyncedToCurrentChain() const {
    AssertLockNotHeld(cs_wal);
    // S
    // c
    // f
    // a
    uint256 last_block_hash = WITH_LOCK(cs_wal, return m_last_block_processed);
    chain().waitForNotificationsTipChanged(last_block_hash);
}
// Note that this function doesn't distinguish between a 0-valued input,
// and a not-"is mine" (according to the filter) input.
CAmount CWalGetDebit(const CTxIn &txin, const isminefilter& filter) const
{
    {
        LOCK(cs_wal);
        const auto mi = mapWal.find(txin.prevout.hash);
        if (mi != mapWal.end())
        {
            const CWalTx& prev = (*mi).second;
            if (txin.prevout.n < prev.tx->vout.size())
                if (IsMine(prev.tx->vout[txin.prevout.n]) & filter)
                    return prev.tx->vout[txin.prevout.n].nValue;
        }
    }
    return 0;
}
isminetype CWalIsMine(const CTxOut& txout) const