From b80d6e049599355f3ac214d0aba5a645baa4a570 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 10 Jul 2019 17:00:11 -0700 Subject: [PATCH 1/2] Avoid unnecessary materialization of list There is a realization of a `list` in the `get_unslashed_attesting_indices` helper that is unnecessary. The functionality in this PR is the same so this change should only really be cosmetic wrt the spec. --- specs/core/0_beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index c0d52463a..e2d734e13 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1271,7 +1271,7 @@ def get_unslashed_attesting_indices(state: BeaconState, output = set() # type: Set[ValidatorIndex] for a in attestations: 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 From 4def681a4ee05f4852828bcafc39daa832d4036f Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 10 Jul 2019 17:05:49 -0700 Subject: [PATCH 2/2] Remove another unnecessary list materialization --- specs/core/0_beacon-chain.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index e2d734e13..569d2a80c 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1284,10 +1284,10 @@ def get_winning_crosslink_and_attesting_indices(state: BeaconState, epoch: Epoch, shard: Shard) -> Tuple[Crosslink, Set[ValidatorIndex]]: 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)), [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 = max(crosslinks, key=lambda c: ( get_attesting_balance(state, [a for a in attestations if a.data.crosslink == c]), c.data_root