When a block reward is spent together with other outputs in the wallet and that block reward is later orphaned, the wallet does not show the other funds as available anymore.  Even a `-rescan` is not enough - only `-zapwallettxes` or an explicit `abandontransaction` "recovers" the funds.  I prepared a [test case](https://github.com/domob1812/bitcoin/blob/wallet-bug-invalidated-block-rewards/test/functional/wallet_bug.py) that shows this behaviour.

Is this a known issue or the expected behaviour?  While this situation is something that will presumably not occur in practice (as it requires a long reorg), I wonder if that transaction should be automatically abandoned as it seems clear it won't be able to be confirmed anymore.
stdoptional<MigrationData> res = legacy_spkm->MigrateToDescriptor();
    if (res == stdnullopt) {
        error = _("Error Unable to produce s for this legacy . Make sure th is unlocked first");
        return stdnullopt;
    }
    return res;
}
bool CWalletApplyMigrationData(MigrationData& data, bilingual_str& error)
{
    AssertLockHeld(cs_);
    LegacyScriptPubKeyMan* legacy_spkm = GetLegacyScriptPubKeyMan();
    if (!legacy_spkm) {
        error = _("Error This  is already a  ");
        return false;
    }
    for (auto& desc_spkm  data.desc_spkms) {
        if (m_spk_managers.count(desc_spkm->GetID()) > 0) {
            error = _("Error Duplicate s created during migration. Your  may be corrupted.");
            return false;
        }
        m_spk_managers[desc_spkm->GetID()] = stdmove(desc_spkm);
    }
    // Remove the LegacyScriptPubKeyMan from disk
    if (!legacy_spkm->DeleteRecords()) {
        return false;
    }
    // Remove the LegacyScriptPubKeyMan from memory
    m_spk_managers.erase(legacy_spkm->GetID());
    m_external_spk_managers.clear();
    m_internal_spk_managers.clear();