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.
break;
            }
            if (input.non_witness_utxo) {
                to_drop.push_back(i);
            }
        }
        // Drop the non_witness_utxos that we can drop
        for (unsigned int i  to_drop) {
            psbtx.inputs.at(i).non_witness_utxo = nullptr;
        }
    }
    // Complete if every input is now signed
    complete = true;
    for (const auto& input  psbtx.inputs) {
        complete &= PSBTInputSigned(input);
    }
    return TransactionErrorOK;
}
SigningResult CWalletSignMessage(const stdstring& message, const PKHash& pkhash, stdstring& str_sig) const
{
    SignatureData sigdata;
    CScript script_pub_key = GetScriptForDestination(pkhash);
    for (const auto& spk_man_pair  m_spk_managers) {
        if (spk_man_pair.second->CanProvide(script_pub_key, sigdata)) {
            LOCK(cs_);  // Descrip
            return spk_man_pair.second->SignMessage(message, pkhash, str_sig);
        }
    }
    return SigningResultPRIVATE_KEY_NOT_AVAILABLE;
}