How does getbestblockhash work with competing blocks?

3 replies 211 views
dave.forkMember
Posts: 165 · Reputation: 185
#1Jul 15, 2019, 12:46 PM
getbestblockhash gives back the latest mined block hash. But what happens when two blocks are sent at the same time? You end up with two chains at the same height, and the next block decides which one is actually valid. So my question is, how does getbestblockhash figure out which hash is the best one in that situation? Is it just the first one the node sees, ignoring others? Shouldn't it return all the best block hashes since there could be multiple?
4 Reply Quote Share
cobra51Newbie
Posts: 52 · Reputation: 31
#2Jul 15, 2019, 05:55 PM
The idea behind getbestblockhash is to return the tip of the chain with the most work that’s also fully validated. In cases of equal height, the block that your node sees first is considered the best. Nodes can still share headers of competing chains, so you can use getchaintips to check out blocks on other chains.
3 Reply Quote Share
dave.forkMember
Posts: 165 · Reputation: 185
#3Jul 15, 2019, 11:04 PM
If both chains have the same amount of work, then there could be two tips or none. If you just pick one, it makes it subjective, right? But what if the other chain is actually the right one? Miners might be building on that tip instead.
1 Reply Quote Share
cobra51Newbie
Posts: 52 · Reputation: 31
#4Jul 16, 2019, 12:16 AM
That’s true, but it’s about being fully validated. If there are competing blocks at the same height, Bitcoin Core waits until the longest chain is established or until one gets orphaned. Usually, miners are working on the best propagated tip, which is the one their node sees. Every node can’t know what the majority is working on, so it’s safer to stick with what they have.
3 Reply Quote Share

Related topics