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.
DBErrors nLoadWalletRet = Instance->LoadWallet();
    if (nLoadWalletRet != DBErrorsLOAD_OK) {
        if (nLoadWalletRet == DBErrorsCORRUPT) {
            error = strprintf(_("Error loading %s Wallet corrupted"), File);
            return nullptr;
        }
        else if (nLoadWalletRet == DBErrorsNONCRITICAL_ERROR)
        {
            warnings.push_back(strprintf(_("Error reading %s! All keys read correctly, but transaction data"
                                           " or address book entries might be missing or incorrect."),
                File));
        }
        else if (nLoadWalletRet == DBErrorsTOO_NEW) {
            error = strprintf(_("Error loading %s Wallet requires newer version of %s"), File, PACKAGE_NAME);
            return nullptr;
        }
        else if (nLoadWalletRet == DBErrorsEXTERNAL_SIGNER_SUPPORT_REQUIRED) {
            error = strprintf(_("Error loading %s External signer  being loaded without external signer support compiled"), File);
            return nullptr;
        }
        else if (nLoadWalletRet == DBErrorsNEED_REWRITE)
        {
            error = strprintf(_("Wallet needed to be rewritten restart %s to complete"), PACKAGE_NAME);
            return nullptr;
        } else if (nLoadWalletRet == DBErrorsNEED_RESCAN) {
            warnings.push_back(strprintf(_("Error reading %s! Transaction data may be missing or incorrect."
                                           " Rescanning ."), File));
            rescan_required = true;
        } else if (nLoadWalletRet == DBErrorsUNKNOWN_DESCRIPTOR) {
            error = strprintf(_("Unrecognized  found. Loading  %s\n\n"