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?
How does getbestblockhash work with competing blocks?
3 replies 211 views
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.
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.
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.
Related topics
- Understanding How Multi-Signature Wallets Work 18
- HD Wallet vs Descriptor Wallet: What's the Deal? 3
- Do derivative traders move funds to wallets after closing positions? 19
- Need Help Cracking My Bitcoin Wallet Password 19
- Elon Musk's New X Wallet: Will Dogecoin Be the Payment Option? 19
- Need Help! My Electrum Wallet Won't Sync 6