Skip to content

Commit

Permalink
Merge pull request #2889 from jtraglia/remove-set-sampling
Browse files Browse the repository at this point in the history
Convert sets to sorted lists prior to sampling
  • Loading branch information
hwwhww authored May 10, 2022
2 parents c1d0836 + 90c1825 commit 96de0fe
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
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

0 comments on commit 96de0fe

Please sign in to comment.