From 47199a3063f2fff0217410e4ed3a0beb2ff9cd5f Mon Sep 17 00:00:00 2001 From: Alex Vlasov Date: Fri, 28 Jun 2024 19:24:13 +0400 Subject: [PATCH 1/6] remove with_viable_for_head_weights=True (kept by mistake) --- .../fork_choice_generated/instantiators/helpers.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/generators/fork_choice_generated/instantiators/helpers.py b/tests/generators/fork_choice_generated/instantiators/helpers.py index 1ccb056160..cb8c2c76ff 100644 --- a/tests/generators/fork_choice_generated/instantiators/helpers.py +++ b/tests/generators/fork_choice_generated/instantiators/helpers.py @@ -370,14 +370,14 @@ def try_add_mesage(runner, message): return False # record initial tick - on_tick_and_append_step(spec, store, store.time, test_steps, checks_with_viable_for_head_weights=True) + on_tick_and_append_step(spec, store, store.time, test_steps) for event in test_events: event_kind = event[0] if event_kind == 'tick': _, time, _ = event if time > store.time: - on_tick_and_append_step(spec, store, time, test_steps, checks_with_viable_for_head_weights=True) + on_tick_and_append_step(spec, store, time, test_steps) assert store.time == time elif event_kind == 'block': _, signed_block, valid = event @@ -391,19 +391,19 @@ def try_add_mesage(runner, message): assert store.blocks[block_root] == signed_block.message else: assert block_root not in store.blocks.values() - output_store_checks(spec, store, test_steps, with_viable_for_head_weights=True) + output_store_checks(spec, store, test_steps) elif event_kind == 'attestation': _, attestation, valid = event if valid is None: valid = try_add_mesage(run_on_attestation, attestation) yield from add_attestation(spec, store, attestation, test_steps, valid=valid) - output_store_checks(spec, store, test_steps, with_viable_for_head_weights=True) + output_store_checks(spec, store, test_steps) elif event_kind == 'attester_slashing': _, attester_slashing, valid = event if valid is None: valid = try_add_mesage(run_on_attester_slashing, attester_slashing) yield from add_attester_slashing(spec, store, attester_slashing, test_steps, valid=valid) - output_store_checks(spec, store, test_steps, with_viable_for_head_weights=True) + output_store_checks(spec, store, test_steps) else: raise ValueError('Unknown event ' + str(event_kind)) From 02a02872db51b338991afdceb3aa1270a1b9a874 Mon Sep 17 00:00:00 2001 From: Alex Vlasov Date: Fri, 28 Jun 2024 19:27:05 +0400 Subject: [PATCH 2/6] put back MutationOps (dropped by mistake) --- .../instantiators/mutation_operators.py | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/generators/fork_choice_generated/instantiators/mutation_operators.py b/tests/generators/fork_choice_generated/instantiators/mutation_operators.py index 1f68170aa7..d5fdeb6ea2 100644 --- a/tests/generators/fork_choice_generated/instantiators/mutation_operators.py +++ b/tests/generators/fork_choice_generated/instantiators/mutation_operators.py @@ -6,6 +6,8 @@ def mut_shift_(tv, idx, delta): new_time = int(time) + delta if new_time >= 0: return sorted(tv[:idx] + [(new_time, event)] + tv[idx+1:], key=lambda x: x[0]) + else: + return idx def mut_shift(tv, rnd: random.Random): @@ -71,3 +73,59 @@ def mutate_test_vector(rnd, initial_tv, cnt, debug=False): else: assert False yield tv_ + + +class MutationOps: + def __init__(self, start_time, seconds_per_slot, shift_bounds=(-2,4)): + self.start_time = int(start_time) + self.seconds_per_slot = int(seconds_per_slot) + self.shift_bounds = shift_bounds + + def apply_shift(self, tv, idx, delta): + return mut_shift_(tv, idx, delta) + + def apply_drop(self, tv, idx): + return mut_drop_(tv, idx) + + def apply_dup_shift(self, tv, idx, delta): + return mut_dup_(tv, idx, delta) + + def apply_mutation(self, tv, op_kind, *params): + if op_kind == 'shift': + return self.apply_shift(tv, *params) + elif op_kind == 'dup_shift': + return self.apply_dup_shift(tv, *params) + elif op_kind == 'drop': + return self.apply_drop(tv, *params) + else: + assert False + + def rand_shift(self, time: int, rnd: random.Random) -> int: + assert time >= self.start_time + neg_shift, pos_shift = self.shift_bounds + min_shift = max(self.start_time - time, neg_shift * self.seconds_per_slot) + max_shift = pos_shift * self.seconds_per_slot + if rnd.randint(0, 1) == 0: + return rnd.randint(min_shift, 0) + else: + return rnd.randint(1, max_shift) + + def rand_mutation(self, tv, rnd: random.Random): + idx = rnd.choice(range(len(tv))) + op_kind = rnd.choice(['shift', 'drop', 'dup_shift']) + if op_kind == 'shift' or op_kind == 'dup_shift': + evt_time = int(tv[idx][0]) + params = idx, self.rand_shift(evt_time, rnd) + else: + params = idx, + return op_kind, *params + + def rand_mutations(self, tv, num, rnd: random.Random): + mutations = [] + for _ in range(num): + if len(tv) == 0: + break + mut_op = self.rand_mutation(tv, rnd) + mutations.append(mut_op) + tv = self.apply_mutation(tv, *mut_op) + return tv, mutations From 423515efd84d8c83db4be802a499bf5b59dd0432 Mon Sep 17 00:00:00 2001 From: Alex Vlasov Date: Fri, 28 Jun 2024 19:36:40 +0400 Subject: [PATCH 3/6] switch to DENEB as the default fork --- tests/generators/fork_choice_generated/instance_generator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/generators/fork_choice_generated/instance_generator.py b/tests/generators/fork_choice_generated/instance_generator.py index 45387a06be..f9dd1fb335 100644 --- a/tests/generators/fork_choice_generated/instance_generator.py +++ b/tests/generators/fork_choice_generated/instance_generator.py @@ -1,4 +1,4 @@ -from eth2spec.test.helpers.constants import ALTAIR +from eth2spec.test.helpers.constants import ALTAIR, DENEB from eth2spec.gen_helpers.gen_base import gen_runner from eth2spec.test.helpers.constants import MINIMAL, MAINNET from itertools import product @@ -9,7 +9,7 @@ from test_provider import GENERATOR_NAME, create_providers -forks = [ALTAIR] +forks = [DENEB] presets = [MINIMAL] From 9930464967799db8d9e372959e9fda14822214eb Mon Sep 17 00:00:00 2001 From: Alex Vlasov Date: Mon, 1 Jul 2024 04:21:57 +0400 Subject: [PATCH 4/6] remove debug prints and recovery property from test steps --- .../fork_choice_generated/test_provider.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/generators/fork_choice_generated/test_provider.py b/tests/generators/fork_choice_generated/test_provider.py index 0bf1dac836..bf614d2cc4 100644 --- a/tests/generators/fork_choice_generated/test_provider.py +++ b/tests/generators/fork_choice_generated/test_provider.py @@ -172,15 +172,15 @@ def yield_test_parts(spec, store, test_data: FCTestData, events): elif event_kind == 'block': assert recovery _block_id = get_block_file_name(event_data) - print('recovered block', _block_id) - test_steps.append({'block': _block_id, 'valid': True, 'recovery': True}) + #print('recovered block', _block_id) + test_steps.append({'block': _block_id, 'valid': True}) #, 'recovery': True}) elif event_kind == 'attestation': assert recovery _attestation_id = get_attestation_file_name(event_data) if _attestation_id not in test_data.atts: yield _attestation_id, event_data - print('recovered attestation', _attestation_id) - test_steps.append({'attestation': _attestation_id, 'valid': True, 'recovery': True}) + #print('recovered attestation', _attestation_id) + test_steps.append({'attestation': _attestation_id, 'valid': True}) #, 'recovery': True}) else: assert False else: @@ -201,17 +201,17 @@ def yield_test_parts(spec, store, test_data: FCTestData, events): if event_kind == 'block': _block_id = get_block_file_name(event_data) if recovery: - print('recovered block', _block_id) - test_steps.append({'block': _block_id, 'valid': True, 'recovery': True}) + #print('recovered block', _block_id) + test_steps.append({'block': _block_id, 'valid': True}) #, 'recovery': True}) else: test_steps.append({'block': _block_id, 'valid': True}) elif event_kind == 'attestation': _attestation_id = get_attestation_file_name(event_data) if recovery: - print('recovered attestation', _attestation_id) + #print('recovered attestation', _attestation_id) if _attestation_id not in test_data.atts: yield _attestation_id, event_data - test_steps.append({'attestation': _attestation_id, 'valid': True, 'recovery': True}) + test_steps.append({'attestation': _attestation_id, 'valid': True}) #, 'recovery': True}) else: assert False test_steps.append({'attestation': _attestation_id, 'valid': True}) From 6a27e1e4f165cab841acea96906e60dc7e314277 Mon Sep 17 00:00:00 2001 From: Alex Vlasov Date: Mon, 1 Jul 2024 04:24:12 +0400 Subject: [PATCH 5/6] drop unnecessary comments --- .../fork_choice_generated/test_provider.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/generators/fork_choice_generated/test_provider.py b/tests/generators/fork_choice_generated/test_provider.py index bf614d2cc4..80043d6e87 100644 --- a/tests/generators/fork_choice_generated/test_provider.py +++ b/tests/generators/fork_choice_generated/test_provider.py @@ -172,15 +172,13 @@ def yield_test_parts(spec, store, test_data: FCTestData, events): elif event_kind == 'block': assert recovery _block_id = get_block_file_name(event_data) - #print('recovered block', _block_id) - test_steps.append({'block': _block_id, 'valid': True}) #, 'recovery': True}) + test_steps.append({'block': _block_id, 'valid': True}) elif event_kind == 'attestation': assert recovery _attestation_id = get_attestation_file_name(event_data) if _attestation_id not in test_data.atts: yield _attestation_id, event_data - #print('recovered attestation', _attestation_id) - test_steps.append({'attestation': _attestation_id, 'valid': True}) #, 'recovery': True}) + test_steps.append({'attestation': _attestation_id, 'valid': True}) else: assert False else: @@ -201,17 +199,15 @@ def yield_test_parts(spec, store, test_data: FCTestData, events): if event_kind == 'block': _block_id = get_block_file_name(event_data) if recovery: - #print('recovered block', _block_id) - test_steps.append({'block': _block_id, 'valid': True}) #, 'recovery': True}) + test_steps.append({'block': _block_id, 'valid': True}) else: test_steps.append({'block': _block_id, 'valid': True}) elif event_kind == 'attestation': _attestation_id = get_attestation_file_name(event_data) if recovery: - #print('recovered attestation', _attestation_id) if _attestation_id not in test_data.atts: yield _attestation_id, event_data - test_steps.append({'attestation': _attestation_id, 'valid': True}) #, 'recovery': True}) + test_steps.append({'attestation': _attestation_id, 'valid': True}) else: assert False test_steps.append({'attestation': _attestation_id, 'valid': True}) From 5a14ef6645dc081759b702685749a3aebeb414d8 Mon Sep 17 00:00:00 2001 From: Alex Vlasov Date: Mon, 1 Jul 2024 04:26:04 +0400 Subject: [PATCH 6/6] Drop `checks_with_viable_for_head_weights` which is not a part of `on_tick_and_append_step` yet --- tests/generators/fork_choice_generated/test_provider.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/generators/fork_choice_generated/test_provider.py b/tests/generators/fork_choice_generated/test_provider.py index 80043d6e87..006915cd63 100644 --- a/tests/generators/fork_choice_generated/test_provider.py +++ b/tests/generators/fork_choice_generated/test_provider.py @@ -238,7 +238,8 @@ def yield_test_parts(spec, store, test_data: FCTestData, events): else: raise ValueError(f'not implemented {kind}') next_slot_time = store.genesis_time + (spec.get_current_slot(store) + 1) * spec.config.SECONDS_PER_SLOT - on_tick_and_append_step(spec, store, next_slot_time, test_steps, checks_with_viable_for_head_weights=True) + on_tick_and_append_step(spec, store, next_slot_time, test_steps) + output_store_checks(spec, store, test_steps, with_viable_for_head_weights=True) yield 'steps', test_steps