<p>First, a quick overview of what happens when you submit a transaction to the network:</p>

<ul>
<li>Each node that hears about your transaction will check to see if it is valid according to their view of the network. If it is valid, the node may broadcast the transaction to its peers, and may add the transaction to its local mempool. If it is invalid, the transaction will be discarded (not broadcast further, not stored in the mempool).</li>
<li>At some point, a miner's node will hear about your transaction. If it is valid and the fee-rate is sufficient, then the miner will add it to the block template that they are mining on.</li>
<li>If the miner finds a block that includes your transaction, then we say the transaction is 'confirmed'. As this block propogates across the network, individual nodes will check to ensure it is valid, and then update their local copy of the blockchain (and their mempool) appropriately. </li>
</ul>

<p>With that in mind, lets look at your questions:</p>

<blockquote>
  <p>1) Will every mining node that read from the pool both these 2 transactions discard the second one ? So as to put in a block only the first transaction (the correct one)</p>
</blockquote>

<p>No, because the mining node will have no way to determine which transaction was truly 'first'. Many nodes follow a 'first seen' policy to determine which transaction they will broadcast and store, but given the choice between the two transactions, a miner <em>could</em> include either one. </p>

<blockquote>
  <p>2) Suppose that for some reasons a mining node A mines the first transaction in a block and propagate its blockchain to the network. At the same time a mining node B mines the second transaction in another block and propagates its blockchain to the network. This creates a fork in the blockchain. Will the other nodes of the network simply reject the B's blockchain because they know that transaction T1 is the correct one ?</p>
</blockquote>

<p>This situation leads to what is referred to as a <a href="https://bitcoin.stackexchange.com/questions/tagged/stale-block?tab=Votes">stale block</a> (or sometimes, and orphan block). Nodes will store both blocks, and it will not be clear which block will be the 'winner' until a miner finds another block, that builds off one of the two blocks in question. </p>

<p>The other block will be discarded, and so if there are conflicting transactions (that spend the same input) in each block, it is only when one chain is extended that it will become clear which transaction will be included in the blockchain history. </p>

<p>Blockchain reorganizations like this are the reason for the often-cited <a href="https://bitcoin.stackexchange.com/questions/1170/why-is-6-the-number-of-confirms-that-is-considered-secure">'6 block confirmation'</a> recommendation when receiving a transaction. </p>

<blockquote>
  <p>3) To me it seems impossible that double spending can happen, every node will almost immediately read transactions T1 and T2 from the pool and discard T2, or discard a block if it contains T2. So i don't understand the need for waiting for 6 confirmations to be sure a transaction is correct.</p>
</blockquote>

<p>A certain output can only be spent once in the blockchain record, this is guaranteed by the network's consensus rules. So a 'double-spend' usually involves some trickery to defraud a transaction's recipient, by convincing them to accept a transaction that will not ultimately end up in the blockchain record. For example:</p>

<ul>
<li>Attacker sends txA to victim, while also creating txB that spends the same coins back to the attacker. Victim accepts the unconfirmed transaction, and releases payment/goods to the attacker. Later, txB is confirmed in a block, so the victim doesn't receive payment (txA is now invalid).</li>
<li>Attacker sends txA to an exchange, while mining a block with txB (spending coins back to attacker, as above). txA confirms in a block, so the exchange credits the attackers account balance, and the attacker quickly withdraws coins (receiving a new UTXO on chain). At the same time, the attacker hopes to mine more blocks than the rest of the network, so that they can publish their longer chain (that includes txB instead of txA), and thus have txA erased from the blockchain history. This would leave the exchange without their deposit, but the attacker would still receive the withdrawal (since it would likely come from an unrelated UTXO that the exchange owned). </li>
</ul>

<p>Thus, the 6 confirmation recommendation (see the link above for more info). Also worth noting: the 6 block confirmation rule is important even in cases where someone is not actively trying to defraud you: stale blocks happen naturally, so by waiting for multiple confirmations you help ensure you don't accept a transaction that is included in a block that doesn't end up in the eventual longest chain. </p>

CC BY-SA 4.0
2019-12-01T02:56:01.403Z
2019-12-01T03:17:21.200Z
2019-12-01T03:17:21.200Z
chytrik
<p>Let’s suppose you have 1 BTC which you try to spend twice.</p>

<p>You made the 1 BTC transaction to a merchant (Transaction T1). Now, you again sign and send the same 1 BTC on another Bitcoin address to try and trick the merchant (Transaction T2).</p>

<p>1) Will every mining node that read from the pool both these 2 transactions discard the second one ? So as to put in a block only the first transaction (the correct one)</p>

<p>2) Suppose that for some reasons a mining node A mines the first transaction  in a block and propagate its blockchain to the network. At the same time a mining node B mines the second transaction in another block and propagates its blockchain to the network. This creates a fork in the blockchain. Will the other nodes of the network simply reject the B's blockchain because they know that transaction T1 is the correct one ?</p>

