From 9fb58067645da1aa02dcfa995cb61fb86a2dff16 Mon Sep 17 00:00:00 2001 From: protolambda Date: Tue, 25 Jun 2019 00:24:13 +0200 Subject: [PATCH] be explicit about input for balance sum --- scripts/build_spec.py | 4 ++-- specs/core/0_beacon-chain.md | 6 +++--- specs/core/1_shard-data-chains.md | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/build_spec.py b/scripts/build_spec.py index 08793869f..237c24384 100644 --- a/scripts/build_spec.py +++ b/scripts/build_spec.py @@ -12,7 +12,7 @@ from typing import ( PHASE0_IMPORTS = '''from typing import ( - Any, Callable, Iterable, Dict, Set, Sequence, Tuple, + Any, Callable, Dict, Set, Sequence, Tuple, ) from dataclasses import ( @@ -37,7 +37,7 @@ from eth2spec.utils.bls import ( from eth2spec.utils.hash_function import hash ''' PHASE1_IMPORTS = '''from typing import ( - Any, Callable, Dict, Iterable, Optional, Set, Sequence, Tuple, + Any, Callable, Dict, Optional, Set, Sequence, Tuple, List as TypingList ) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 4d6be89f7..b8cab7eaf 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -908,7 +908,7 @@ def bytes_to_int(data: bytes) -> int: ### `get_total_balance` ```python -def get_total_balance(state: BeaconState, indices: Iterable[ValidatorIndex]) -> Gwei: +def get_total_balance(state: BeaconState, indices: Set[ValidatorIndex]) -> Gwei: """ Return the combined effective balance of the ``indices``. (1 Gwei minimum to avoid divisions by zero.) """ @@ -1383,7 +1383,7 @@ def process_crosslinks(state: BeaconState) -> None: for epoch in (get_previous_epoch(state), get_current_epoch(state)): for offset in range(get_epoch_committee_count(state, epoch)): shard = Shard((get_epoch_start_shard(state, epoch) + offset) % SHARD_COUNT) - crosslink_committee = get_crosslink_committee(state, epoch, shard) + crosslink_committee = set(get_crosslink_committee(state, epoch, shard)) winning_crosslink, attesting_indices = get_winning_crosslink_and_attesting_indices(state, epoch, shard) if 3 * get_total_balance(state, attesting_indices) >= 2 * get_total_balance(state, crosslink_committee): state.current_crosslinks[shard] = winning_crosslink @@ -1456,7 +1456,7 @@ def get_crosslink_deltas(state: BeaconState) -> Tuple[Sequence[Gwei], Sequence[G 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) - crosslink_committee = get_crosslink_committee(state, epoch, shard) + crosslink_committee = set(get_crosslink_committee(state, epoch, shard)) winning_crosslink, attesting_indices = get_winning_crosslink_and_attesting_indices(state, epoch, shard) attesting_balance = get_total_balance(state, attesting_indices) committee_balance = get_total_balance(state, crosslink_committee) diff --git a/specs/core/1_shard-data-chains.md b/specs/core/1_shard-data-chains.md index f84b0dd46..dd48a842a 100644 --- a/specs/core/1_shard-data-chains.md +++ b/specs/core/1_shard-data-chains.md @@ -378,7 +378,7 @@ Let: * `shard` be a valid `Shard` * `shard_blocks` be the `ShardBlock` list such that `shard_blocks[slot]` is the canonical `ShardBlock` for shard `shard` at slot `slot` * `beacon_state` be the canonical `BeaconState` -* `valid_attestations` be the list of valid `Attestation`, recursively defined +* `valid_attestations` be the set of valid `Attestation` objects, recursively defined * `candidate` be a candidate `Attestation` which is valid under Phase 0 rules, and for which validity is to be determined under Phase 1 rules by running `is_valid_beacon_attestation` ```python @@ -388,7 +388,7 @@ def is_valid_beacon_attestation(shard: Shard, valid_attestations: Set[Attestation], candidate: Attestation) -> bool: # Check if attestation is already determined valid - for _, attestation in enumerate(valid_attestations): + for attestation in valid_attestations: if candidate == attestation: return True