Hi, what happens if a double spent bitcoin gets merged with a valid bitcoin, and sent as 2 bitcoins to another address?
e.g.
valid_utxo1 +
invalid_utxo2
will it become an invalid transaction? if so, what happens to the original valid bitcoin? will it be assigned a new utxo? will the other address receive 1 bitcoin and not the doublespent one?
So, what is the immediate scenario and what is the scenario after say, 6 blocks?
Double-spends don't exist in the blockchain. They can't. That's the reason the blockchain exists in the first place.
Perhaps you are talking about two unconfirmed transactions that both spend the same UTXO?
As an example:
To begin with, a wallet has control of 2 valid, confirmed UTXO:
UTXO_A
UTXO_D
Unconfirmed Transaction 1
Spends UTXO_A
Creates UTXO_B
Unconfirmed Transaction 2
Spends UTXO_A
Creates UTXO_C
Transaction 3
Spends unconfirmed UTXO_B and confirmed UTXO_D
Creates UTXO_E
What happens if Transaction 2 is confirmed (and the block it is confirmed in does not get orphaned)?
Transaction 1 then becomes invalid and is dropped from the memory pool of all nodes that receive the block that confirmed Transaction 2. Essentially, Transaction 1 no longer exists. If the sender of Transaction 1 tries to re-broadcast the transaction, then all peers will reject the transaction as invalid and will refuse to relay it.
Since transaction 3 is attempting to spend a non-existent output (UTXO_B), it is an invalid transaction. Any peer that received the block that confirmed Transaction 2 will drop Transaction 3 from their memory pool. If the sender of Transaction 3 tries to re-broadcast the transaction, then all peers will reject the transaction as invalid and will refuse to relay it.
Since the entire network refuses to acknowledge Transaction 3 as valid, it won't be added to any blocks, and will be treated as if it simply doesn't exist.
Therefore UTXO_A remains spent (in Transaction 2), UTXO_C remains unspent and confirmed (in Transaction 2), UTXO_B doesn't exist (because Transaction 1 is invalid), UTXO_D remains unspent (because Transaction 3 is invalid), and UTXO_E doesn't exist (because Transaction 3 is invalid).