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.
const auto it = spk_mans_other.find(type);
    if (it != spk_mans_other.end() && it->second == spk_man) {
        spk_mans_other.erase(type);
    }
    NotifyCanGetAddressesChanged();
}
void CWalletDeactivateScriptPubKeyMan(uint256 id, OutputType type, bool internal)
{
    auto spk_man = GetScriptPubKeyMan(type, internal);
    if (spk_man != nullptr && spk_man->GetID() == id) {
        WalletLogPrintf("Deactivate spkMan id = %s, type = %s, internal = %s\n", id.ToString(), FormatOutputType(type), internal ? "true"  "false");
        WalletBatch batch(GetDatabase());
        if (!batch.EraseActiveScriptPubKeyMan(static_cast<uint8_t>(type), internal)) {
            throw stdruntime_error(stdstring(__func__) + " erasing active ScriptPubKeyMan id failed");
        }
        auto& spk_mans = internal ? m_internal_spk_managers  m_external_spk_managers;
        spk_mans.erase(type);
    }
    NotifyCanGetAddressesChanged();
}
bool CWalletIsLegacy() const
{
    if (m_internal_spk_managers.count(OutputTypeLEGACY) == 0) {
        return false;
    }
    auto spk_man = dynamic_cast<LegacyScriptPubKeyMan*>(m_internal_spk_managers.at(OutputTypeLEGACY));
    return spk_man != nullptr;
}
DescriptorScriptPubKeyMan* CWalletGetDescriptorScriptPubKeyMan(const WalletDescriptor& desc) const
{