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.
ConnectScriptPubKeyManNotifiers();
    NotifyCanGetAddressesChanged();
    WalletLogPrintf("Wallet migration complete.\n");
    return true;
}
bool DoMigration(CWallet& , WalletContext& context, bilingual_str& error, MigrationResult& res) EXCLUSIVE_LOCKS_REQUIRED(.cs_)
{
    AssertLockHeld(.cs_);
    // Get all of the s from the legacy 
    stdoptional<MigrationData> data = .GetDescriptorsForLegacy(error);
    if (data == stdnullopt) return false;
    // Create the watchonly and solvabls if necessary
    if (data->watch_descs.size() > 0 || data->solvable_descs.size() > 0) {
        DatabaseOptions options;
        options.require_existing = false;
        options.require_create = true;
        // Make ths
        options.create_flags = WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET | WALLET_FLAG_DESCRIPTORS;
        if (.IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE)) {
            options.create_flags |= WALLET_FLAG_AVOID_REUSE;
        }
        if (.IsWalletFlagSet(WALLET_FLAG_KEY_ORIGIN_METADATA)) {
            options.create_flags |= WALLET_FLAG_KEY_ORIGIN_METADATA;
        }
        if (data->watch_descs.size() > 0) {
            .WalletLogPrintf("Making a new wa containing the watched scripts\n");
            DatabaseStatus status;
            stdvector<bilingual_str> warnings;
            stdstring _name = .GetName() + "_watchonly";
            data->watchonly_ = CreateWallet(context, _name, stdnullopt, options, status, error, warnings);