Skip to content

Commit

Permalink
feat: extra tweaks & additions to eels-e-r.
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-tb committed Sep 6, 2024
1 parent 1c23c59 commit 2c02f48
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 74 deletions.
92 changes: 21 additions & 71 deletions src/evm_transition_tool/execution_specs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Ethereum Specs EVM Transition tool interface.
Ethereum Specs EVM Resolver Transition Tool Interface.
https://github.com/ethereum/execution-specs
https://github.com/petertdavies/ethereum-spec-evm-resolver
"""

import subprocess
Expand All @@ -20,76 +20,23 @@

class ExecutionSpecsTransitionTool(TransitionTool):
"""
Ethereum Specs `ethereum-spec-evm` Transition tool interface wrapper class.
The behavior of this tool is almost identical to go-ethereum's `evm t8n` command.
note: Using the latest version of the `ethereum-spec-evm` tool:
As the `ethereum` package provided by `execution-specs` is a requirement of
`execution-spec-tests`, the `ethereum-spec-evm` is already installed in the
virtual environment where `execution-spec-tests` is installed
(via `pip install -e .`). Therefore, the `ethereum-spec-evm` transition tool
can be used to fill tests via:
```console
fill --evm-bin=ethereum-spec-evm
```
To ensure you're using the latest version of `ethereum-spec-evm` you can run:
```
pip install --force-reinstall -e .
```
or
```
pip install --force-reinstall -e .[docs,lint,tests]
```
as appropriate.
note: Using a specific version of the `ethereum-spec-evm` tool:
1. Create a virtual environment and activate it:
```
python -m venv venv-execution-specs
source venv-execution-specs/bin/activate
```
2. Clone the ethereum/execution-specs repository, change working directory to it and
retrieve the desired version of the repository:
```
git clone [email protected]:ethereum/execution-specs.git
cd execution-specs
git checkout <version>
```
3. Install the packages provided by the repository:
```
pip install -e .
```
Check that the `ethereum-spec-evm` command is available:
```
ethereum-spec-evm --help
```
4. Clone the ethereum/execution-specs-tests repository and change working directory to it:
```
cd ..
git clone [email protected]:ethereum/execution-spec-tests.git
cd execution-spec-tests
```
5. Install the packages provided by the ethereum/execution-spec-tests repository:
```
pip install -e .
```
6. Run the tests, specifying the `ethereum-spec-evm` command as the transition tool:
```
fill --evm-bin=path/to/venv-execution-specs/ethereum-spec-evm
```
Ethereum Specs EVM Resolver `ethereum-spec-evm-resolver` Transition Tool wrapper class.
`ethereum-spec-evm-resolver` is installed by default for `execution-spec-tests`:
```console
uv run fill --evm-bin=ethereum-spec-evm
```
To use a specific version of the `ethereum-spec-evm-resolver` tool, update it to the
desired version in `pyproject.toml`.
The `ethereum-spec-evm-resolver` tool essentially wraps around the EELS evm daemon. It can
handle requests for different EVM forks, even when those forks are implemented by different
versions of EELS hosted in different places.
"""

default_binary = Path("ethereum-spec-evm")
detect_binary_pattern = compile(r"^ethereum-spec-evm\b")
default_binary = Path("ethereum-spec-evm-resolver")
detect_binary_pattern = compile(r"^ethereum-spec-evm-resolver\b")
t8n_use_server: bool = True
server_dir: Optional[TemporaryDirectory] = None

Expand All @@ -105,7 +52,8 @@ def __init__(
result = subprocess.run(args, capture_output=True, text=True)
except subprocess.CalledProcessError as e:
raise Exception(
"ethereum-spec-evm process unexpectedly returned a non-zero status code: " f"{e}."
"ethereum-spec-evm-resolver process unexpectedly returned a non-zero status code: "
f"{e}."
)
except Exception as e:
raise Exception(f"Unexpected exception calling ethereum-spec-evm: {e}.")
Expand All @@ -126,6 +74,8 @@ def start_server(self):
"--uds",
self.server_file_path,
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
start = time.time()
while True:
Expand Down
41 changes: 40 additions & 1 deletion src/evm_transition_tool/transition_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,22 +394,61 @@ def _evaluate_server(
"""
Executes the transition tool sending inputs and outputs via a server.
"""
input_contents = t8n_data.to_input()
input_json = input_contents.model_dump(mode="json", **model_dump_config)
post_data = {
"state": {
"fork": t8n_data.fork_name,
"chainid": t8n_data.chain_id,
"reward": t8n_data.reward,
},
"input": t8n_data.to_input().model_dump(mode="json", **model_dump_config),
"input": input_json,
}

if debug_output_path:
request_info = (
f"Server URL: {self.server_url}\n\n"
f"Request Data:\n{json.dumps(post_data, indent=2)}\n"
)
dump_files_to_directory(
debug_output_path,
{
"input/alloc.json": input_contents.alloc,
"input/env.json": input_contents.env,
"input/txs.json": [
tx.model_dump(mode="json", **model_dump_config)
for tx in input_contents.txs
],
"request_info.txt": request_info,
},
)

response = Session().post(self.server_url, json=post_data, timeout=10)
response.raise_for_status() # exception visible in pytest failure output
if response.status_code != 200:
raise Exception(
f"t8n-server returned status code {response.status_code}, "
f"response: {response.text}"
)

output: TransitionToolOutput = TransitionToolOutput.model_validate(response.json())

if debug_output_path:
response_info = (
f"Status Code: {response.status_code}\n\n"
f"Headers:\n{json.dumps(dict(response.headers), indent=2)}\n\n"
f"Content:\n{response.text}\n"
)
dump_files_to_directory(
debug_output_path,
{
"output/alloc.json": output.alloc,
"output/result.json": output.result,
"output/txs.rlp": str(output.body),
"response_info.txt": response_info,
},
)

return output

def _evaluate_stream(
Expand Down
4 changes: 2 additions & 2 deletions src/pytest_plugins/forks/forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ def get_fork_option(config, option_name: str, parameter_name: str) -> Set[Fork]:

evm_bin = config.getoption("evm_bin")
t8n = TransitionTool.from_binary_path(binary_path=evm_bin)
config.unsupported_forks = frozenset(
filter(lambda fork: not t8n.is_fork_supported(fork), fork_set) # type: ignore
config.unsupported_forks = frozenset( # type: ignore
filter(lambda fork: not t8n.is_fork_supported(fork), fork_set)
)


Expand Down

0 comments on commit 2c02f48

Please sign in to comment.