core: use deterministic same-difficulty tie breaker #266
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When encountering two chain heads with the same block number and total difficulty, a random one would be chosen as canonical with a 50/50 chance. This could happen if a single node sends out two different versions of a block (with different txs), or it could be two arbitrary length competing branches. In either case, it's not clear who should win (either choice is valid). This PR proposes choosing the block with the most gas used, before falling back to randomization. In the length-1 case, the 'bigger' block is the obvious choice. In the arbitrary length case, the history would have to be inspected to make a more informed choice, but this method is no worse than the old. In both cases, all nodes on the chain will now make the same deterministic choice (when the gas used is different), reducing split decisions.