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

Update pow_chain to dict and reuse it instead of calling get_pow_block #2694

Merged
merged 1 commit into from
Oct 27, 2021

Conversation

hwwhww
Copy link
Contributor

@hwwhww hwwhww commented Oct 26, 2021

Issue

Per #2636 (comment) discussion:
If the validator already maintains all PoW blocks, they don't really have to call get_pow_block(block.parent_hash) (which we implied it's a JSON-RPC call) to get the parent block.

How did I fix it

  1. As @mkalinin suggested, we can change the abstract pow_chain structure to Dict[Hash32, PowBlock] so that we can query the block by hash easily.
  2. Change parent = get_pow_block(block.parent_hash) to parent = pow_chain[block.parent_hash].
    • Note: KeyError is considered invalid.

It turns out get_terminal_pow_block is much more concise with this change! ✨

@hwwhww hwwhww added scope:v-guide Validator guide Bellatrix CL+EL Merge labels Oct 26, 2021
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.

lgtm

Copy link
Collaborator

@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! 👍

@mkalinin mkalinin merged commit 4879383 into dev Oct 27, 2021
@hwwhww hwwhww deleted the reuse-pow-chain branch October 27, 2021 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bellatrix CL+EL Merge scope:v-guide Validator guide
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants