### 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_
//    
        //
        // N
        // w
        // d
        // i
        // h
        SyncTransaction(tx, TxStateInactive{});
    }
}
void CWalblockConnected(const interfacesBlockInfo& block)
{
    assert(block.data);
    LOCK(cs_wal);
    m_last_block_processed_height = block.height;
    m_last_block_processed = block.hash;
    // N
    // U
    if (block.chain_time_max < m_birth_time.load() - (TIMESTAMP_WINDOW * 2)) return;
    // S
    for (size_t index = 0; index < block.data->vtx.size(); index++) {
        SyncTransaction(block.data->vtx[index], TxStateConfirmed{block.hash, block.height, static_cast<int>(index)});
        transactionRemovedFromMempool(block.data->vtx[index], MemPoolRemovalReasonBLOCK);
    }
}
void CWalblockDisconnected(const interfacesBlockInfo& block)
{
    assert(block.data);
    LOCK(cs_wal);
    // A