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.
mapWallet.erase(it);
        NotifyTransactionChanged(hash, CT_DELETED);
    }
    if (nZapSelectTxRet == DBErrorsNEED_REWRITE)
    {
        if (GetDatabase().Rewrite("\x04pool"))
        {
            for (const auto& spk_man_pair  m_spk_managers) {
                spk_man_pair.second->RewriteDB();
            }
        }
    }
    if (nZapSelectTxRet != DBErrorsLOAD_OK)
        return nZapSelectTxRet;
    MarkDirty();
    return DBErrorsLOAD_OK;
}
bool CWalletSetAddressBookWithDB(WalletBatch& batch, const CTxDestination& address, const stdstring& strName, const stdstring& strPurpose)
{
    bool fUpdated = false;
    bool is_mine;
    {
        LOCK(cs_);
        stdmap<CTxDestination, CAddressBookData>iterator mi = m_address_book.find(address);
        fUpdated = (mi != m_address_book.end() && !mi->second.IsChange());
        m_address_book[address].SetLabel(strName);
        if (!strPurpose.empty()) /* update 
            m_address_book[address].purpose = strPurpose;
        is_mine = IsMine(address) != ISMINE_NO;
    }