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.


3 Answers 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.


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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.