Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Make epoch first class and update epoch transition rule #256

Merged
merged 16 commits into from
Feb 5, 2019

Conversation

NIC619
Copy link
Contributor

@NIC619 NIC619 commented Feb 4, 2019

What was wrong?

Fix #235

How was it fixed?

  • rename many variables from *_slot to *_epoch
  • Update config values
    • add GENESIS_EPOCH
    • FAR_FUTURE_SLOT -> FAR_FUTURE_EPOCH
    • SEED_LOOKAHEAD
    • ENTRY_EXIT_DELAY
    • ETH1_DATA_VOTING_PERIOD
    • MIN_VALIDATOR_WITHDRAWAL_EPOCHS
  • add helper function
    • get_epoch_start_slot
    • slot_to_epoch
  • rename function and update function logic
    • get_committee_count_per_slot -> get_epoch_committee_count
    • get_previous_epoch_committee_count_per_slot -> get_previous_epoch_committee_count
    • get_current_epoch_committee_count_per_slot -> get_current_epoch_committee_count
    • entry_exit_effect_slot -> get_entry_exit_effect_epoch
  • update function logic
    • is_active_validator(Validator.is_active)
    • get_active_validator_indices
    • get_shuffling
    • get_crosslink_committees_at_slot
    • get_randao_mix
    • get_active_index_root
    • generate_seed
    • get_fork_version
    • get_domain
    • verify_slashable_vote_data
    • is_double_vote
    • is_surround_vote
    • get_initial_beacon_state
    • validate_proof_of_possession
    • activate_validator
    • exit_validator
    • penalize_validator
  • update per-slot processing
    • don't update state.latest_randao_mixes
  • update per-block processing
  • update per-epoch processing

Cute Animal Picture

get_committee_count_per_slot,
get_previous_epoch_committee_count_per_slot,
get_current_epoch_committee_count_per_slot,
entry_exit_effect_slot
GENESIS_EPOCH, FAR_FUTURE_SLOT, SEED_LOOKAHEAD, ENTRY_EXIT_DELAY, ETH1_DATA_VOTING_PERIOD, MIN_VALI
DATOR_WITHDRAWAL_EPOCHS
AttestationData.justified_slot, Exit. slot,
State(validator_registry_update_slot/previous_epoch_calculation_slot/current_epoch_calculation_slot/previous_justified_slot/justified_slot/finalized_slot),
Validator.(activation_slot/exit_slot/withdrawal_slot/penalized_slot),
Crosslink.slot, Fork.slot
is_active_validator, get_active_validator_indices, get_shuffling, get_crosslink_committees_at_slot
get_randao_mix, get_active_index_root, generate_seed, get_fork_version, get_domain, verify_slashable_vote_data, is_double_vote, is_surround_vote
get_initial_beacon_state, validate_proof_of_possession, activate_validator, exit_validator, penalize_validator
fix get_previous_epoch_attestations/get_current_epoch_attestations
fix process_crosslinks
Copy link
Contributor

@hwwhww hwwhww left a comment

Choose a reason for hiding this comment

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

excellent work!

eth2/beacon/helpers.py Show resolved Hide resolved
eth2/beacon/helpers.py Outdated Show resolved Hide resolved
eth2/beacon/validator_status_helpers.py Outdated Show resolved Hide resolved
eth2/beacon/validator_status_helpers.py Outdated Show resolved Hide resolved
tests/core/p2p-proto/bcc/test_commands.py Outdated Show resolved Hide resolved
tests/core/p2p-proto/bcc/test_commands.py Outdated Show resolved Hide resolved
tests/eth2/beacon/helpers.py Outdated Show resolved Hide resolved
@NIC619 NIC619 changed the title [WIP]Make epoch first class and update epoch transition rule Make epoch first class and update epoch transition rule Feb 4, 2019
@NIC619 NIC619 force-pushed the first_class_epoch_and_epoch_transition branch from 05675c6 to 98c55f8 Compare February 4, 2019 13:47
current_epoch = state.current_epoch(config.EPOCH_LENGTH)
next_epoch = state.next_epoch(config.EPOCH_LENGTH)
previous_index = current_epoch % config.LATEST_PENALIZED_EXIT_LENGTH
current_index = next_epoch % config.LATEST_PENALIZED_EXIT_LENGTH

state = state.copy(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we update latest_index_roots in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahhh you're right!!!
I was looking for these changes needed to be updated:

    index_root = hash_eth2(
        b''.join(
            [
                index.to_bytes(32, 'big')
                for index in active_validator_indices
            ]
        )
    )

    latest_index_roots = update_tuple_item(
        state.latest_index_roots,
        next_epoch % config.LATEST_INDEX_ROOTS_LENGTH,
        index_root,
    )

to

In spec: Set state.latest_index_roots[(next_epoch + ENTRY_EXIT_DELAY) % LATEST_INDEX_ROOTS_LENGTH] = hash_tree_root(get_active_validator_indices(state, next_epoch + ENTRY_EXIT_DELAY)).

But now I found these changes belong to #258. 😢

docstring, TODO, naming
eth2/beacon/helpers.py Outdated Show resolved Hide resolved
@NIC619 NIC619 merged commit 320162d into ethereum:master Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make epochs first class citizens and epoch trans at end of epoch
3 participants