<p>Blocks form a chain; each block contains a <code>prev</code> field containing the hash of the block that "precedes" it.  The two blocks Ma and Mb are incompatible (the block chain is not allowed to contain two conflicting transactions), so neither can precede the other.  Hence they must be a "fork"; two different blocks with the same common ancestor.  All other miners will have to decide which fork they want to mine on; e.g. whether they want to create a block whose <code>prev</code> field points to Ma or Mb's block.  It doesn't really matter in this case. </p>

<p>Say the next block is found by Mc and points to the Ma block.  Then the chain ending in Mc is longer, and the next miner will prefer to mine on that side of the fork.    After a few more iterations, it should be clear that the chain including Ma (which has transaction Ta) is longer, and will be preferred by miners from then on.  This means transaction Tb is now dead.  (Moreover, Mb doesn't get to collect their 12.5 BTC block reward, because the block that awards it only exists on a side chain which is dead.)</p>

CC BY-SA 3.0
2017-06-21T18:33:13.873Z
so the both block will propagate through the network and block chain have forked blocks in all the nodes?. and the time of average 10 min for finding the block is all about solving a block by a node or is it overall time for adding the block in the block chain by all the nodes , i.e completed block chain?
Laxmi Kadariya
CC BY-SA 3.0
2017-06-21T18:44:35.627Z
Right, all nodes will see both blocks.  The 10 minutes is the average time to solve a block; once that happens, the block is typically distributed to all other nodes in the network very quickly (which is part of why forks happen rarely).
Nate Eldredge
CC BY-SA 3.0
2017-06-21T18:51:57.333Z
so it is said that when a node receives a block , it will validate the blocks so here at some point one block will be already added to chain and when it receives another block with double spend transaction, won't it drop down the block instead of forking it?
Laxmi Kadariya
CC BY-SA 3.0
2017-06-21T20:31:44.540Z
Suppose blocks A,B contain conflicting transactions.  If B names A as its predecessor, then B is invalid and will be dropped.  If A,B both name C as their predecessor, then either one could be valid, and you have a fork.  The node will keep both blocks, at least for a while, because it doesn't know whether the next block D will name A as its predecessor, or B.
Nate Eldredge
CC BY-SA 3.0
2017-06-21T20:37:02.793Z
so does this mean block validation  by a node is only on checking its parent ?not whether the blocks contains the transaction that is invalid or not?
Laxmi Kadariya
CC BY-SA 3.0
2017-06-21T02:42:29.260Z
2017-06-21T02:42:29.260Z
Nate Eldredge
<p>In order to visualize the manner in which Bitcoin blocks and transactions "flow" through the network, they should be viewed as <em>propagating</em> through the P2P network. Connected peers (nodes) notify one another of new transactions and blocks, and peers can then ask for all of the transaction or block data (inventory).</p>

<p>In the double-spend example you give, where the double spend txns go to different miners, the transaction that is <em>confirmed first</em>, i.e. included in a valid block first by a miner, is considered valid by the network - provided the transaction and block is valid in all other respects. </p>

<p>The remaining transaction (even if it was broadcast first) will be deemed a double spend attempt according to the network's consensus rules because it spends the same outputs (UTXOs) as a transaction that has already been confirmed. Yet, since it was confirmed in a competing valid block (as per your example), this second (chronological) block will most likely be <em>orphaned</em>.</p>

<p>During the propagation of newly mined blocks they are subject to validation by peers. Peers (and, therefore, the network) will build consensus on the validity of two (or more) competing blocks and likely choose one - as described in the previous paragraph. In some cases, the chain may temporarily fork until subsequent mined blocks allow consensus to converge, in which case one chain will be orphaned in favor of the consensus branch.</p>

<p>It sounds overly complicated when discussed in this way, but the ever-shifting state of consensus eventually leads to convergence. This is why the blockchain is described as "slow" and "cumbersome", as it builds consensus on the validity of every transaction and every block.</p>

<p>There is a useful discussion of double-spending in <a href="https://bitcoin.stackexchange.com/questions/13370/how-do-i-detect-a-double-spend">this related question</a>.</p>

CC BY-SA 4.0
2017-06-21T02:56:49.213Z
2020-06-15T00:52:50.790Z
2020-06-15T00:52:50.790Z
venzen
<p>I was trying to learn about Bitcoin and its flow. Actually, I was stuck how the control flows in solving the double spend.</p>

<p>For eg. if T<sub>a</sub> and T<sub>b</sub> are a double spend of the same transaction with different outputs. These two transactions can flow through different path in the network, and assume flow in exactly opposite path. So T<sub>a</sub> reaches miner M<sub>a</sub> who creates a block and T<sub>b</sub> reaches another miner M<sub>b</sub>. Now, M<sub>a</sub> may solve the block with T<sub>a</sub> and M<sub>b</sub> with T<sub>b</sub>. Both start broadcasting the respective blocks with Ta and T<sub>b</sub> to be a part of block chain. </p>

<p>After some time in relay some node may get both transactions and find its invalid but here already the block are relayed.
What happens in such a case and how is the double spend resolved?</p>

<doublespend><blockchain-fork>
How does a double spend get resolved when two miners find conflicting blocks at the same time?
Laxmi Kadariya
# How does a double spend get resolved when two miners find conflicting blocks at the same time?

(Asked by: username_0 on 2017-06-21)

I was trying to learn about Bitcoin and its flow. Actually, I was stuck how the control flows in solving the double spend.

For eg. if Ta and Tb are a double spend of the same transaction with different outputs. These two transactions can flow through different path in the network, and assume flow in exactly opposite path. So Ta reaches miner Ma who creates a block and Tb reaches another miner Mb. Now, Ma may solve the block with Ta and Mb with Tb. Both start broadcasting the respective blocks with Ta and Tb to be a part of block chain.

After some time in relay some node may get both transactions and find its invalid but here already the block are relayed.
What happens in such a case and how is the double spend resolved?

**Tags:** doublespend, blockchain-fork


---

## 2 answers

### Answer by username_1 on 2017-06-21. Score: 3

Blocks form a chain; each block contains a `prev` field containing the hash of the block that "precedes" it. The two blocks Ma and Mb are incompatible (the block chain is not allowed to contain two conflicting transactions), so neither can precede the other. Hence they must be a "fork"; two different blocks with the same common ancestor. All other miners will have to decide which fork they want to mine on; e.g. whether they want to create a block whose `prev` field points to Ma or Mb's block. It doesn't really matter in this case.

Say the next block is found by Mc and points to the Ma block. Then the chain ending in Mc is longer, and the next miner will prefer to mine on that side of the fork. After a few more iterations, it should be clear that the chain including Ma (which has transaction Ta) is longer, and will be preferred by miners from then on. This means transaction Tb is now dead. (Moreover, Mb doesn't get to collect their 12.5 BTC block reward, because the block that awards it only exists on a side chain which is dead.)

> **Comments:**
> **username_0**: so the both block will propagate through the network and block chain have forked blocks in all the nodes?. and the time of average 10 min for finding the block is all about solving a block by a node or is it overall time for adding the block in the block chain by all the nodes , i.e completed block chain?  
> **username_1**: Right, all nodes will see both blocks.  The 10 minutes is the average time to solve a block; once that happens, the block is typically distributed to all other nodes in the network very quickly (which is part of why forks happen rarely).  
> **username_0**: so it is said that when a node receives a block , it will validate the blocks so here at some point one block will be already added to chain and when it receives another block with double spend transaction, won't it drop down the block instead of forking it?  
> **username_1**: Suppose blocks A,B contain conflicting transactions.  If B names A as its predecessor, then B is invalid and will be dropped.  If A,B both name C as their predecessor, then either one could be valid, and you have a fork.  The node will keep both blocks, at least for a while, because it doesn't know whether the next block D will name A as its predecessor, or B.  
> **username_0**: so does this mean block validation  by a node is only on checking its parent ?not whether the blocks contains the transaction that is invalid or not?  

---

### Answer by username_2 on 2017-06-21. Score: 3

In order to visualize the manner in which Bitcoin blocks and transactions "flow" through the network, they should be viewed as *propagating* through the P2P network. Connected peers (nodes) notify one another of new transactions and blocks, and peers can then ask for all of the transaction or block data (inventory).

In the double-spend example you give, where the double spend txns go to different miners, the transaction that is *confirmed first*, i.e. included in a valid block first by a miner, is considered valid by the network - provided the transaction and block is valid in all other respects.

The remaining transaction (even if it was broadcast first) will be deemed a double spend attempt according to the network's consensus rules because it spends the same outputs (UTXOs) as a transaction that has already been confirmed. Yet, since it was confirmed in a competing valid block (as per your example), this second (chronological) block will most likely be *orphaned*.

During the propagation of newly mined blocks they are subject to validation by peers. Peers (and, therefore, the network) will build consensus on the validity of two (or more) competing blocks and likely choose one - as described in the previous paragraph. In some cases, the chain may temporarily fork until subsequent mined blocks allow consensus to converge, in which case one chain will be orphaned in favor of the consensus branch.

It sounds overly complicated when discussed in this way, but the ever-shifting state of consensus eventually leads to convergence. This is why the blockchain is described as "slow" and "cumbersome", as it builds consensus on the validity of every transaction and every block.

There is a useful discussion of double-spending in [this related question](https://bitcoin.stackexchange.com/questions/13370/how-do-i-detect-a-double-spend).


---

