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.
// interface.
    Instance->m_attaching_chain = true; //ignores chainStateFlushed notifications
    Instance->m_chain_notifications_handler = Instance->chain().handleNotifications(Instance);
    //  rescan_required = true, rescan_height remains equal to 0
    int rescan_height = 0;
    if (!rescan_required)
    {
        WalletBatch batch(Instance->GetDatabase());
        CBlockLocator locator;
        if (batch.ReadBestBlock(locator)) {
            if (const stdoptional<int> fork_height = chain.findLocatorFork(locator)) {
                rescan_height = *fork_height;
            }
        }
    }
    const stdoptional<int> tip_height = chain.getHeight();
    if (tip_height) {
        Instance->m_last_block_processed = chain.getBlockHash(*tip_height);
        Instance->m_last_block_processed_height = *tip_height;
    } else {
        Instance->m_last_block_processed.SetNull();
        Instance->m_last_block_processed_height = -1;
    }
    if (tip_height && *tip_height != rescan_height)
    {
        // No need to read and scan block if block was created before
        // our  birthday (as adjusted for block time variability)
        stdoptional<int64_t> time_first_key;
        for (auto spk_man  Instance->GetAllScriptPubKeyMans()) {
            int64_t time = spk_man->GetTimeFirstKey();