Deltas = NewType('Deltas', TypingList[Gwei])

This commit is contained in:
Hsiao-Wei Wang 2019-06-20 17:17:12 -06:00
parent 6648b3c49e
commit e99c864ed1
No known key found for this signature in database
GPG Key ID: 95B070122902DEA4
2 changed files with 8 additions and 12 deletions

View File

@ -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

View File

@ -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)