From 1310105174368d10f21948be410ca0525e49366b Mon Sep 17 00:00:00 2001 From: terence tsao Date: Thu, 13 May 2021 16:22:28 -0700 Subject: [PATCH 1/2] Return non-duplicated sync committee subnets --- specs/altair/validator.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/altair/validator.md b/specs/altair/validator.md index 4aee98ad4..e6e00a674 100644 --- a/specs/altair/validator.md +++ b/specs/altair/validator.md @@ -292,7 +292,7 @@ The validator broadcasts the assembled signature to the assigned subnet, the `sy The `subnet_id` is derived from the position in the sync committee such that the sync committee is divided into "subcommittees". `subnet_id` can be computed via `compute_subnets_for_sync_committee(state, validator_index)` where `state` is a `BeaconState` during the matching sync committee period. -*Note*: This function returns multiple subnets if a given validator index is included multiple times in a given sync committee across multiple subcommittees. +*Note*: This function returns multiple non-duplicated subnets if a given validator index is included multiple times in a given sync committee across multiple subcommittees. ```python def compute_subnets_for_sync_committee(state: BeaconState, validator_index: ValidatorIndex) -> Sequence[uint64]: @@ -304,10 +304,10 @@ def compute_subnets_for_sync_committee(state: BeaconState, validator_index: Vali target_pubkey = state.validators[validator_index].pubkey sync_committee_indices = [index for index, pubkey in enumerate(sync_committee.pubkeys) if pubkey == target_pubkey] - return [ + return set([ uint64(index // (SYNC_COMMITTEE_SIZE // SYNC_COMMITTEE_SUBNET_COUNT)) for index in sync_committee_indices - ] + ]) ``` *Note*: Subnet assignment does not change during the duration of a validator's assignment to a given sync committee. From 5dd29b6659c0f4bc05b01390d577d8d9f908636a Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Fri, 14 May 2021 06:15:48 -0600 Subject: [PATCH 2/2] fix tests and minor copy edit --- specs/altair/validator.md | 4 ++-- .../test/altair/unittests/validator/test_validator.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/specs/altair/validator.md b/specs/altair/validator.md index e6e00a674..3b3362b22 100644 --- a/specs/altair/validator.md +++ b/specs/altair/validator.md @@ -292,10 +292,10 @@ The validator broadcasts the assembled signature to the assigned subnet, the `sy The `subnet_id` is derived from the position in the sync committee such that the sync committee is divided into "subcommittees". `subnet_id` can be computed via `compute_subnets_for_sync_committee(state, validator_index)` where `state` is a `BeaconState` during the matching sync committee period. -*Note*: This function returns multiple non-duplicated subnets if a given validator index is included multiple times in a given sync committee across multiple subcommittees. +*Note*: This function returns multiple deduplicated subnets if a given validator index is included multiple times in a given sync committee across multiple subcommittees. ```python -def compute_subnets_for_sync_committee(state: BeaconState, validator_index: ValidatorIndex) -> Sequence[uint64]: +def compute_subnets_for_sync_committee(state: BeaconState, validator_index: ValidatorIndex) -> Set[uint64]: next_slot_epoch = compute_epoch_at_slot(Slot(state.slot + 1)) if compute_sync_committee_period(get_current_epoch(state)) == compute_sync_committee_period(next_slot_epoch): sync_committee = state.current_sync_committee diff --git a/tests/core/pyspec/eth2spec/test/altair/unittests/validator/test_validator.py b/tests/core/pyspec/eth2spec/test/altair/unittests/validator/test_validator.py index cefaaf694..18fb730d7 100644 --- a/tests/core/pyspec/eth2spec/test/altair/unittests/validator/test_validator.py +++ b/tests/core/pyspec/eth2spec/test/altair/unittests/validator/test_validator.py @@ -149,9 +149,10 @@ def _subnet_for_sync_committee_index(spec, i): def _get_expected_subnets_by_pubkey(sync_committee_members): - expected_subnets_by_pubkey = defaultdict(list) + # Build deduplicated set for each pubkey + expected_subnets_by_pubkey = defaultdict(set) for (subnet, pubkey) in sync_committee_members: - expected_subnets_by_pubkey[pubkey].append(subnet) + expected_subnets_by_pubkey[pubkey].add(subnet) return expected_subnets_by_pubkey