Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert sets to sorted lists prior to sampling #2889

Merged
merged 3 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _drop_random_quarter(_slot, _index, indices):
assert committee_len >= 4
filter_len = committee_len // 4
participant_count = committee_len - filter_len
return rng.sample(indices, participant_count)
return rng.sample(sorted(indices), participant_count)

yield from _run_transition_test_with_attestations(
state,
Expand All @@ -304,7 +304,7 @@ def _drop_random_half(_slot, _index, indices):
assert committee_len >= 2
filter_len = committee_len // 2
participant_count = committee_len - filter_len
return rng.sample(indices, participant_count)
return rng.sample(sorted(indices), participant_count)

yield from _run_transition_test_with_attestations(
state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_is_assigned_to_sync_committee(spec, state):
if disqualified_pubkeys:
sample_size = 3
assert validator_count >= sample_size
some_pubkeys = rng.sample(disqualified_pubkeys, sample_size)
some_pubkeys = rng.sample(sorted(disqualified_pubkeys), sample_size)
for pubkey in some_pubkeys:
validator_index = active_pubkeys.index(pubkey)
is_current = spec.is_assigned_to_sync_committee(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,45 +200,63 @@ def participation_tracker(slot, comm_index, comm):
@spec_state_test
def test_almost_empty_attestations(spec, state):
rng = Random(1234)
yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, 1))

def participation_fn(slot, comm_index, comm):
return rng.sample(sorted(comm), 1)
yield from run_with_participation(spec, state, participation_fn)


@with_all_phases
@spec_state_test
@leaking()
def test_almost_empty_attestations_with_leak(spec, state):
rng = Random(1234)
yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, 1))

def participation_fn(slot, comm_index, comm):
return rng.sample(sorted(comm), 1)
yield from run_with_participation(spec, state, participation_fn)


@with_all_phases
@spec_state_test
def test_random_fill_attestations(spec, state):
rng = Random(4567)
yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, len(comm) // 3))

def participation_fn(slot, comm_index, comm):
return rng.sample(sorted(comm), len(comm) // 3)
yield from run_with_participation(spec, state, participation_fn)


@with_all_phases
@spec_state_test
@leaking()
def test_random_fill_attestations_with_leak(spec, state):
rng = Random(4567)
yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, len(comm) // 3))

def participation_fn(slot, comm_index, comm):
return rng.sample(sorted(comm), len(comm) // 3)
yield from run_with_participation(spec, state, participation_fn)


@with_all_phases
@spec_state_test
def test_almost_full_attestations(spec, state):
rng = Random(8901)
yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, len(comm) - 1))

def participation_fn(slot, comm_index, comm):
return rng.sample(sorted(comm), len(comm) - 1)
yield from run_with_participation(spec, state, participation_fn)


@with_all_phases
@spec_state_test
@leaking()
def test_almost_full_attestations_with_leak(spec, state):
rng = Random(8901)
yield from run_with_participation(spec, state, lambda slot, comm_index, comm: rng.sample(comm, len(comm) - 1))

def participation_fn(slot, comm_index, comm):
return rng.sample(sorted(comm), len(comm) - 1)
yield from run_with_participation(spec, state, participation_fn)


@with_all_phases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _drop_random_one_third(_slot, _index, indices):
assert committee_len >= 3
filter_len = committee_len // 3
participant_count = committee_len - filter_len
return rng.sample(indices, participant_count)
return rng.sample(sorted(indices), participant_count)


@with_all_phases
Expand Down