From fe68a8d1f0febab6524e232a50cac136b5b02af9 Mon Sep 17 00:00:00 2001 From: Carl Beekhuizen Date: Sun, 30 Jun 2019 22:59:12 +0200 Subject: [PATCH 1/2] Minor python style tweaks --- specs/core/0_beacon-chain.md | 10 +++++----- specs/core/0_fork-choice.md | 4 ++-- specs/core/1_shard-data-chains.md | 8 ++++---- specs/light_client/sync_protocol.md | 4 ++-- specs/validator/0_beacon-chain-validator.md | 7 +++---- test_libs/pyspec/eth2spec/test/sanity/test_blocks.py | 4 ++-- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 7dd6a71bf..9bb562bb6 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1438,8 +1438,8 @@ def process_registry_updates(state: BeaconState) -> None: # Process activation eligibility and ejections for index, validator in enumerate(state.validators): if ( - validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and - validator.effective_balance == MAX_EFFECTIVE_BALANCE + validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH + and validator.effective_balance == MAX_EFFECTIVE_BALANCE ): validator.activation_eligibility_epoch = get_current_epoch(state) @@ -1448,9 +1448,9 @@ def process_registry_updates(state: BeaconState) -> None: # Queue validators eligible for activation and not dequeued for activation prior to finalized epoch activation_queue = sorted([ - index for index, validator in enumerate(state.validators) if - validator.activation_eligibility_epoch != FAR_FUTURE_EPOCH and - validator.activation_epoch >= compute_activation_exit_epoch(state.finalized_checkpoint.epoch) + index for index, validator in enumerate(state.validators) + if validator.activation_eligibility_epoch != FAR_FUTURE_EPOCH + and validator.activation_epoch >= compute_activation_exit_epoch(state.finalized_checkpoint.epoch) ], key=lambda index: state.validators[index].activation_eligibility_epoch) # Dequeued validators for activation up to churn limit (without resetting activation epoch) for index in activation_queue[:get_validator_churn_limit(state)]: diff --git a/specs/core/0_fork-choice.md b/specs/core/0_fork-choice.md index 89eecff02..40ca305dc 100644 --- a/specs/core/0_fork-choice.md +++ b/specs/core/0_fork-choice.md @@ -113,8 +113,8 @@ def get_latest_attesting_balance(store: Store, root: Hash) -> Gwei: active_indices = get_active_validator_indices(state, get_current_epoch(state)) return Gwei(sum( state.validators[i].effective_balance for i in active_indices - if (i in store.latest_messages and - get_ancestor(store, store.latest_messages[i].root, store.blocks[root].slot) == root) + if (i in store.latest_messages + and get_ancestor(store, store.latest_messages[i].root, store.blocks[root].slot) == root) )) ``` diff --git a/specs/core/1_shard-data-chains.md b/specs/core/1_shard-data-chains.md index 745d437c2..05f95e16a 100644 --- a/specs/core/1_shard-data-chains.md +++ b/specs/core/1_shard-data-chains.md @@ -181,8 +181,8 @@ def get_persistent_committee(state: BeaconState, # Take not-yet-cycled-out validators from earlier committee and already-cycled-in validators from # later committee; return a sorted list of the union of the two, deduplicated return sorted(list(set( - [i for i in earlier_committee if epoch % PERSISTENT_COMMITTEE_PERIOD < get_switchover_epoch(state, epoch, i)] + - [i for i in later_committee if epoch % PERSISTENT_COMMITTEE_PERIOD >= get_switchover_epoch(state, epoch, i)] + [i for i in earlier_committee if epoch % PERSISTENT_COMMITTEE_PERIOD < get_switchover_epoch(state, epoch, i)] + + [i for i in later_committee if epoch % PERSISTENT_COMMITTEE_PERIOD >= get_switchover_epoch(state, epoch, i)] ))) ``` @@ -398,8 +398,8 @@ def is_valid_beacon_attestation(shard: Shard, assert candidate.data.previous_crosslink.data_root == Hash() else: previous_attestation = next( - (attestation for attestation in valid_attestations if - attestation.data.crosslink.data_root == candidate.data.previous_crosslink.data_root), + (attestation for attestation in valid_attestations + if attestation.data.crosslink.data_root == candidate.data.previous_crosslink.data_root), None, ) assert previous_attestation is not None diff --git a/specs/light_client/sync_protocol.md b/specs/light_client/sync_protocol.md index 2b1703f21..15f13b15b 100644 --- a/specs/light_client/sync_protocol.md +++ b/specs/light_client/sync_protocol.md @@ -153,8 +153,8 @@ def compute_committee(header: BeaconBlockHeader, # Take not-yet-cycled-out validators from earlier committee and already-cycled-in validators from # later committee; return a sorted list of the union of the two, deduplicated return sorted(list(set( - [i for i in actual_earlier_committee if epoch % PERSISTENT_COMMITTEE_PERIOD < get_switchover_epoch(i)] + - [i for i in actual_later_committee if epoch % PERSISTENT_COMMITTEE_PERIOD >= get_switchover_epoch(i)] + [i for i in actual_earlier_committee if epoch % PERSISTENT_COMMITTEE_PERIOD < get_switchover_epoch(i)] + + [i for i in actual_later_committee if epoch % PERSISTENT_COMMITTEE_PERIOD >= get_switchover_epoch(i)] ))) ``` diff --git a/specs/validator/0_beacon-chain-validator.md b/specs/validator/0_beacon-chain-validator.md index e354345fa..2626b50aa 100644 --- a/specs/validator/0_beacon-chain-validator.md +++ b/specs/validator/0_beacon-chain-validator.md @@ -132,10 +132,9 @@ Once a validator is activated, the validator is assigned [responsibilities](#bea A validator can get committee assignments for a given epoch using the following helper via `get_committee_assignment(state, epoch, validator_index)` where `epoch <= next_epoch`. ```python -def get_committee_assignment( - state: BeaconState, - epoch: Epoch, - validator_index: ValidatorIndex) -> Tuple[List[ValidatorIndex], Shard, Slot]: +def get_committee_assignment(state: BeaconState, + epoch: Epoch, + validator_index: ValidatorIndex) -> Tuple[List[ValidatorIndex], Shard, Slot]: """ Return the committee assignment in the ``epoch`` for ``validator_index``. ``assignment`` returned is a tuple of the following form: diff --git a/test_libs/pyspec/eth2spec/test/sanity/test_blocks.py b/test_libs/pyspec/eth2spec/test/sanity/test_blocks.py index b6f0ecba2..886f9bf6a 100644 --- a/test_libs/pyspec/eth2spec/test/sanity/test_blocks.py +++ b/test_libs/pyspec/eth2spec/test/sanity/test_blocks.py @@ -188,8 +188,8 @@ def test_attester_slashing(spec, state): pre_state = deepcopy(state) attester_slashing = get_valid_attester_slashing(spec, state, signed_1=True, signed_2=True) - validator_index = (attester_slashing.attestation_1.custody_bit_0_indices + - attester_slashing.attestation_1.custody_bit_1_indices)[0] + validator_index = (attester_slashing.attestation_1.custody_bit_0_indices + + attester_slashing.attestation_1.custody_bit_1_indices)[0] assert not state.validators[validator_index].slashed From 8b10ed598e9ce99d16181fcf3d7cff1f675fe678 Mon Sep 17 00:00:00 2001 From: Carl Beekhuizen Date: Sun, 30 Jun 2019 23:14:16 +0200 Subject: [PATCH 2/2] Adds a lone space --- specs/core/1_shard-data-chains.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/core/1_shard-data-chains.md b/specs/core/1_shard-data-chains.md index 05f95e16a..6213169d7 100644 --- a/specs/core/1_shard-data-chains.md +++ b/specs/core/1_shard-data-chains.md @@ -399,7 +399,7 @@ def is_valid_beacon_attestation(shard: Shard, else: previous_attestation = next( (attestation for attestation in valid_attestations - if attestation.data.crosslink.data_root == candidate.data.previous_crosslink.data_root), + if attestation.data.crosslink.data_root == candidate.data.previous_crosslink.data_root), None, ) assert previous_attestation is not None