<p>3) To me it seems impossible that double spending can happen, every node will almost immediately read transactions T1 and T2 from the pool and discard T2, or discard a block if it contains T2. So i don't understand the need for waiting for 6 confirmations to be sure a transaction is correct.</p>

<transactions><blockchain><blockchain-fork><doublespend>
Understand double spending through an example
AleWolf
# Understand double spending through an example

(Asked by: username_0 on 2019-11-30)

Let’s suppose you have 1 BTC which you try to spend twice.

You made the 1 BTC transaction to a merchant (Transaction T1). Now, you again sign and send the same 1 BTC on another Bitcoin address to try and trick the merchant (Transaction T2).

1) Will every mining node that read from the pool both these 2 transactions discard the second one ? So as to put in a block only the first transaction (the correct one)

2) Suppose that for some reasons a mining node A mines the first transaction in a block and propagate its blockchain to the network. At the same time a mining node B mines the second transaction in another block and propagates its blockchain to the network. This creates a fork in the blockchain. Will the other nodes of the network simply reject the B's blockchain because they know that transaction T1 is the correct one ?

3) To me it seems impossible that double spending can happen, every node will almost immediately read transactions T1 and T2 from the pool and discard T2, or discard a block if it contains T2. So i don't understand the need for waiting for 6 confirmations to be sure a transaction is correct.

**Tags:** transactions, blockchain, blockchain-fork, doublespend


---

## 1 answers

### Answer by username_1 on 2019-12-01. Score: 2

First, a quick overview of what happens when you submit a transaction to the network:

* Each node that hears about your transaction will check to see if it is valid according to their view of the network. If it is valid, the node may broadcast the transaction to its peers, and may add the transaction to its local mempool. If it is invalid, the transaction will be discarded (not broadcast further, not stored in the mempool).
* At some point, a miner's node will hear about your transaction. If it is valid and the fee-rate is sufficient, then the miner will add it to the block template that they are mining on.
* If the miner finds a block that includes your transaction, then we say the transaction is 'confirmed'. As this block propogates across the network, individual nodes will check to ensure it is valid, and then update their local copy of the blockchain (and their mempool) appropriately.

With that in mind, lets look at your questions:

> 1) Will every mining node that read from the pool both these 2 transactions discard the second one ? So as to put in a block only the first transaction (the correct one)

No, because the mining node will have no way to determine which transaction was truly 'first'. Many nodes follow a 'first seen' policy to determine which transaction they will broadcast and store, but given the choice between the two transactions, a miner *could* include either one.

> 2) Suppose that for some reasons a mining node A mines the first transaction in a block and propagate its blockchain to the network. At the same time a mining node B mines the second transaction in another block and propagates its blockchain to the network. This creates a fork in the blockchain. Will the other nodes of the network simply reject the B's blockchain because they know that transaction T1 is the correct one ?

This situation leads to what is referred to as a [stale block](https://bitcoin.stackexchange.com/questions/tagged/stale-block?tab=Votes) (or sometimes, and orphan block). Nodes will store both blocks, and it will not be clear which block will be the 'winner' until a miner finds another block, that builds off one of the two blocks in question.

The other block will be discarded, and so if there are conflicting transactions (that spend the same input) in each block, it is only when one chain is extended that it will become clear which transaction will be included in the blockchain history.

Blockchain reorganizations like this are the reason for the often-cited ['6 block confirmation'](https://bitcoin.stackexchange.com/questions/1170/why-is-6-the-number-of-confirms-that-is-considered-secure) recommendation when receiving a transaction.

> 3) To me it seems impossible that double spending can happen, every node will almost immediately read transactions T1 and T2 from the pool and discard T2, or discard a block if it contains T2. So i don't understand the need for waiting for 6 confirmations to be sure a transaction is correct.

A certain output can only be spent once in the blockchain record, this is guaranteed by the network's consensus rules. So a 'double-spend' usually involves some trickery to defraud a transaction's recipient, by convincing them to accept a transaction that will not ultimately end up in the blockchain record. For example:

* Attacker sends txA to victim, while also creating txB that spends the same coins back to the attacker. Victim accepts the unconfirmed transaction, and releases payment/goods to the attacker. Later, txB is confirmed in a block, so the victim doesn't receive payment (txA is now invalid).
* Attacker sends txA to an exchange, while mining a block with txB (spending coins back to attacker, as above). txA confirms in a block, so the exchange credits the attackers account balance, and the attacker quickly withdraws coins (receiving a new UTXO on chain). At the same time, the attacker hopes to mine more blocks than the rest of the network, so that they can publish their longer chain (that includes txB instead of txA), and thus have txA erased from the blockchain history. This would leave the exchange without their deposit, but the attacker would still receive the withdrawal (since it would likely come from an unrelated UTXO that the exchange owned).

Thus, the 6 confirmation recommendation (see the link above for more info). Also worth noting: the 6 block confirmation rule is important even in cases where someone is not actively trying to defraud you: stale blocks happen naturally, so by waiting for multiple confirmations you help ensure you don't accept a transaction that is included in a block that doesn't end up in the eventual longest chain.


---

