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

Add Fork Choice compliance test generator #3831

Draft
wants to merge 113 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
68deb2d
Implement basic version of SM link generator
mkalinin Dec 12, 2023
f989f37
Remove numpy as a dependency
mkalinin Dec 18, 2023
967445f
Clean up generator's code
mkalinin Dec 18, 2023
2101e9f
Add debug output
mkalinin Dec 18, 2023
507bac8
Add anchor_epoch as a parameter and debug checks
mkalinin Dec 18, 2023
5885bf4
Switch sm_links generator to minizinc model
mkalinin Dec 19, 2023
0c7ff17
Rename sm_links test and its deps
mkalinin Dec 21, 2023
a6e9dd5
Disable debug mode
mkalinin Dec 21, 2023
e00346a
Fixes and polishing
mkalinin Dec 21, 2023
cf38551
Update sm_links test and generator
mkalinin Dec 28, 2023
ae322c7
Fix contraint reachability problem
mkalinin Dec 28, 2023
3a2d5fe
Update debug output
mkalinin Dec 28, 2023
995cab2
Add CLI args to fork choice generator
mkalinin Dec 29, 2023
beac058
Fix bugs, inrease verbosity
mkalinin Feb 13, 2024
e07f580
Add basic block tree model instantiator
mkalinin Feb 15, 2024
aab9f4b
Minor fixes
mkalinin Feb 27, 2024
c46b9a3
Add block cover instantiator
mkalinin Mar 14, 2024
84c658b
Update block_cover3 model and fix instantiator
mkalinin Mar 29, 2024
e4b4556
Sort tips before sampling
ericsson49 Apr 1, 2024
71e70ad
Added an option to pre-generated model instances: `--fc-gen-instances…
ericsson49 Apr 1, 2024
0f358da
Sample yaml file with pre-generated instances
ericsson49 Apr 1, 2024
c819ef4
minor fixes
ericsson49 Apr 1, 2024
9b5f6ec
rename params
ericsson49 Apr 1, 2024
a0999cd
Modified `filter_block_tree_generator.py`: added an option to loa pre…
ericsson49 Apr 1, 2024
5f00017
Implement on_attestation
mkalinin Apr 6, 2024
310893c
Implement attester slashings
mkalinin Apr 7, 2024
cc852ca
Update block tree model
mkalinin Apr 8, 2024
d477b33
Added `test_gen.py` driver to generate all tests from a single confi.
ericsson49 Apr 2, 2024
b0be1ae
Implement invalid blocks
mkalinin Apr 8, 2024
b563381
Omit valid: true for on_attestation
mkalinin Apr 9, 2024
e59e612
Mutation operators/shuffling added.
ericsson49 Apr 9, 2024
cedc82f
Added customizeable test_name.
ericsson49 Apr 10, 2024
b3dae8f
Pass block parents as a parameter, update block tree model
mkalinin Apr 10, 2024
3eda0b7
Added command line args for `with_attester_slashings` and `with_inval…
ericsson49 Apr 10, 2024
67138ef
Refactor block parents parametrization
mkalinin Apr 10, 2024
54756e9
Modified solutions construction
ericsson49 Apr 10, 2024
f4886e0
Changed block_tree format
ericsson49 Apr 10, 2024
4058856
Added test instances generator (from MiniZinc models to yaml)
ericsson49 Apr 10, 2024
8cc662b
Add invalid attestations and slashings
mkalinin Apr 11, 2024
12c214e
Handle slashed proposer as it were a regular invalid block
mkalinin Apr 11, 2024
573b5ef
Fix valid block production
mkalinin Apr 11, 2024
1f80417
fix solutions construction
ericsson49 Apr 11, 2024
be1b1f8
fixed file format (`sm_links` instead of `sources/targets`)
ericsson49 Apr 11, 2024
db5b03f
renamed GENERATOR_NAME
ericsson49 Apr 11, 2024
d4b33cb
fixed solution constuction (`sm_links` instead of `sources/targets`)
ericsson49 Apr 11, 2024
84ca475
Added a command line option to pass the test_gen configuration path
ericsson49 Apr 16, 2024
991d026
Ensure voting source matches the attestation source
mkalinin Apr 22, 2024
40aadb3
Remove over constraining assert check
mkalinin Apr 22, 2024
c4ca1bc
Ensure that epoch 1 is not supposed to be justified
mkalinin Apr 23, 2024
4c9e402
Re-formatted test_gen config
ericsson49 Apr 23, 2024
c6a1496
Refactoring of test generator routines: streamline code organization
ericsson49 Apr 23, 2024
6bf265a
Improve block cover instantiator to accommodate for more blocks
mkalinin Apr 24, 2024
0ff437a
Fix unexpected justifed checkpoint in block cover
mkalinin Apr 25, 2024
00abe77
Make block cover instantiator more flexible
mkalinin Apr 25, 2024
3c5ca9d
Make justified epoch 1 check stricter
mkalinin Apr 26, 2024
8b34ac8
Fixed bug in `is_leaf``
ericsson49 Apr 25, 2024
3ad01e4
temporary small refactoring
ericsson49 May 1, 2024
d2e029b
refactoring
ericsson49 May 1, 2024
d1dd31d
Extend FC checks with filtered block weights
mkalinin May 10, 2024
371288c
Move instantiators into a separate dir
mkalinin May 10, 2024
faee7d5
Unify test case instantiator
mkalinin May 11, 2024
fe5b078
new instance configurations added: small, smoke, standard
ericsson49 May 15, 2024
909a9f5
new testgen configs added: small, smoke and standard
ericsson49 May 15, 2024
51e68f0
add block_cover instances
ericsson49 May 15, 2024
2a352b0
add block_tree_tree instances
ericsson49 May 15, 2024
255f01e
add block_tree_other instances
ericsson49 May 15, 2024
50df903
fix typos
ericsson49 May 15, 2024
6f08518
put test configs into separate directories
ericsson49 May 15, 2024
6af67eb
Fix test DNA file paths to run test_gen from root dir
mkalinin May 29, 2024
6af1e9e
Use pyspec_tests suite name for fc generated tests
mkalinin May 29, 2024
c428779
Add bls_setting to meta data for fc generated tests
mkalinin May 29, 2024
f3a7194
Add pseudo randao_reveal for fc generated tests
mkalinin May 29, 2024
b049f90
Replace filtered_block_weights with viable_for_head_roots_and_weights
mkalinin May 29, 2024
de42529
Fix pseudo randao_reveal computation
mkalinin May 29, 2024
a6af078
Make MutationGenerator serializeable
ericsson49 May 30, 2024
f99592b
Make TestProviders finer granular
ericsson49 May 30, 2024
789704f
Fixed typo in standard/block_cover config
ericsson49 May 30, 2024
22b2a90
Fixed a problem with running in multiprocessor node - incompatible re…
ericsson49 Jun 11, 2024
a2c0997
Added shuffling_test (by splitting block_weight_test)
ericsson49 Jun 11, 2024
bbdae54
renamed small -> tiny, smoke -> small
ericsson49 Jun 11, 2024
bd5e38b
renamed small -> tiny, smoke -> small
ericsson49 Jun 11, 2024
e6505df
renamed small -> tiny, smoke -> small
ericsson49 Jun 11, 2024
399fd16
Refactoring to improve code structure and ensure deterministic behavi…
ericsson49 Jun 12, 2024
bb56274
Code restructuring
ericsson49 Jun 12, 2024
c9c345b
refactored code, to use test data from instantiators, instead of full…
ericsson49 Jun 18, 2024
638642b
Code reorg: make helper methods
ericsson49 Jun 19, 2024
fd21a46
split `yield_fork_choice_test_case` into two steps:
ericsson49 Jun 19, 2024
aa91e8d
refactoring of mutated test generation
ericsson49 Jun 19, 2024
7fe26e6
re-worked test generation: skip duplicate tick events
ericsson49 Jun 20, 2024
8233c8c
Links added:
ericsson49 Jun 25, 2024
05bbbc7
Test runner added
ericsson49 Jun 27, 2024
3cec3f1
Typos fixed - increase amount of tests for shuffling test
ericsson49 Jun 27, 2024
c947d0c
Fixed some bugs with scheduling
ericsson49 Jun 27, 2024
7c9ddbb
Move mutation_operators to instantiators
ericsson49 Jun 27, 2024
f184254
Extend fork choice test format
mkalinin Jun 28, 2024
47199a3
remove with_viable_for_head_weights=True (kept by mistake)
ericsson49 Jun 28, 2024
02a0287
put back MutationOps (dropped by mistake)
ericsson49 Jun 28, 2024
423515e
switch to DENEB as the default fork
ericsson49 Jun 28, 2024
9930464
remove debug prints and recovery property from test steps
ericsson49 Jul 1, 2024
6a27e1e
drop unnecessary comments
ericsson49 Jul 1, 2024
5a14ef6
Drop `checks_with_viable_for_head_weights` which is not a part of `on…
ericsson49 Jul 1, 2024
8545060
Merge pull request #17 from ericsson49/fc-compliance2
mkalinin Jul 1, 2024
4ed16ab
added `viable_for_head_roots_and_weights` check description
ericsson49 Jul 1, 2024
fb3ff0f
fixed names (small -> tiny, smoke -> small)
ericsson49 Jul 1, 2024
c494a96
added instructions how to generate and run tests
ericsson49 Jul 1, 2024
fb231de
Update README.md
ericsson49 Jul 1, 2024
eeafb1c
Update README.md
ericsson49 Jul 1, 2024
959274f
Update tests/formats/fork_choice/README.md
ericsson49 Jul 2, 2024
ce897c8
Fix viable_for_head_roots_and_weights in example
mkalinin Jul 2, 2024
4a0745b
Merge pull request #19 from ericsson49/fc-compliance2
mkalinin Jul 2, 2024
543ec86
Added a line about EF grant
ericsson49 Jul 3, 2024
1854266
Changed viable_for_head_roots_and_weights format
ericsson49 Jul 3, 2024
2eb1575
Added CLI switch to turn on multiprocessing mode
ericsson49 Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,7 @@ def should_skip_case_dir(case_dir, is_force, diagnostics_obj):
return is_skip, diagnostics_obj


