Bitcoin Forum
April 16, 2024, 08:30:15 PM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How does the blockchain stay in sync?  (Read 1251 times)
purelithium (OP)
Hero Member
*****
Offline Offline

Activity: 504
Merit: 500



View Profile
July 13, 2012, 11:39:53 PM
 #1

I'm trying to figure out how all the different pools and miners stay in sync, how come none of them mine the same blocks?

Like my post? 1H7bfRYh7F89mfmFgsRCdn4awDaUHQmYqY
Each block is stacked on top of the previous one. Adding another block to the top makes all lower blocks more difficult to remove: there is more "weight" above each block. A transaction in a block 6 blocks deep (6 confirmations) will be very difficult to remove.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713299415
Hero Member
*
Offline Offline

Posts: 1713299415

View Profile Personal Message (Offline)

Ignore
1713299415
Reply with quote  #2

1713299415
Report to moderator
1713299415
Hero Member
*
Offline Offline

Posts: 1713299415

View Profile Personal Message (Offline)

Ignore
1713299415
Reply with quote  #2

1713299415
Report to moderator
DeathAndTaxes
Donator
Legendary
*
Offline Offline

Activity: 1218
Merit: 1079


Gerald Davis


View Profile
July 14, 2012, 12:17:18 AM
 #2

Because it is very hard to solve a block.
On average the entire network only solves one block every ten minutes.  This gives the network enough time to notify all nodes that a block has been found and when notified nodes beginning mining the next block.

However sometimes two miners/pools will solve a block at roughly the same time (within 3-5 seconds of each other) at which point the network is in conflict.  Eventually one of those chains will be extended another block and the competing block will be orphaned.

