Skip to content

Fix get_pow_block_at_terminal_total_difficulty and add unit tests#2726

Merged
djrtwo merged 3 commits intodevfrom
get_pow_block_at_ttd-tests
Nov 19, 2021
Merged

Fix get_pow_block_at_terminal_total_difficulty and add unit tests#2726
djrtwo merged 3 commits intodevfrom
get_pow_block_at_ttd-tests

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

@hwwhww hwwhww added scope:v-guide testing CI, actions, tests, testing infra bellatrix labels Nov 17, 2021
@hwwhww hwwhww requested a review from mkalinin November 17, 2021 10:03
@hwwhww hwwhww requested a review from djrtwo November 17, 2021 10:43
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

@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

bellatrix testing CI, actions, tests, testing infra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants