Merge pull request #1287 from ethereum/ralexstokes-patch-3

Avoid unnecessary materialization of list
This commit is contained in:
Danny Ryan 2019-07-14 15:33:16 -06:00 committed by GitHub
commit d8ce0e0e6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -1271,7 +1271,7 @@ def get_unslashed_attesting_indices(state: BeaconState,
output = set() # type: Set[ValidatorIndex] output = set() # type: Set[ValidatorIndex]
for a in attestations: for a in attestations:
output = output.union(get_attesting_indices(state, a.data, a.aggregation_bits)) output = output.union(get_attesting_indices(state, a.data, a.aggregation_bits))
return set(filter(lambda index: not state.validators[index].slashed, list(output))) return set(filter(lambda index: not state.validators[index].slashed, output))
``` ```
```python ```python
@ -1284,10 +1284,10 @@ def get_winning_crosslink_and_attesting_indices(state: BeaconState,
epoch: Epoch, epoch: Epoch,
shard: Shard) -> Tuple[Crosslink, Set[ValidatorIndex]]: shard: Shard) -> Tuple[Crosslink, Set[ValidatorIndex]]:
attestations = [a for a in get_matching_source_attestations(state, epoch) if a.data.crosslink.shard == shard] attestations = [a for a in get_matching_source_attestations(state, epoch) if a.data.crosslink.shard == shard]
crosslinks = list(filter( crosslinks = filter(
lambda c: hash_tree_root(state.current_crosslinks[shard]) in (c.parent_root, hash_tree_root(c)), lambda c: hash_tree_root(state.current_crosslinks[shard]) in (c.parent_root, hash_tree_root(c)),
[a.data.crosslink for a in attestations] [a.data.crosslink for a in attestations]
)) )
# Winning crosslink has the crosslink data root with the most balance voting for it (ties broken lexicographically) # Winning crosslink has the crosslink data root with the most balance voting for it (ties broken lexicographically)
winning_crosslink = max(crosslinks, key=lambda c: ( winning_crosslink = max(crosslinks, key=lambda c: (
get_attesting_balance(state, [a for a in attestations if a.data.crosslink == c]), c.data_root get_attesting_balance(state, [a for a in attestations if a.data.crosslink == c]), c.data_root