Merge pull request #1943 from ethereum/avoid-neg-op

Avoid negative values and minor refactoring
This commit is contained in:
Danny Ryan 2020-07-02 09:37:16 -06:00 committed by GitHub
commit 5a9dd44ff4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 8 deletions

View File

@ -307,7 +307,7 @@ def get_eth1_vote(state: BeaconState, eth1_chain: Sequence[Eth1Block]) -> Eth1Da
valid_votes = [vote for vote in state.eth1_data_votes if vote in votes_to_consider]
# Default vote on latest eth1 block data in the period range unless eth1 chain is not live
default_vote = votes_to_consider[-1] if any(votes_to_consider) else state.eth1_data
default_vote = votes_to_consider[len(votes_to_consider) - 1] if any(votes_to_consider) else state.eth1_data
return max(
valid_votes,

View File

@ -532,7 +532,7 @@ def get_active_shard_count(state: BeaconState) -> uint64:
```python
def get_online_validator_indices(state: BeaconState) -> Set[ValidatorIndex]:
active_validators = get_active_validator_indices(state, get_current_epoch(state))
return set([i for i in active_validators if state.online_countdown[i] != 0])
return set(i for i in active_validators if state.online_countdown[i] != 0) # non-duplicate
```
#### `get_shard_committee`

View File

@ -234,9 +234,12 @@ Given one set of data, return the custody atoms: each atom will be combined with
```python
def get_custody_atoms(bytez: bytes) -> Sequence[bytes]:
bytez += b'\x00' * (-len(bytez) % BYTES_PER_CUSTODY_ATOM) # right-padding
return [bytez[i:i + BYTES_PER_CUSTODY_ATOM]
for i in range(0, len(bytez), BYTES_PER_CUSTODY_ATOM)]
length_remainder = len(bytez) % BYTES_PER_CUSTODY_ATOM
bytez += b'\x00' * ((BYTES_PER_CUSTODY_ATOM - length_remainder) % BYTES_PER_CUSTODY_ATOM) # right-padding
return [
bytez[i:i + BYTES_PER_CUSTODY_ATOM]
for i in range(0, len(bytez), BYTES_PER_CUSTODY_ATOM)
]
```
### `get_custody_secrets`
@ -557,7 +560,6 @@ def process_custody_slashing(state: BeaconState, signed_custody_slashing: Signed
slash_validator(state, custody_slashing.whistleblower_index)
```
## Per-epoch processing
### Handling of reveal deadlines
@ -589,7 +591,7 @@ def process_custody_final_updates(state: BeaconState) -> None:
# Reset withdrawable epochs if challenge records are empty
records = state.custody_chunk_challenge_records
validator_indices_in_records = set([record.responder_index for record in records])
validator_indices_in_records = set(record.responder_index for record in records) # non-duplicate
for index, validator in enumerate(state.validators):
if validator.exit_epoch != FAR_FUTURE_EPOCH:
not_all_secrets_are_revealed = validator.all_custody_secrets_revealed_epoch == FAR_FUTURE_EPOCH

View File

@ -162,7 +162,7 @@ def get_shard_winning_roots(state: BeaconState,
committee = get_beacon_committee(state, on_time_attestation_slot, committee_index)
# Loop over all shard transition roots, looking for a winning root
shard_transition_roots = set([a.data.shard_transition_root for a in shard_attestations])
shard_transition_roots = set(a.data.shard_transition_root for a in shard_attestations) # non-duplicate
for shard_transition_root in sorted(shard_transition_roots):
transition_attestations = [
a for a in shard_attestations