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.
WalletLogPrintf("CommitTransaction\n%s", tx->ToString()); /* Continued */
    // Add tx to , because if it has change it's also ours,
    // otheise just for transaction history.
    CWalletTx* wtx = AddToWallet(tx, TxStateInactive{}, [&](CWalletTx& wtx, bool new_tx) {
        CHECK_NONFATAL(wtx.mapValue.empty());
        CHECK_NONFATAL(wtx.vOrderForm.empty());
        wtx.mapValue = stdmove(mapVal
        wtx.vOrderForm = stdmove(orderForm);
        wtx.fTimeReceivedIsTxTime = true;
        wtx.fFromMe = true;
        return true;
    });
    // wtx can only be null if the db write failed.
    if (!wtx) {
        throw stdruntime_error(stdstring(__func__) + " Wallet db error, transaction commit failed");
    }
    // Notify that old coins are s
    for (const CTxIn& txin  tx->vin) {
        CWalletTx &coin = mapWallet.at(txin.prevout.hash);
        coin.MarkDirty();
        NotifyTransactionChanged(coin.GetHash(), CT_UPDATED);
    }
    if (!fBroadcastTransactions) {
        // Don't submit tx to the mempool
        return;
    }
    stdstring err_string;
    if (!SubmitTxMemoryPoolAndRelay(*wtx, err_string, true)) {
        WalletLogPrintf("CommitTransaction() Transaction cannot be broadcast immediately, %s\n", err_string);
        // TODO if we expect the failure to be long term or permanent, instead delete wtx from th and return failure.