-
Notifications
You must be signed in to change notification settings - Fork 182
feat(fill): add a plugin for optional execution witness generation #2066
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f67704d
feat(fixtures): add `executionWitness` to `FixtureBlockBase`
danceratopz 3f5be35
feat(fill): add a plugin for execution witness generation
danceratopz 6e4d8ee
feat(fill): use the `generate_witness` fixture in the `filler` plugin
danceratopz c43c1ba
feat(fill,help): enable witness plugin help output to `fill --help`.
danceratopz d2eddbf
chore(fill): fix punctuation in witness plugin help string
danceratopz a2bb2b1
chore(fill): add hotfix to generate_witness for Paris
danceratopz 9be75e8
docs: update changelog
danceratopz 4bb6019
fill: update witness-filler ref as requested by jsign
danceratopz 9de8401
fixtures: change WitnessChunk from dataclass to CamelModel
danceratopz c8d28da
fixtures: rename WitnessChunk json parser helper method
danceratopz 14494fd
fill: add a WitnessFillerResult to validate witness-filler output
danceratopz 7ead93c
refactor(fill): improve `generate_witness` fixture & fork checks
danceratopz bd5c72a
chore(fixtures): remove unncessary pydantic field alias
danceratopz 6c4551a
chore(fill): exit on error if witness-filler is unavailable
danceratopz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
""" | ||
Pytest plugin for witness functionality. | ||
Provides --witness command-line option that installs the witness-filler tool | ||
and generates execution witness data for blockchain test fixtures when enabled. | ||
""" | ||
|
||
import subprocess | ||
from typing import Any, Callable | ||
|
||
import pytest | ||
|
||
from ethereum_test_fixtures.blockchain import FixtureBlock, WitnessChunk | ||
|
||
|
||
def pytest_addoption(parser: pytest.Parser): | ||
"""Add witness command-line options to pytest.""" | ||
witness_group = parser.getgroup("witness", "Arguments for witness functionality") | ||
witness_group.addoption( | ||
"--witness", | ||
"--witness-the-fitness", | ||
danceratopz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
action="store_true", | ||
dest="witness", | ||
default=False, | ||
help=( | ||
"Install the witness-filler tool and generate execution witness data for blockchain " | ||
"test fixtures." | ||
), | ||
) | ||
|
||
|
||
def pytest_configure(config): | ||
""" | ||
Pytest hook called after command line options have been parsed. | ||
If --witness is enabled, installs the witness-filler tool from the specified | ||
git repository. | ||
""" | ||
if config.getoption("witness"): | ||
print("🔧 Installing witness-filler tool from kevaundray/reth...") | ||
print(" This may take several minutes for first-time compilation...") | ||
|
||
result = subprocess.run( | ||
[ | ||
"cargo", | ||
"install", | ||
"--git", | ||
"https://github.com/kevaundray/reth.git", | ||
"--rev", | ||
"8016a8a5736e4427b3d285c82cd39c4ece70f8c4", | ||
danceratopz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
"witness-filler", | ||
], | ||
) | ||
marioevz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
if result.returncode != 0: | ||
pytest.exit( | ||
f"Failed to install witness-filler tool (exit code: {result.returncode}). " | ||
"Please ensure you have a compatible Rust toolchain installed. " | ||
"You may need to update your Rust version to 1.86+ or run without --witness.", | ||
1, | ||
) | ||
else: | ||
print("✅ witness-filler tool installed successfully!") | ||
|
||
|
||
@pytest.fixture | ||
def witness_generator(request: pytest.FixtureRequest) -> Callable[[Any], None] | None: | ||
""" | ||
Provide a witness generator function if --witness is enabled. | ||
Returns: | ||
None if witness functionality is disabled. | ||
Callable that generates witness data for a fixture if enabled. | ||
""" | ||
if not request.config.getoption("witness"): | ||
return None | ||
|
||
def generate_witness(fixture: Any) -> None: | ||
"""Generate witness data for a fixture using the witness-filler tool.""" | ||
if not hasattr(fixture, "blocks") or not fixture.blocks: | ||
return | ||
danceratopz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
# Hotfix: witness-filler expects "Merge" but execution-spec-tests uses "Paris" | ||
original_fork = None | ||
if hasattr(fixture, "fork") and str(fixture.fork) == "Paris": | ||
original_fork = fixture.fork | ||
fixture.fork = "Merge" | ||
|
||
try: | ||
result = subprocess.run( | ||
["witness-filler"], | ||
input=fixture.model_dump_json(by_alias=True), | ||
text=True, | ||
capture_output=True, | ||
) | ||
finally: | ||
# Restore original fork value | ||
if original_fork is not None: | ||
fixture.fork = original_fork | ||
|
||
if result.returncode != 0: | ||
raise RuntimeError( | ||
f"witness-filler tool failed with exit code {result.returncode}. " | ||
f"stderr: {result.stderr}" | ||
) | ||
|
||
try: | ||
witnesses = WitnessChunk.from_json(result.stdout) | ||
for i, witness in enumerate(witnesses): | ||
if i < len(fixture.blocks) and isinstance(fixture.blocks[i], FixtureBlock): | ||
fixture.blocks[i].execution_witness = witness | ||
except (ValueError, IndexError, AttributeError) as e: | ||
raise RuntimeError( | ||
f"Failed to parse witness data from witness-filler tool. " | ||
f"Output was: {result.stdout[:500]}{'...' if len(result.stdout) > 500 else ''}" | ||
) from e | ||
danceratopz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
return generate_witness |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.