Skip to content

Commit

Permalink
feat(clis): Add parameter slow_request to t8n evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Dec 19, 2024
1 parent 84ce8bd commit c50c5ad
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/ethereum_clis/transition_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

model_dump_config: Mapping = {"by_alias": True, "exclude_none": True}

NORMAL_SERVER_TIMEOUT = 20
SLOW_REQUEST_TIMEOUT = 60


class TransitionTool(EthereumCLI, FixtureVerifier):
"""
Expand Down Expand Up @@ -276,6 +279,7 @@ def _evaluate_filesystem(
def _server_post(
self,
data: Dict[str, Any],
timeout: int,
url_args: Dict[str, List[str] | str] = {},
retries: int = 5,
) -> Response:
Expand All @@ -288,7 +292,7 @@ def _server_post(
response = Session().post(
f"{self.server_url}?{urlencode(url_args, doseq=True)}",
json=data,
timeout=20,
timeout=timeout,
)
break
except ConnectionError as e:
Expand Down Expand Up @@ -316,6 +320,7 @@ def _evaluate_server(
*,
t8n_data: TransitionToolData,
debug_output_path: str = "",
timeout: int,
) -> TransitionToolOutput:
"""
Executes the transition tool sending inputs and outputs via a server.
Expand Down Expand Up @@ -349,7 +354,9 @@ def _evaluate_server(
},
)

response = self._server_post(data=post_data, url_args=self._generate_post_args(t8n_data))
response = self._server_post(
data=post_data, url_args=self._generate_post_args(t8n_data), timeout=timeout
)
output: TransitionToolOutput = TransitionToolOutput.model_validate(response.json())

if debug_output_path:
Expand Down Expand Up @@ -496,6 +503,7 @@ def evaluate(
eips: Optional[List[int]] = None,
debug_output_path: str = "",
state_test: bool = False,
slow_request: bool = False,
) -> TransitionToolOutput:
"""
Executes the relevant evaluate method as required by the `t8n` tool.
Expand Down Expand Up @@ -524,7 +532,11 @@ def evaluate(
if self.t8n_use_server:
if not self.process:
self.start_server()
return self._evaluate_server(t8n_data=t8n_data, debug_output_path=debug_output_path)
return self._evaluate_server(
t8n_data=t8n_data,
debug_output_path=debug_output_path,
timeout=SLOW_REQUEST_TIMEOUT if slow_request else NORMAL_SERVER_TIMEOUT,
)

if self.t8n_use_stream:
return self._evaluate_stream(t8n_data=t8n_data, debug_output_path=debug_output_path)
Expand Down

0 comments on commit c50c5ad

Please sign in to comment.