Example:
current block is #182800
Miner A & Miner B both solve block #182801
Miner A publishes it block to part of the network lets call it #182801-A.
Miner B publishes it block to part of the network lets call it #182801-B.
Each portion of the network mines to extend their version of the block chain. 
Say Miner C finds the next block (#182802) and it was using #182801-A as the prior block then #182801-B will be orphaned.

Scott J
Legendary
*
Offline Offline

Activity: 1792
Merit: 1000


View Profile
July 14, 2012, 12:21:55 AM
 #3

Because it is very hard to solve a block.
On average the entire network only solves one block every ten minutes.  This gives the network enough time to notify all nodes that a block has been found and when notified nodes beginning mining the next block.

However sometimes two miners/pools will solve a block at roughly the same time (within 3-5 seconds of each other) at which point the network is in conflict.  Eventually one of those chains will be extended another block and the competing block will be orphaned.

Example:
current block is #182800
Miner A & Miner B both solve block #182801
Miner A publishes it block to part of the network lets call it #182801-A.
Miner B publishes it block to part of the network lets call it #182801-B.
Each portion of the network mines to extend their version of the block chain. 
Say Miner C finds the next block (#182802) and it was using #182801-A as the prior block then #182801-B will be orphaned.
What would happen if two miners solved a block at exactly the same time?
mcorlett
Donator
Sr. Member
*
Offline Offline

Activity: 308
Merit: 250



View Profile
July 14, 2012, 12:27:46 AM
 #4

What would happen if two miners solved a block at exactly the same time?
One of them would become orphaned.

DeathAndTaxes
Donator
Legendary
*
Offline Offline

Activity: 1218
Merit: 1079


Gerald Davis


View Profile
July 14, 2012, 12:32:46 AM
Last edit: July 14, 2012, 12:49:24 AM by DeathAndTaxes
 #5

Quote
What would happen if two miners solved a block at exactly the same time?

0s or 0.1s, or 1.2s it doesn't really matter*.  When a miner solves a block he broadcasts it to his peers and those peers to their peers and those peers to their peers until every node knows about the new block.  From the period of time between a block being found and every node being aware of the block it is possible for another node to be unaware that block is already solved and two competing blocks to be produced.  If two miners broadcast competing blocks to the network before all the nodes are aware of the new block(s) then the network will temporarily be in conflict.  

If two blocks are found at the same time the same h  Until every node has been notified about a new block the potential for a race exists.  Some nodes will believe "a" is the correct next block and some will believe "b" is the correct next block.  The network resolves that conflict by the outcome of the next block.  If an "a" supported solves the next block then "a" becomes part of the longest chain and "b" is orphaned.  If an "b" supported solves the next block then "b" becomes part of the longest chain and "a" is orphaned.

Remember this is pretty rare only about 1% or so of blocks end up in a "race" with a competitor.  That critical window only lasts a few seconds.  Major pools an incentive to minimize orphaned blocks, because orphaned blocks produce no revenue.  The easiest way is to have a huge number of peers so within the latency of one connection they have already notified a significant fraction of the network.



* Technically the more of a head start one block has the more time it has to notify the network before the other block is found.  So the difference in time between the two blocks does affect the outcome of who wins the race but not the chance of a race itself. If 70% of the network hashing power considers "a" to be the next block and only 30% considers "b" to the next block then "a" has a 70% chance to win the race.
Scott J
Legendary
*
Offline Offline

Activity: 1792
Merit: 1000


View Profile
July 14, 2012, 12:43:46 AM
 #6

Thanks for the explanation.
Koooooj
Member
**
Offline Offline

Activity: 75
Merit: 10



View Profile
July 14, 2012, 07:15:17 PM
 #7

This may be getting too technical, but can't a block be orphaned before the next block is found?  It's my understanding that when a mining node hears about two blocks that are both the same number (e.g. 182801), it will immediately reject the one that has the larger hash (lower effective difficulty).  Miners accept the chain with the largest proof of work, which is the largest sum of difficulties.  In the example described, the block is not orphaned until the block competing with it gets a block built on it, and then the race is immediately over. Isn't there the possibility for a race between two chains to go for more than one block (although it is highly unlikely)?  For example, I remember reading about a ~50 block orphaned chain in Litecoin a few weeks ago.  Bitcoin is probably past the point of having an orphaned chain longer than one, but I find the theory interesting.
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1025



View Profile WWW
July 15, 2012, 10:03:26 AM
Last edit: July 15, 2012, 10:21:09 AM by deepceleron
 #8

This may be getting too technical, but can't a block be orphaned before the next block is found?  It's my understanding that when a mining node hears about two blocks that are both the same number (e.g. 182801), it will immediately reject the one that has the larger hash (lower effective difficulty).  Miners accept the chain with the largest proof of work, which is the largest sum of difficulties.  In the example described, the block is not orphaned until the block competing with it gets a block built on it, and then the race is immediately over. Isn't there the possibility for a race between two chains to go for more than one block (although it is highly unlikely)?  For example, I remember reading about a ~50 block orphaned chain in Litecoin a few weeks ago.  Bitcoin is probably past the point of having an orphaned chain longer than one, but I find the theory interesting.

Bitcoin communicates both transactions and new blocks over the p2p network by relaying - the passing of messages to all other connected Bitcoins. This is how they "stay in sync".

The first sentence could be rewritten to be correct: "a block can be orphaned when the next block is found." If two block solutions are both published on the Bitcoin network, the solution the next miner uses when they find another block will be the one that becomes part of the block chain. The other is orphaned, that block's miner(s) gets no reward.

I was previously corrected in thinking the hash size matters (although I still haven't looked at code for myself). I think an instance of Bitcoin just uses the first block that it receives from the p2p network as the one to build on. Since relaying happens quickly on Bitcoin, the block that is orphaned was likely found after the one accepted anyway.

Orphaned chains are usually just one block. When BIP16 happened, there were often two blocks orphaned in a chain from two different versions of Bitcoin on the network playing by different rules (an old Bitcoin would build on another's bad block, and then the whole thing would get tossed by the whole network upon the next valid block).

The alternate chains have a low hashrate, so it is relatively easy for a single actor to develop a long blockchain fork by themselves, longer than the rest of the whole network, and publish it all at once.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!