3

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?

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).

Normally, if a miner node receives two transactions spending the same inputs, both transactions will be considered invalid and discarded.

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.

2

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.)

  • 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 Jun 21 '17 at 18:33
  • 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 Jun 21 '17 at 18:44
  • 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 Jun 21 '17 at 18:51
  • 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 Jun 21 '17 at 20:31
  • 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 Jun 21 '17 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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