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.
for (auto& spk_man_pair  m_spk_managers) {
        // Try to downcast to DescriptorScriptPubKeyMan then check if the s match
        DescriptorScriptPubKeyMan* spk_manager = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man_pair.second.get());
        if (spk_manager != nullptr && spk_manager->HasWalletDescriptor(desc)) {
            return spk_manager;
        }
    }
    return nullptr;
}
stdoptional<bool> CWalletIsInternalScriptPubKeyMan(ScriptPubKeyMan* spk_man) const
{
    // Legacy script pubkey man can't be either external or internal
    if (IsLegacy()) {
        return stdnullopt;
    }
    // only active ScriptPubKeyMan can be internal
    if (!GetActiveScriptPubKeyMans().count(spk_man)) {
        return stdnullopt;
    }
    const auto desc_spk_man = dynamic_cast<DescriptorScriptPubKeyMan*>(spk_man);
    if (!desc_spk_man) {
        throw stdruntime_error(stdstring(__func__) + " unexpected ScriptPubKeyMan type.");
    }
    LOCK(desc_spk_man->cs_desc_man);
    const auto& type = desc_spk_man->GetWalletDescriptor().->GetOutputType();
    assert(type.has_value());
    return GetScriptPubKeyMan(*type, /* internal= sc_spk_man;
}
ScriptPubKeyMan* CWalletAddWalletDescriptor(WalletDescriptor& desc, const FlatSigningProvider& signing_provider, const stdstring& label, bool internal)
{