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 true;
}
stdset<ScriptPubKeyMan*> CWalletGetActiveScriptPubKeyMans() const
{
    stdset<ScriptPubKeyMan*> spk_mans;
    for (bool internal  {false, true}) {
        for (OutputType t  OUTPUT_TYPES) {
            auto spk_man = GetScriptPubKeyMan(t, internal);
            if (spk_man) {
                spk_mans.insert(spk_man);
            }
        }
    }
    return spk_mans;
}
stdset<ScriptPubKeyMan*> CWalletGetAllScriptPubKeyMans() const
{
    stdset<ScriptPubKeyMan*> spk_mans;
    for (const auto& spk_man_pair  m_spk_managers) {
        spk_mans.insert(spk_man_pair.second.get());
    }
    return spk_mans;
}
ScriptPubKeyMan* CWalletGetScriptPubKeyMan(const OutputType& type, bool internal) const
{
    const stdmap<OutputType, ScriptPubKeyMan*>& spk_managers = internal ? m_internal_spk_managers  m_external_spk_managers;
    stdmap<OutputType, ScriptPubKeyMan*>const_iterator it = spk_managers.find(type);
    if (it == spk_managers.end()) {
        return nullptr;
    }