I'm curious about how Bitcoin nodes sync their time. There are delays within data transmission so if a node mines a block, how does the network determine whether it is the first?
1 Answer
Nodes determine which block is "first" based on whichever block they receive first.
Or in other words, the timestamp on a block is not used to determine which block a node will add to their blockchain; nodes simply add the first valid block they receive to their blockchain.
As a result, if two blocks are mined at the same time, it's possible that different nodes on the network will have different blocks at the top of their blockchain. To illustrate:
Node1 Node2
----- -----
[x] [y]
[c] [c]
[b] [b]
[a] [a]
- block
[x]
was mined "first" - block
[y]
was mined just after block[x]
- Due to network delays,
Node2
ends up receiving block[y]
first - Therefore, Node2 adds
[y]
to the top of their chain (but they also keep a copy of block|x|
)
So at this point in time, there is a disagreement about the state of the blockchain on the network. This happens.
This situation is resolved when a new block gets mined.
For example, if Node1
mines a new block on to their chain:
Node1
-----
[z]
[x]
[c]
[b]
[a]
This new block [z]
creates the new longest chain on the network. So when Node2
receives block [z]
, they will adopt the new longest chain:
Node1 Node2
----- -----
[z] [z]
[x] [x][y]
[c] [c]
[b] [b]
[a] [a]
...and the network is back in agreement about the state of the blockchain.
Summary:
The order of blocks (or which block is "first") is not determined by the timestamp on blocks relative to any network time.
Instead, nodes will add the first block they receive, and are free to disagree on which block is at the top of the chain. The order is resolved when a new block is mined, and all nodes adopt the longest known chain.
-
So, if I want to get a list of nodes ordered by the time when they mine a block, is this possible?– YangruiNov 2, 2016 at 3:24
-