Bitcoin Forum
July 26, 2026, 08:14:03 AM *
News: Latest Bitcoin Core release: 31.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Question about getbestblockhash  (Read 73 times)
BlackHatCoiner (OP)
Legendary
*
Offline

Activity: 2100
Merit: 9953


Cross Chain Crypto Swap


View Profile
December 29, 2024, 01:36:35 PM
 #1

Command getbestblockhash returns the latest block hash that has been mined. But, in case of two blocks being broadcasted at the same time, there are two chains, with the same height, and the next block will determine which one has the most work (AKA, is the right one).

My question is: How does getbestblockhash determine what is the best block hash in that case? Is best block hash the first that the node receives, and ignores the rest that come later? Shouldn't it return an array of best block hashes since there is potentially more than one?

 
 b1exch.to 
  ETH      DAI   
  BTC      LTC   
  USDT     XMR    
.███████████▄▀▄▀
█████████▄█▄▀
███████████
███████▄█▀
█▀█
▄▄▀░░██▄▄
▄▀██▄▀█████▄
██▄▀░▄██████
███████░█████
█░████░█████████
█░█░█░████░█████
█░█░█░██░█████
▀▀▀▄█▄████▀▀▀
ranochigo
Legendary
*
Offline

Activity: 3178
Merit: 4512


View Profile
December 29, 2024, 01:58:46 PM
Merited by BlackHatCoiner (4)
 #2

The getbestblockhash by definition should only return the tip of the most work and fully validated chain. In this case for the same height, the block that has arrived earlier would be the best chain for your node. Since nodes can still propagate the headers of competing chain, you can still refer to getchaintips to observe blocks that are on competing chains.

Conventionally, Bitcoin Core has always considered whichever chain that has the highest work and arrived first to be the best.
BlackHatCoiner (OP)
Legendary
*
Offline

Activity: 2100
Merit: 9953


Cross Chain Crypto Swap


View Profile
December 29, 2024, 03:32:04 PM
 #3

The getbestblockhash by definition should only return the tip of the most work and fully validated chain.
If both chains have equal work, then there are either two tips, or no tips. Picking one would mean you're introducing subjectivity.

Quote
In this case for the same height, the block that has arrived earlier would be the best chain for your node.
But, why? It can very well be the other chain, the correct one, because miners mine on top of the other tip.

Quote
Since nodes can still propagate the headers of competing chain, you can still refer to getchaintips to observe blocks that are on competing chains.
I didn't know about getchaintips. Thank you. I think this answers my question.

 
 b1exch.to 
  ETH      DAI   
  BTC      LTC   
  USDT     XMR    
.███████████▄▀▄▀
█████████▄█▄▀
███████████
███████▄█▀
█▀█
▄▄▀░░██▄▄
▄▀██▄▀█████▄
██▄▀░▄██████
███████░█████
█░████░█████████
█░█░█░████░█████
█░█░█░██░█████
▀▀▀▄█▄████▀▀▀
ranochigo
Legendary
*
Offline

Activity: 3178
Merit: 4512


View Profile
December 29, 2024, 03:42:32 PM
Last edit: December 30, 2024, 10:15:59 AM by ranochigo
 #4

If both chains have equal work, then there are either two tips, or no tips. Picking one would mean you're introducing subjectivity.
Fully validated in that case. If there are any competing blocks at the same height, then Bitcoin Core doesn't immediately validate it until the competing block becomes the new longest chain or isn't validated at all if it becomes orphaned.
But, why? It can very well be the other chain, the correct one, because miners mine on top of the other tip.
Traditionally, the reference implementation is used for mining as well. Miners are thus mining directly ontop of the best tip and it's better to start work on a chaintip that is better propagated, in the view of the individual node. Since each node has no way of knowing what is the block that is seen (and currently worked on) by the majority, it's better to prefer the block that is seen first and not having to swap over when another block at the same height appears.

Note: I don't think this is the actual reason, but the actual reason should be just for the sake of simplicity. This was a conclusion that I made after some discussion and research previously.
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!