-
Notifications
You must be signed in to change notification settings - Fork 63
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
Conversation
|
||
sback = current_block.slot_number - cycle_length * 2 | ||
assert sback <= slot < sback + cycle_length * 2 | ||
return active_state.recent_block_hashes[slot - sback] |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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:
active_state.recent_block_hashes
was initialized to a list ofCYCLE_LENGTH * 2
zero hashes, and then updated viaget_new_recent_block_hashes
block by block.- The domain of
slot - sback
was guaranteed by the assertionsback <= 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! 👍
b638683
to
8ec0903
Compare
beacon_chain/state/helpers.py
Outdated
cycle_length = config['cycle_length'] | ||
|
||
ifh_start = crystallized_state.last_state_recalc - cycle_length | ||
assert ifh_start <= slot < ifh_start + cycle_length * 2 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
What was wrong?
Fixes #59
How was it fixed?
indices_for_heights
toindices_for_slots
get_indices_for_slot
andget_block_hash
helper functions.get_signed_parent_hashes()
andget_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.