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

Commit

Permalink
Capitalize CommitteeConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Feb 13, 2019
1 parent 2cabc2a commit 7c1f552
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 30 deletions.
17 changes: 9 additions & 8 deletions eth2/beacon/committee_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,15 @@ def get_crosslink_committees_at_slot(
"""
Return the list of ``(committee, shard)`` tuples for the ``slot``.
"""
genesis_epoch = committee_config.genesis_epoch
epoch_length = committee_config.epoch_length
target_committee_size = committee_config.target_committee_size
shard_count = committee_config.shard_count
seed_lookahead = committee_config.seed_lookahead
entry_exit_delay = committee_config.entry_exit_delay
latest_index_roots_length = committee_config.latest_index_roots_length
latest_randao_mixes_length = committee_config.latest_randao_mixes_length
genesis_epoch = committee_config.GENESIS_EPOCH
shard_count = committee_config.SHARD_COUNT
epoch_length = committee_config.EPOCH_LENGTH
target_committee_size = committee_config.TARGET_COMMITTEE_SIZE

seed_lookahead = committee_config.SEED_LOOKAHEAD
entry_exit_delay = committee_config.ENTRY_EXIT_DELAY
latest_index_roots_length = committee_config.LATEST_INDEX_ROOTS_LENGTH
latest_randao_mixes_length = committee_config.LATEST_RANDAO_MIXES_LENGTH

epoch = slot_to_epoch(slot, epoch_length)
current_epoch = state.current_epoch(epoch_length)
Expand Down
16 changes: 8 additions & 8 deletions eth2/beacon/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@
class CommitteeConfig:
def __init__(self, config: BeaconConfig):
# Basic
self.genesis_epoch = config.GENESIS_EPOCH
self.shard_count = config.SHARD_COUNT
self.epoch_length = config.EPOCH_LENGTH
self.target_committee_size = config.TARGET_COMMITTEE_SIZE
self.GENESIS_EPOCH = config.GENESIS_EPOCH
self.SHARD_COUNT = config.SHARD_COUNT
self.EPOCH_LENGTH = config.EPOCH_LENGTH
self.TARGET_COMMITTEE_SIZE = config.TARGET_COMMITTEE_SIZE

# For seed
self.seed_lookahead = config.SEED_LOOKAHEAD
self.entry_exit_delay = config.ENTRY_EXIT_DELAY
self.latest_index_roots_length = config.LATEST_INDEX_ROOTS_LENGTH
self.latest_randao_mixes_length = config.LATEST_RANDAO_MIXES_LENGTH
self.SEED_LOOKAHEAD = config.SEED_LOOKAHEAD
self.ENTRY_EXIT_DELAY = config.ENTRY_EXIT_DELAY
self.LATEST_INDEX_ROOTS_LENGTH = config.LATEST_INDEX_ROOTS_LENGTH
self.LATEST_RANDAO_MIXES_LENGTH = config.LATEST_RANDAO_MIXES_LENGTH
13 changes: 7 additions & 6 deletions eth2/beacon/state_machines/forks/serenity/block_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def validate_proposer_signature(state: BeaconState,
proposer_pubkey = state.validator_registry[beacon_proposer_index].pubkey
domain = get_domain(
state.fork,
state.current_epoch(committee_config.epoch_length),
state.current_epoch(committee_config.EPOCH_LENGTH),
SignatureDomain.DOMAIN_PROPOSAL
)

Expand Down Expand Up @@ -107,20 +107,21 @@ def validate_attestation(state: BeaconState,
Validate the given ``attestation``.
Raise ``ValidationError`` if it's invalid.
"""
epoch_length = committee_config.EPOCH_LENGTH

validate_attestation_slot(
attestation.data,
state.slot,
committee_config.epoch_length,
epoch_length,
min_attestation_inclusion_delay,
)

validate_attestation_justified_epoch(
attestation.data,
state.current_epoch(committee_config.epoch_length),
state.current_epoch(epoch_length),
state.previous_justified_epoch,
state.justified_epoch,
committee_config.epoch_length,
epoch_length,
)

validate_attestation_justified_block_root(
Expand All @@ -129,7 +130,7 @@ def validate_attestation(state: BeaconState,
state=state,
slot=get_epoch_start_slot(
attestation.data.justified_epoch,
committee_config.epoch_length,
epoch_length,
),
latest_block_roots_length=latest_block_roots_length,
),
Expand Down Expand Up @@ -296,7 +297,7 @@ def validate_attestation_aggregate_signature(state: BeaconState,
message = AttestationDataAndCustodyBit.create_attestation_message(attestation.data)
domain = get_domain(
fork=state.fork,
epoch=slot_to_epoch(attestation.data.slot, committee_config.epoch_length),
epoch=slot_to_epoch(attestation.data.slot, committee_config.EPOCH_LENGTH),
domain_type=SignatureDomain.DOMAIN_ATTESTATION,
)

Expand Down
8 changes: 4 additions & 4 deletions eth2/beacon/state_machines/forks/serenity/epoch_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ def _update_latest_index_roots(state: BeaconState,
"""
Return the BeaconState with updated `latest_index_roots`.
"""
next_epoch = state.next_epoch(committee_config.epoch_length)
next_epoch = state.next_epoch(committee_config.EPOCH_LENGTH)

# TODO: chanege to hash_tree_root
active_validator_indices = get_active_validator_indices(
state.validator_registry,
EpochNumber(next_epoch + committee_config.entry_exit_delay),
EpochNumber(next_epoch + committee_config.ENTRY_EXIT_DELAY),
)
index_root = hash_eth2(
b''.join(
Expand All @@ -260,8 +260,8 @@ def _update_latest_index_roots(state: BeaconState,
latest_index_roots = update_tuple_item(
state.latest_index_roots,
(
(next_epoch + committee_config.entry_exit_delay) %
committee_config.latest_index_roots_length
(next_epoch + committee_config.ENTRY_EXIT_DELAY) %
committee_config.LATEST_INDEX_ROOTS_LENGTH
),
index_root,
)
Expand Down
6 changes: 3 additions & 3 deletions eth2/beacon/validator_status_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _settle_penality_to_validator_and_whistleblower(
state.validator_balances[index] -= whistleblower_reward
validator.penalized_epoch = slot_to_epoch(state.slot)
"""
EPOCH_LENGTH = committee_config.epoch_length
EPOCH_LENGTH = committee_config.EPOCH_LENGTH

# Update `state.latest_penalized_balances`
current_epoch_penalization_index = state.current_epoch(
Expand Down Expand Up @@ -174,8 +174,8 @@ def penalize_validator(state: BeaconState,
Exit the validator, penalize the validator, and reward the whistleblower.
"""
EPOCH_LENGTH = committee_config.epoch_length
ENTRY_EXIT_DELAY = committee_config.entry_exit_delay
EPOCH_LENGTH = committee_config.EPOCH_LENGTH
ENTRY_EXIT_DELAY = committee_config.ENTRY_EXIT_DELAY
state = exit_validator(state, index, EPOCH_LENGTH, ENTRY_EXIT_DELAY)
state = _settle_penality_to_validator_and_whistleblower(
state=state,
Expand Down
2 changes: 1 addition & 1 deletion tests/eth2/beacon/test_validator_status_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def mock_get_crosslink_committees_at_slot(state,
# Check `state.latest_penalized_balances`
latest_penalized_balances_list = list(state.latest_penalized_balances)
last_penalized_epoch = (
state.current_epoch(committee_config.epoch_length) % latest_penalized_exit_length
state.current_epoch(committee_config.EPOCH_LENGTH) % latest_penalized_exit_length
)
latest_penalized_balances_list[last_penalized_epoch] = max_deposit_amount
latest_penalized_balances = tuple(latest_penalized_balances_list)
Expand Down

0 comments on commit 7c1f552

Please sign in to comment.