Skip to content

Commit

Permalink
Merge pull request #1943 from ethereum/avoid-neg-op
Browse files Browse the repository at this point in the history
Avoid negative values and minor refactoring
  • Loading branch information
djrtwo authored Jul 2, 2020
2 parents 32818a3 + 9663638 commit 5a9dd44
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion specs/phase0/validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion specs/phase1/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
12 changes: 7 additions & 5 deletions specs/phase1/custody-game.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion specs/phase1/validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5a9dd44

Please sign in to comment.