Fix get_pow_block_at_terminal_total_difficulty and add unit tests#2726
Merged
Fix get_pow_block_at_terminal_total_difficulty and add unit tests#2726
get_pow_block_at_terminal_total_difficulty and add unit tests#2726Conversation
6 tasks
mkalinin
reviewed
Nov 17, 2021
specs/merge/validator.md
Outdated
| if block_reached_ttd and block.parent_hash == Hash32(): | ||
| return block | ||
| # Genesis block | ||
| if block.parent_hash == Hash32(): |
Contributor
There was a problem hiding this comment.
What if we do it as follows:
if block_reached_ttd:
if block.parent_hash == Hash32():
return block
else:
parent = pow_chain[block.parent_hash]
parent_reached_ttd = parent.total_difficulty >= TERMINAL_TOTAL_DIFFICULTY
if not parent_reached_ttd:
return block
djrtwo
reviewed
Nov 19, 2021
Contributor
djrtwo
left a comment
There was a problem hiding this comment.
looks good. minor suggestion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Part of #2722
Spec changes
get_pow_block_at_terminal_total_difficultywas wrongly iteratingpow_chainkeys. It should be dict valuespow_chain.values()instead ofpow_chain.block.parent_hash == Hash32() and block.parent_hash not in pow_chain. Without handling it, it would raiseKeyErorrin pyspec.New concern: it's the first time to usefixedcontinuein specs. Is it too Pythonic and difficult to do formal verification?Testing
Add unit tests for
get_pow_block_at_terminal_total_difficulty