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.
int submitted_tx_count = 0;
    { // cs_ scope
        LOCK(cs_);
        // First filter for the transactions we want to rebroadcast.
        // We use a set with WalletTxOrderComparator so that rebroadcasting occurs in insertion order
        stdset<CWalletTx*, WalletTxOrderComparator> to_submit;
        for (auto& [txid, wtx]  mapWallet) {
            // Only re
            if (!wtx.isUnconfirmed()) continue;
            // Attempt 
            // the las
            if (!force && wtx.nTimeReceived > m_best_block_time - 5 * 60) continue;
            to_submit.insert(&wtx);
        }
        // Now try submitting the transactions to the memory pool and (optionally) relay them.
        for (auto wtx  to_submit) {
            stdstring unused_err_string;
            if (SubmitTxMemoryPoolAndRelay(*wtx, unused_err_string, relay)) ++submitted_tx_count;
        }
    } // cs_
    if (submitted_tx_count > 0) {
        WalletLogPrintf("%s resubmit %u unconfirmed transactions\n", __func__, submitted_tx_count);
    }
}
/** @} */  mapWallet
void MaybeResendWalletTxs(WalletContext& context)
{
    for (const stdshared_ptr<CWallet>& p  GetWallets(context)) {
        if (!p->ShouldResend()) continue;
        p->ResubmitWalletTransactions(/*relay=*/rce