ethereum / ethereum/execution-specs

Refactor manual retry logic in `execute` plugins to use tenacity

Open
#1,931 1 comment 0 reactions 1 assignee Claimed by @danceratopz View on GitHub
A-test-execute C-refactor stale
Dominant language
Python
Stars
1.2k
Forks
505
Avg merge
2d 14h
Merged PRs (30d)
116

Description

Refactor manual retry logic in `execute` plugins to use tenacity, analogous to https://github.com/ethereum/execution-specs/pull/1930 for `consume` simulators.

The `chain_builder_eth_rpc.py` module contains several manual retry/wait patterns that could benefit from tenacity-based helpers for improved robustness, readability, and potentially faster execution.

### Candidates for Refactoring

**1. Initial Forkchoice Update Retry ([lines 246-259](https://github.com/ethereum/execution-specs/blob/dca59f62f16089e6a3256979b9d218976570140f/packages/testing/src/execution_testing/cli/pytest_commands/plugins/execute/rpc/chain_builder_eth_rpc.py#L246-L259))**

Manual retry loop waiting for `VALID` status:
```python
for _ in range(initial_forkchoice_update_retries):
response = self.engine_rpc.forkchoice_updated(...)
if response.payload_status.status == PayloadStatusEnum.VALID:
break
time.sleep(0.5)
else:
raise Exception("Initial forkchoice_updated was invalid")
```

This is nearly identical to the pattern refactored in #1930. Could directly use `forkchoice_updated_with_retry()`.

**2. Get Payload Wait ([line 319](https://github.com/ethereum/execution-specs/blob/dca59f62f16089e6a3256979b9d218976570140f/packages/testing/src/execution_testing/cli/pytest_commands/plugins/execute/rpc/chain_builder_eth_rpc.py#L319))**

Fixed sleep waiting for payload to be built:
```python
time.sleep(self.get_payload_wait_time)
```

Currently waits a fixed duration before calling `get_payload()`. This could be replaced with a polling approach:
- Try `get_payload()` immediately.
- If the client errors (payload not yet available), retry with short intervals.
- Return as soon as the payload is ready.

This would be faster when clients build payloads quickly, while remaining robust for slower clients. A `get_payload_with_retry()` helper could handle this, with configurable max wait time.

Note: If clients return partial/empty payloads instead of erroring, a smarter retry condition may be needed (e.g., retry while `transactions` list is empty).

**3. Transaction Inclusion Wait ([lines 419-440](https://github.com/ethereum/execution-specs/blob/dca59f62f16089e6a3256979b9d218976570140f/packages/testing/src/execution_testing/cli/pytest_commands/plugins/execute/rpc/chain_builder_eth_rpc.py#L419-L440))**

Manual while loop polling for transaction inclusion:
```python
while True:
# Poll for tx inclusion in blocks
if (time.time() - start_time) > self.transaction_wait_timeout:
break
time.sleep(0.1)
```

More complex logic with pending transaction handling. Lower priority, but could potentially use a `wait_for_transactions_included()` helper.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.