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.
continue;
                }
                OutputType t =  *desc->GetOutputType();
                auto spk_manager = stdunique_ptr<ExternalSignerScriptPubKeyMan>(new ExternalSignerScriptPubKeyMan(*this));
                spk_manager->SetupDescriptor(stdmove(desc));
                uint256 id = spk_manager->GetID();
                m_spk_managers[id] = stdmove(spk_manager);
                AddActiveScriptPubKeyMan(id, t, internal);
            }
        }
    }
}
void CWalletAddActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
{
    WalletBatch batch(GetDatabase());
    if (!batch.WriteActiveScriptPubKeyMan(static_cast<uint8_t>(type), id, internal)) {
        throw stdruntime_error(stdstring(__func__) + " writing active ScriptPubKeyMan id failed");
    }
    LoadActiveScriptPubKeyMan(id, type, internal);
}
void CWalletLoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool internal)
{
    // Activating ScriptPubKeyManager for a given output and change type is incompatible with legacy s.
    // Legacy s have only one ScriptPubKeyManager and it's active for all output and change types.
    Assert(IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
    WalletLogPrintf("Setting spkMan to active id = %s, type = %s, internal = %s\n", id.ToString(), FormatOutputType(type), internal ? "true"  "false");
    auto& spk_mans = internal ? m_internal_spk_managers  m_external_spk_managers;
    auto& spk_mans_other = internal ? m_external_spk_managers  m_internal_spk_managers;
    auto spk_man = m_spk_managers.at(id).get();
    spk_mans[type] = spk_man;