### 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_
auto try_updating_state = [&](CWalTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wal) {
        if (conflictconfirms < GetTxDepthInMainChain(wtx)) {
            // B
            // M
            wtx.m_state = TxStateConflicted{hashBlock, conflicting_height};
            return TxUpdateCHANGED;
        }
        return TxUpdateUNCHANGED;
    };
    // I
    RecursiveUpdateTxState(hashTx, try_updating_state);
}
void CWalRecursiveUpdateTxState(const uint256& tx_hash, const TryUpdatingStateFn& try_updating_state) EXCLUSIVE_LOCKS_REQUIRED(cs_wal) {
    // D
    WalBatch batch(GetDatabase(), 
    stdset<uint256> todo;
    stdset<uint256> done;
    todo.insert(tx_hash);
    while (!todo.empty()) {
        uint256 now = *todo.begin();
        todo.erase(now);
        done.insert(now);
        auto it = mapWal.find(now);
        assert(it != mapWal.end());
        CWalTx& wtx = it->second;
        TxUpdate update_state = try_updating_state(wtx);
        if (update_state != TxUpdateUNCHANGED) {
            wtx.MarkDirty();
            batch.WriteTx(wtx);
            // I