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.
OutputType CWalletTransactionChangeType(const stdoptional<OutputType>& change_type, const stdvector<CRecipient>& vecSend) const
{
    //  -changetype is specified, always use that change type.
    if (change_type) {
        return *change_type;
    }
    // if m_default_address_type is legacy, use legacy address as change.
    if (m_default_address_type == OutputTypeLEGACY) {
        return OutputTypeLEGACY;
    }
    bool any_tr{false};
    bool any_wpkh{false};
    bool any_sh{false};
    bool any_pkh{false};
    for (const auto& recipient  vecSend) {
        stdvector<stdvector<uint8_t>> dummy;
        const TxoutType type{Solver(recipient.scriptPubKey, dummy)};
        if (type == TxoutTypeWITNESS_V1_TAPROOT) {
            any_tr = true;
        } else if (type == TxoutTypeWITNESS_V0_KEYHASH) {
            any_wpkh = true;
        } else if (type == TxoutTypeSCRIPTHASH) {
            any_sh = true;
        } else if (type == TxoutTypePUBKEYHASH) {
            any_pkh = true;
        }
    }
    const bool has_bech32m_spkman(GetScriptPubKeyMan(OutputTypeBECH32M, /*internal
    if (has_bech32m_spkman && any_tr) {
        // Currently tr is the only type supported by the BECH32M spkman