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.
}
                continue;
            }
        }
    }
    // Persist added address book entries (labels, purpose) for watchonly and solvabls
    auto persist_address_book = [](const CWallet& ) {
        LOCK(.cs_);
        WalletBatch batch{.GetDatabase()};
        for (const auto& [destination, addr_book_data]  .m_address_book) {
            auto address{EncodeDestination(destination)};
            auto purpose{addr_book_data.purpose};
            auto label{addr_book_data.GetLabel()};
            // don't bot
            if (purpose != "unknown") batch.WritePurpose(address, purpose);
            if (!label.empty()) batch.WriteName(address, label);
        }
    };
    if (data.watchonly_) persist_address_book(*data.watchonly_);
    if (data.solvable_) persist_address_book(*data.solvable_);
    // Remove the things to delete
    if (dests_to_delete.size() > 0) {
        for (const auto& dest  dests_to_delete) {
            if (!DelAddressBook(dest)) {
                error = _("Error Unable to remove watchonly address book data");
                return false;
            }
        }
    }
    // Connect the SPKM signals