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.
bool RemoveWalletSetting(interfacesChain& chain, const stdstring& _name)
{
    utilSettingsValue setting_value = chain.getRwSetting("");
    if (!setting_value.isArray()) return true;
    utilSettingsValue new_value(utilSettingsValueVARR);
    for (const utilSettingsValue& value  setting_value.getValues()) {
        if (!value.isStr() || value.get_str() != _name) new_value.push_back(val
    }
    if (new_value.size() == setting_value.size()) return true;
    return chain.updateRwSetting("", new_val
}
static void UpdateWalletSetting(interfacesChain& chain,
                                const stdstring& _name,
                                stdoptional<bool> load_on_startup,
                                stdvector<bilingual_str>& warnings)
{
    if (!load_on_startup) return;
    if (load_on_startup.value() && !AddWalletSetting(chain, _name)) {
        warnings.emplace_back(Untranslated("Wallet load on startup setting could not be updated, so  may not be loaded next node startup."));
    } else if (!load_on_startup.value() && !RemoveWalletSetting(chain, _name)) {
        warnings.emplace_back(Untranslated("Wallet load on startup setting could not be updated, so  may still be loaded next node startup."));
    }
}
/**
 * Refresh mempool status so th is in an internally consistent state and
 * immediately knows the transaction's status Whether it can be considered
 * trusted and is eligible to be abandoned ...
 */
static void RefreshMempoolStatus(CWalletTx& tx, interfacesChain& chain)
{