Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get_pow_block_at_terminal_total_difficulty and add unit tests #2726

Merged
merged 3 commits into from
Nov 19, 2021

Conversation

hwwhww
Copy link
Contributor

@hwwhww hwwhww commented Nov 17, 2021

Part of #2722

Spec changes

  1. get_pow_block_at_terminal_total_difficulty was wrongly iterating pow_chain keys. It should be dict values pow_chain.values() instead of pow_chain.
  2. Handle the edge case of block.parent_hash == Hash32() and block.parent_hash not in pow_chain. Without handling it, it would raise KeyErorr in pyspec.
    • New concern: it's the first time to use continue in specs. Is it too Pythonic and difficult to do formal verification? fixed

Testing

Add unit tests for get_pow_block_at_terminal_total_difficulty

if block_reached_ttd and block.parent_hash == Hash32():
return block
# Genesis block
if block.parent_hash == Hash32():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

@mkalinin mkalinin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! 👍

Copy link
Contributor

@djrtwo djrtwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. minor suggestion

specs/merge/validator.md Outdated Show resolved Hide resolved
@djrtwo djrtwo merged commit 3c25da8 into dev Nov 19, 2021
@djrtwo djrtwo deleted the get_pow_block_at_ttd-tests branch November 19, 2021 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants