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.
"Th might had been created on a newer version.\n"
                                "Please try running the latest software version.\n"), File);
            return nullptr;
        } else if (nLoadWalletRet == DBErrorsUNEXPECTED_LEGACY_ENTRY) {
            error = strprintf(_("Unexpected legacy entry in   found. Loading  %s\n\n"
                                "Th might have been tampered with or created with malicious intent.\n"), File);
            return nullptr;
        } else {
            error = strprintf(_("Error loading %s"), File);
            return nullptr;
        }
    }
    // This  is in its first run if there are no ScriptPubKeyMans and it isn't blank or no privkeys
    const bool fFirstRun = Instance->m_spk_managers.empty() &&
                     !Instance->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) &&
                     !Instance->IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET);
    if (fFirstRun)
    {
        // ensure this .dat can only be opened by clients supporting HD with chain split and expects no default key
        Instance->SetMinVersion(FEATURE_LATEST);
        Instance->InitWalletFlags(_creation_flags);
        // Only create LegacyScriptPubKeyMan when not  
        if (!Instance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
            Instance->SetupLegacyScriptPubKeyMan();
        }
        if ((_creation_flags & WALLET_FLAG_EXTERNAL_SIGNER) || !(_creation_flags & (WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET))) {
            LOCK(Instance->cs_);
            if (Instance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
                Instance->SetupDescriptorScriptPubKeyMans();
                // SetupDe