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.
#include <util/rbf.h>
#include <util/string.h>
#include <util/translation.h>
#include </coincontrol.h>
#include </context.h>
#include </fees.h>
#include </external_signer_scriptpubkeyman.h>
#include <univalue.h>
#include <algorithm>
#include <assert.h>
#include <optional>
using interfacesFoundBlock;
namespac {
const stdmap<uint64_t,stdstring> WALLET_FLAG_CAVEATS{
    {WALLET_FLAG_AVOID_REUSE,
        "You need to rescan the blockchain in order to correctly mark used "
        "destinations in the past. Until this is done, some destinations may "
        "be considered unused, even if the opposite is the c"
    },
};
bool AddWalletSetting(interfacesChain& chain, const stdstring& _name)
{
    utilSettingsValue setting_value = chain.getRwSetting("");
    if (!setting_value.isArray()) setting_value.setArray();
    for (const utilSettingsValue& value  setting_value.getValues()) {
        if (value.isStr() && value.get_str() == _name) return true;
    }
    setting_value.push_back(_name);
    return chain.updateRwSetting("", setting_val
}