From e99c864ed18ef172adc5795f1777035ef517fc82 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 20 Jun 2019 17:17:12 -0600 Subject: [PATCH] Deltas = NewType('Deltas', TypingList[Gwei]) --- scripts/build_spec.py | 12 ++++-------- specs/core/0_beacon-chain.md | 8 ++++---- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/scripts/build_spec.py b/scripts/build_spec.py index 45cb0368f..bd7686ff5 100644 --- a/scripts/build_spec.py +++ b/scripts/build_spec.py @@ -12,7 +12,8 @@ from typing import ( PHASE0_IMPORTS = '''from typing import ( - Any, Callable, Iterable, Dict, Set, Tuple + Any, Callable, Iterable, Dict, Set, Tuple, NewType, + List as TypingList, ) from eth2spec.utils.ssz.ssz_impl import ( @@ -30,12 +31,9 @@ from eth2spec.utils.bls import ( ) from eth2spec.utils.hash_function import hash - - -Deltas = list ''' PHASE1_IMPORTS = '''from typing import ( - Any, Callable, Dict, Optional, Set, Tuple, Iterable, + Any, Callable, Dict, Optional, Set, Tuple, Iterable, NewType, List as TypingList ) @@ -56,9 +54,6 @@ from eth2spec.utils.bls import ( ) from eth2spec.utils.hash_function import hash - - -Deltas = list ''' SUNDRY_FUNCTIONS = ''' # Monkey patch hash cache @@ -149,6 +144,7 @@ def objects_to_spec(functions: Dict[str, str], spec = ( imports + '\n\n' + new_type_definitions + + '\n\n' + "Deltas = NewType('Deltas', TypingList[Gwei])" + '\n\n' + constants_spec + '\n\n\n' + ssz_objects_instantiation_spec + '\n\n' + functions_spec diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index f171bd4df..e89f0baed 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1405,8 +1405,8 @@ def get_base_reward(state: BeaconState, index: ValidatorIndex) -> Gwei: def get_attestation_deltas(state: BeaconState) -> Tuple[Deltas, Deltas]: previous_epoch = get_previous_epoch(state) total_balance = get_total_active_balance(state) - rewards = Deltas(0 for _ in range(len(state.validators))) - penalties = Deltas(0 for _ in range(len(state.validators))) + rewards = Deltas([Gwei(0) for _ in range(len(state.validators))]) + penalties = Deltas([Gwei(0) for _ in range(len(state.validators))]) eligible_validator_indices = [ ValidatorIndex(index) for index, v in enumerate(state.validators) if is_active_validator(v, previous_epoch) or (v.slashed and previous_epoch + 1 < v.withdrawable_epoch) @@ -1454,8 +1454,8 @@ def get_attestation_deltas(state: BeaconState) -> Tuple[Deltas, Deltas]: ```python def get_crosslink_deltas(state: BeaconState) -> Tuple[Deltas, Deltas]: - rewards = Deltas(0 for _ in range(len(state.validators))) - penalties = Deltas(0 for _ in range(len(state.validators))) + rewards = Deltas([Gwei(0) for _ in range(len(state.validators))]) + penalties = Deltas([Gwei(0) for _ in range(len(state.validators))]) epoch = get_previous_epoch(state) for offset in range(get_epoch_committee_count(state, epoch)): shard = Shard((get_epoch_start_shard(state, epoch) + offset) % SHARD_COUNT)