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

Add and use get_indices_for_slot and get_block_hash #62

Merged
merged 5 commits into from
Aug 23, 2018

Conversation

hwwhww
Copy link
Contributor

@hwwhww hwwhww commented Aug 20, 2018

What was wrong?

Fixes #59

How was it fixed?

  • Rename indices_for_heights to indices_for_slots
  • Added get_indices_for_slot and get_block_hash helper functions.
  • Modified get_signed_parent_hashes() and get_attestation_indices to use those functions.

I think if we use the old get_signed_parent_hashes() + add some boundary cases checks, it would be faster and efficient than the new one.

TODO: Add more tests and refactor.

mratsim added a commit to status-im/nimbus-eth2 that referenced this pull request Aug 21, 2018

sback = current_block.slot_number - cycle_length * 2
assert sback <= slot < sback + cycle_length * 2
return active_state.recent_block_hashes[slot - sback]

Choose a reason for hiding this comment

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

have you considered the case where sback could be negative?
Example:
current_block.slot_number = 10
sback = 10 - 64 * 2 = -118
then it'll return active_state.recent_block_hashes[slot + 118]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's okay since practically:

  1. active_state.recent_block_hashes was initialized to a list of CYCLE_LENGTH * 2 zero hashes, and then updated via get_new_recent_block_hashes block by block.
  2. The domain of slot - sback was guaranteed by the assertion sback <= slot < sback + cycle_length * 2, that said, 0 <= slot - sback < CYCLE_LENGTH * 2.

I will add a test of the scenario you mentioned, thank you! 👍

cycle_length = config['cycle_length']

ifh_start = crystallized_state.last_state_recalc - cycle_length
assert ifh_start <= slot < ifh_start + cycle_length * 2
Copy link
Contributor

@ChihChengLiang ChihChengLiang Aug 23, 2018

Choose a reason for hiding this comment

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

What does ifh stand for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, indices_for_height, but it was renamed to indices_for_slot. I will update it. Thanks.

@hwwhww hwwhww merged commit 8a52309 into ethereum:master Aug 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add get_indices_for_slot and get_block_hash
3 participants