Fix `run_sync_committee_sanity_test` so that it works with duplicate committee indices

This commit is contained in:
Hsiao-Wei Wang 2021-10-07 03:29:09 +08:00
parent 7a7ab81306
commit 4ae8fb182e
No known key found for this signature in database
GPG Key ID: 1111A8A81778319E
1 changed files with 8 additions and 2 deletions

View File

@ -23,13 +23,19 @@ from eth2spec.test.helpers.inactivity_scores import randomize_inactivity_scores
def run_sync_committee_sanity_test(spec, state, fraction_full=1.0, rng=Random(454545)):
all_pubkeys = [v.pubkey for v in state.validators]
committee = [all_pubkeys.index(pubkey) for pubkey in state.current_sync_committee.pubkeys]
participants = rng.sample(committee, int(len(committee) * fraction_full))
selected_indices = rng.sample(list(range(len(committee))), int(len(committee) * fraction_full))
sync_committee_bits = [True if i in selected_indices else False for i in range(len(committee))]
participants = [
validator_index
for i, validator_index in enumerate(committee)
if sync_committee_bits[i]
]
yield 'pre', state
block = build_empty_block_for_next_slot(spec, state)
block.body.sync_aggregate = spec.SyncAggregate(
sync_committee_bits=[index in participants for index in committee],
sync_committee_bits=sync_committee_bits,
sync_committee_signature=compute_aggregate_sync_committee_signature(
spec,
state,