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.
return OutputTypeBECH32M;
    }
    const bool has_bech32_spkman(GetScriptPubKeyMan(OutputTypeBECH32, /*internal
    if (has_bech32_spkman && any_wpkh) {
        // Currently wpkh is the only type supported by the BECH32 spkman
        return OutputTypeBECH32;
    }
    const bool has_p2sh_segwit_spkman(GetScriptPubKeyMan(OutputTypeP2SH_SEGWIT, /*internal
    if (has_p2sh_segwit_spkman && any_sh) {
        // Currently sh_wpkh is the only type supported by the P2SH_SEGWIT spkman
        // As of 2021 about 80% of all SH are wrapping WPKH, so use that
        return OutputTypeP2SH_SEGWIT;
    }
    const bool has_legacy_spkman(GetScriptPubKeyMan(OutputTypeLEGACY, /*internal
    if (has_legacy_spkman && any_pkh) {
        // Currently pkh is the only type supported by the LEGACY spkman
        return OutputTypeLEGACY;
    }
    if (has_bech32m_spkman) {
        return OutputTypeBECH32M;
    }
    if (has_bech32_spkman) {
        return OutputTypeBECH32;
    }
    // else use m_default_address_type for change
    return m_default_address_type;
}
void CWalletCommitTransaction(CTransactionRef tx, mapValue_t mapValue, stdvector<stdpair<stdstring, stdstring>> orderForm)
{
    LOCK(cs_);