<p>It doesn’t matter if it’s the same or a different block, it’s still a double spend because both transactions spend the same coins.</p>
<p>In your example node B can’t include the transaction in the block because there are no coins to spend.</p>

CC BY-SA 4.0
2021-11-27T01:33:38.313Z
2021-11-27T01:33:38.313Z
Mike D
<blockquote>
<p>Node B accepts the new blockchain from Node A and now continues the chain by creating a new block, including the transaction it received earlier in the next block.</p>
</blockquote>
<p>When node B accepts the new block from node A, it removes from its mempool all unconfirmed transactions that appear in that block. Node B will only use remaining mempool transactions in its new block.</p>
<p>Node B, and all other nodes, would already have removed from their UTXO lists the inputs consumed by the transaction. This means any new block containing a transaction that attempts to consume the already consumed UTXOs would be seen as invalid.</p>
<p>If node B didn't remove a confirmed transaction from its mempool and produced another block containing a transaction already present in the blockchain, all other nodes would reject node B's new block and node B would not be able to spend the block reward.</p>

CC BY-SA 4.0
2021-11-27T14:01:05.743Z
2021-12-20T19:31:54.737Z
2021-12-20T19:31:54.737Z
RedGrittyBrick
<p>When someone is paid on the Bitcoin network, this happens via a transaction creating a new transaction output that locks funds to an output script the recipient can spend. Every full node on the network explicitly tracks all <em>Unspent Transaction Outputs (UTXOs)</em>. The <em>UTXO set</em> can be thought of as the ledger of all balances in Bitcoin, although they're tracked in the chunks as they were created rather than e.g. &quot;account balances&quot;.</p>
<p>When someone spends bitcoins, the transaction explicitly specifies which UTXOs it is spending. Each UTXO can only spent once in full. If there are any funds left over after paying the recipient(s), the sender assigns the remainder to one of their own addresses in a so-called <em>change output</em>.</p>
<p>Since UTXOs are uniquely identifiable via the transaction that created them and their position in the transaction's output list, i.e. the <em>outpoint</em> <code>txid:vout</code>, it is trivial for full nodes to determine whether funds are still available for spending. Likewise, when a transaction is included in a block that spends a specific UTXO, all full nodes update their UTXO set to mark that UTXO as spent. When a second transaction comes along trying to spend the same UTXO, it is discarded as invalid.</p>

CC BY-SA 4.0
2021-12-20T19:41:17.800Z
2021-12-20T19:41:17.800Z
Murch
<p>I'm sure I am missing something trivial here but I have a question.</p>
<p>Let's say there are Node A and Node B. We send a transaction to both nodes. Both nodes now contain an unconfirmed transaction in their local mempool.</p>
<p>Node A includes the transaction in the next block with a successful solution. Node B accepts the new block from Node A and continues the chain by creating another new block, including the transaction it received earlier in that next block.</p>
<p>So we have a situation where Node A included the transaction in the first block and Node B included the transaction in the second block. How is this prevented?</p>
<p>I am aware of double spending but the resources I have read usually talk about the same transaction being included in the next block of both nodes but, in that case, one of the blocks would just be discarded.</p>
<p>Thanks.</p>

<doublespend><utxo><block-validity>
What happens if a transaction is duplicated across different blocks?
RStevoUK
# What happens if a transaction is duplicated across different blocks?

(Asked by: username_0 on 2021-11-27)

I'm sure I am missing something trivial here but I have a question.

Let's say there are Node A and Node B. We send a transaction to both nodes. Both nodes now contain an unconfirmed transaction in their local mempool.

Node A includes the transaction in the next block with a successful solution. Node B accepts the new block from Node A and continues the chain by creating another new block, including the transaction it received earlier in that next block.

So we have a situation where Node A included the transaction in the first block and Node B included the transaction in the second block. How is this prevented?

I am aware of double spending but the resources I have read usually talk about the same transaction being included in the next block of both nodes but, in that case, one of the blocks would just be discarded.

Thanks.

**Tags:** doublespend, utxo, block-validity


---

## 3 answers

### Answer by username_1 on 2021-11-27. Score: 3

It doesn’t matter if it’s the same or a different block, it’s still a double spend because both transactions spend the same coins.

In your example node B can’t include the transaction in the block because there are no coins to spend.


---

### Answer by username_2 on 2021-11-27. Score: 1

> Node B accepts the new blockchain from Node A and now continues the chain by creating a new block, including the transaction it received earlier in the next block.

When node B accepts the new block from node A, it removes from its mempool all unconfirmed transactions that appear in that block. Node B will only use remaining mempool transactions in its new block.

Node B, and all other nodes, would already have removed from their UTXO lists the inputs consumed by the transaction. This means any new block containing a transaction that attempts to consume the already consumed UTXOs would be seen as invalid.

If node B didn't remove a confirmed transaction from its mempool and produced another block containing a transaction already present in the blockchain, all other nodes would reject node B's new block and node B would not be able to spend the block reward.


---

### Answer by username_3 on 2021-12-20. Score: 0

When someone is paid on the Bitcoin network, this happens via a transaction creating a new transaction output that locks funds to an output script the recipient can spend. Every full node on the network explicitly tracks all *Unspent Transaction Outputs (UTXOs)*. The *UTXO set* can be thought of as the ledger of all balances in Bitcoin, although they're tracked in the chunks as they were created rather than e.g. "account balances".

When someone spends bitcoins, the transaction explicitly specifies which UTXOs it is spending. Each UTXO can only spent once in full. If there are any funds left over after paying the recipient(s), the sender assigns the remainder to one of their own addresses in a so-called *change output*.

Since UTXOs are uniquely identifiable via the transaction that created them and their position in the transaction's output list, i.e. the *outpoint* `txid:vout`, it is trivial for full nodes to determine whether funds are still available for spending. Likewise, when a transaction is included in a block that spends a specific UTXO, all full nodes update their UTXO set to mark that UTXO as spent. When a second transaction comes along trying to spend the same UTXO, it is discarded as invalid.


---

