6

Let's say two miners created 2 different blocks and broadcast them into the network. Now some clients see blockchain 1 and other blockchain 2 which are different from each other.
I would like to understand technically as possible how in the end the majority of clients will continue with only single chain and the other be abandoned?
Why will they choose one over the other?
I would like to believe this is done automatically by the clients / miners without human touch, only by some kind of coded logic. That logic is what I'm after.

Related question: What happens to extinct blockchains, and transactions inside of them?

1
  • a.k.a. An orphaned block. A valid block that achieved some network propagation but a "better" block came along at the same time and took over.
    – George
    May 6, 2015 at 20:30

2 Answers 2

10

You're looking for CBlockIndexWorkComparator, which operates by three rules. The rules are applied one at a time, and if a rule leads to a tie, then the next rule is applied.

  • Which blockchain has the most work?
  • Which one was received first? (This can be different for different clients, which is why the previous rule is applied first.)
  • Which one has a larger pointer address? (This is largely random, and different for different clients.)
6
  • 1
    Please explain the meaning of the 3rd rule. May 7, 2015 at 12:24
  • 2
    @HaddarMacdasi Programs on a computer use memory, and pointers tell the program where it can find the data it wants to see. What pointer address each one gets is decided by a memory allocator, which is usually part of the operating system. The purpose of this rule is to provide a tie-breaker that can always break ties.
    – Nick ODell
    May 7, 2015 at 13:43
  • If clients will get into deciding the chain to go with based on the 3rd rule, which has I understand is just like flipping a coin, won't the decision splits again 50% going with the 1st chain an the rest with the 2nd ? May 7, 2015 at 14:07
  • 1
    @HaddarMacdasi Exactly. But that split won't last forever, because of rule #1. Eventually some miner will win.
    – Nick ODell
    May 7, 2015 at 14:21
  • 1
    The third rule only applies to old blocks, loaded from disk. It should never affect the outcome on the network, because as soon as a block is received from the network, the second rule takes precedence (one block must have been received before another). Aug 28, 2018 at 18:09
4

This is explained in the Bitcoin paper:

Nodes always consider the longest chain to be the correct one and will keep working on extending it. If two nodes broadcast different versions of the next block simultaneously, some nodes may receive one or the other first. In that case, they work on the first one they received, but save the other branch in case it becomes longer. The tie will be broken when the next proof-of-work is found and one branch becomes longer; the nodes that were working on the other branch will then switch to the longer one.

The idea is that it's quite rare for the network to find 2 different blocks at around the same time. If it happens, you'll have peers working on one chain and others on the other. It becomes even rarer for it to happen in succession, so it's just a matter of time that the network will converge on a single chain.

Your Answer

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

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