def run_generator(generator_name, test_providers: Iterable[TestProvider]):
"""
Implementation for a general test generator.
:param generator_name: The name of the generator. (lowercase snake_case)
:param test_providers: A list of test provider,
each of these returns a callable that returns an iterable of test cases.
The call to get the iterable may set global configuration,
and the iterable should not be resumed after a pause with a change of that configuration.
:return:
"""

def create_arg_parser(generator_name: str) -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog="gen-" + generator_name,
description=f"Generate YAML test suite files for {generator_name}",
Expand Down Expand Up @@ -194,6 +184,23 @@ def run_generator(generator_name, test_providers: Iterable[TestProvider]):
help="if set only print tests to generate, do not actually run the test and dump the target data",
)

return parser


def run_generator(generator_name, test_providers: Iterable[TestProvider], parser: argparse.ArgumentParser = None):
"""
Implementation for a general test generator.
:param generator_name: The name of the generator. (lowercase snake_case)
:param test_providers: A list of test provider,
each of these returns a callable that returns an iterable of test cases.
The call to get the iterable may set global configuration,
and the iterable should not be resumed after a pause with a change of that configuration.
:return:
"""

if parser is None:
parser = create_arg_parser(generator_name)

args = parser.parse_args()
output_dir = args.output_dir
if not args.force:
Expand Down
55 changes: 36 additions & 19 deletions tests/core/pyspec/eth2spec/test/helpers/fork_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ def run_func():
yield from with_blob_data(spec, blob_data, run_func)


