-
Notifications
You must be signed in to change notification settings - Fork 146
Implement light client friendliness changes #234
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,16 +8,20 @@ | |
from eth2._utils.tuple import ( | ||
update_tuple_item, | ||
) | ||
from eth2.beacon._utils.hash import ( | ||
hash_eth2, | ||
) | ||
from eth2.beacon import helpers | ||
from eth2.beacon.helpers import ( | ||
get_active_validator_indices, | ||
get_current_epoch_committee_count_per_slot, | ||
get_randao_mix, | ||
) | ||
from eth2.beacon.types.states import BeaconState | ||
from eth2.beacon.state_machines.configs import BeaconConfig | ||
|
||
|
||
# | ||
# Validator Registry | ||
# Validator registry and shuffling seed data | ||
# | ||
def _check_if_update_validator_registry(state: BeaconState, | ||
config: BeaconConfig) -> Tuple[bool, int]: | ||
|
@@ -48,13 +52,42 @@ def update_validator_registry(state: BeaconState) -> BeaconState: | |
return state | ||
|
||
|
||
def _update_latest_index_roots(state: BeaconState, | ||
config: BeaconConfig) -> BeaconState: | ||
""" | ||
Return the BeaconState with updated `latest_index_roots`. | ||
""" | ||
next_epoch = state.next_epoch(config.EPOCH_LENGTH) | ||
|
||
# TODO: chanege to hash_tree_root | ||
index_root = hash_eth2( | ||
bytes( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it guaranteed that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ohhh good point!!!! # TODO: chanege to hash_tree_root
index_root = hash_eth2(
b''.join(
[
index.to_bytes(32, 'big')
for index in get_active_validator_indices(
state.validator_registry,
# TODO: change to `per-epoch` version
state.slot,
)
]
)
) (p.s. The upper-bound of the size of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hrm, a |
||
get_active_validator_indices( | ||
state.validator_registry, | ||
# TODO: change to `per-epoch` version | ||
state.slot, | ||
hwwhww marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
) | ||
) | ||
latest_index_roots = update_tuple_item( | ||
state.latest_index_roots, | ||
next_epoch % config.LATEST_INDEX_ROOTS_LENGTH, | ||
index_root, | ||
) | ||
|
||
return state.copy( | ||
latest_index_roots=latest_index_roots, | ||
) | ||
|
||
|
||
def process_validator_registry(state: BeaconState, | ||
config: BeaconConfig) -> BeaconState: | ||
state = state.copy( | ||
previous_epoch_calculation_slot=state.current_epoch_calculation_slot, | ||
previous_epoch_start_shard=state.current_epoch_start_shard, | ||
previous_epoch_randao_mix=state.current_epoch_randao_mix, | ||
previous_epoch_seed=state.current_epoch_seed, | ||
) | ||
state = _update_latest_index_roots(state, config) | ||
|
||
need_to_update, num_shards_in_committees = _check_if_update_validator_registry(state, config) | ||
|
||
|
@@ -71,12 +104,18 @@ def process_validator_registry(state: BeaconState, | |
state.current_epoch_start_shard + num_shards_in_committees | ||
) % config.SHARD_COUNT, | ||
) | ||
|
||
# `helpers.generate_seed` path for mocking tests | ||
current_epoch_seed = helpers.generate_seed( | ||
state=state, | ||
slot=state.current_epoch_calculation_slot, | ||
epoch_length=config.EPOCH_LENGTH, | ||
seed_lookahead=config.SEED_LOOKAHEAD, | ||
latest_index_roots_length=config.LATEST_INDEX_ROOTS_LENGTH, | ||
latest_randao_mixes_length=config.LATEST_RANDAO_MIXES_LENGTH, | ||
) | ||
state = state.copy( | ||
current_epoch_randao_mix=get_randao_mix( | ||
state, | ||
state.current_epoch_calculation_slot - config.SEED_LOOKAHEAD, | ||
config.LATEST_RANDAO_MIXES_LENGTH, | ||
), | ||
current_epoch_seed=current_epoch_seed, | ||
) | ||
else: | ||
epochs_since_last_registry_change = ( | ||
|
@@ -88,13 +127,21 @@ def process_validator_registry(state: BeaconState, | |
state = state.copy( | ||
current_epoch_calculation_slot=state.slot, | ||
) | ||
|
||
# `helpers.generate_seed` path for mocking tests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think know what this comment is indicating but could we maybe make it a bit more explicit. Here's what I think it is trying to say.
|
||
current_epoch_seed = helpers.generate_seed( | ||
state=state, | ||
slot=state.current_epoch_calculation_slot, | ||
epoch_length=config.EPOCH_LENGTH, | ||
seed_lookahead=config.SEED_LOOKAHEAD, | ||
latest_index_roots_length=config.LATEST_INDEX_ROOTS_LENGTH, | ||
latest_randao_mixes_length=config.LATEST_RANDAO_MIXES_LENGTH, | ||
) | ||
state = state.copy( | ||
current_epoch_randao_mix=get_randao_mix( | ||
state, | ||
state.current_epoch_calculation_slot - config.SEED_LOOKAHEAD, | ||
config.LATEST_RANDAO_MIXES_LENGTH, | ||
), | ||
current_epoch_seed=current_epoch_seed, | ||
) | ||
else: | ||
pass | ||
|
||
return state | ||
|
||
|
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.
👍