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.
NotifyAddressBookChanged(address, strName, is_mine,
                             strPurpose, (fUpdated ? CT_UPDATED  CT_NEW));
    if (!strPurpose.empty() && !batch.WritePurpose(EncodeDestination(address), strPurpose))
        return false;
    return batch.WriteName(EncodeDestination(address), strName);
}
bool CWalletSetAddressBook(const CTxDestination& address, const stdstring& strName, const stdstring& strPurpose)
{
    WalletBatch batch(GetDatabase());
    return SetAddressBookWithDB(batch, address, strName, strPurpose);
}
bool CWalletDelAddressBook(const CTxDestination& address)
{
    bool is_mine;
    WalletBatch batch(GetDatabase());
    {
        LOCK(cs_);
        //  we want to delete receiving addresses, we need to take care that DestData "used" (and possibly newer DestData) gets preserved (and the "deleted" address transformed into a change entry instead of actually being deleted)
        // NOTE This isn't a problem for sending addresses because they never have any DestData yet!
        // When adding new DestData, it should be considered here whether to retain or delete it (or move it?).
        if (IsMine(address)) {
            WalletLogPrintf("%s called with IsMine address, NOT SUPPORTED. Please report this bug! %s\n", __func__, PACKAGE_BUGREPORT);
            return false;
        }
        // Delete destdata tuples associated with address
        stdstring strAddress = EncodeDestination(address);
        for (const stdpair<const stdstring, stdstring> &item  m_address_book[address].destdata)
        {
            batch.EraseDestData(strAddress, item.first);
        }