def add_attestation(spec, store, attestation, test_steps, is_from_block=False):
spec.on_attestation(store, attestation, is_from_block=is_from_block)
def add_attestation(spec, store, attestation, test_steps, is_from_block=False, valid=True):
run_on_attestation(spec, store, attestation, is_from_block=is_from_block, valid=valid)
yield get_attestation_file_name(attestation), attestation
test_steps.append({'attestation': get_attestation_file_name(attestation)})
if valid:
test_steps.append({'attestation': get_attestation_file_name(attestation)})
else:
test_steps.append({'attestation': get_attestation_file_name(attestation), 'valid': False})


def add_attestations(spec, store, attestations, test_steps, is_from_block=False):
Expand Down Expand Up @@ -282,22 +285,36 @@ def output_head_check(spec, store, test_steps):
})


def output_store_checks(spec, store, test_steps):
test_steps.append({
'checks': {
'time': int(store.time),
'head': get_formatted_head_output(spec, store),
'justified_checkpoint': {
'epoch': int(store.justified_checkpoint.epoch),
'root': encode_hex(store.justified_checkpoint.root),
},
'finalized_checkpoint': {
'epoch': int(store.finalized_checkpoint.epoch),
'root': encode_hex(store.finalized_checkpoint.root),
},
'proposer_boost_root': encode_hex(store.proposer_boost_root),
}
})
def output_store_checks(spec, store, test_steps, with_viable_for_head_weights=False):
checks = {
'time': int(store.time),
'head': get_formatted_head_output(spec, store),
'justified_checkpoint': {
'epoch': int(store.justified_checkpoint.epoch),
'root': encode_hex(store.justified_checkpoint.root),
},
'finalized_checkpoint': {
'epoch': int(store.finalized_checkpoint.epoch),
'root': encode_hex(store.finalized_checkpoint.root),
},
'proposer_boost_root': encode_hex(store.proposer_boost_root),
}

if with_viable_for_head_weights:
filtered_block_roots = spec.get_filtered_block_tree(store).keys()
leaves_viable_for_head = [root for root in filtered_block_roots
if not any(c for c in filtered_block_roots if store.blocks[c].parent_root == root)]

viable_for_head_roots_and_weights = [
{
'root': encode_hex(viable_for_head_root),
'weight': int(spec.get_weight(store, viable_for_head_root))
}
for viable_for_head_root in leaves_viable_for_head
]
checks['viable_for_head_roots_and_weights'] = viable_for_head_roots_and_weights

test_steps.append({'checks': checks})


def apply_next_epoch_with_attestations(spec,
Expand Down
Loading