|
| 1 | +""" |
| 2 | +EELS T8N transition tool. |
| 3 | +
|
| 4 | +https://github.com/ethereum/execution-specs |
| 5 | +""" |
| 6 | + |
| 7 | +from abc import ABC, abstractmethod |
| 8 | +from typing import List |
| 9 | + |
| 10 | +from ethereum_clis import TransitionTool, TransitionToolOutput |
| 11 | +from ethereum_test_base_types import BlobSchedule |
| 12 | +from ethereum_test_forks import Fork |
| 13 | +from ethereum_test_types import Alloc, Environment, Transaction |
| 14 | + |
| 15 | + |
| 16 | +class EELST8NWrapper(TransitionTool, ABC): |
| 17 | + """ |
| 18 | + Abstract base class for EELS T8N wrapper implementations. |
| 19 | +
|
| 20 | + This class provides an interface for calling the EELS T8N entrypoint directly |
| 21 | + without going through a binary. It implements a registration mechanism for |
| 22 | + concrete implementations to be set as the default wrapper. |
| 23 | +
|
| 24 | + Attributes: |
| 25 | + _default (class): The registered default subclass to use for instantiation. |
| 26 | + Should be set via `set_default()`. |
| 27 | +
|
| 28 | + Usage: |
| 29 | + 1. Create a concrete subclass implementing all abstract methods |
| 30 | + 2. Register it using `EELST8NWrapper.set_default(YourSubclass)` |
| 31 | + 3. Instantiate via `EELST8NWrapper.default()` |
| 32 | +
|
| 33 | + """ |
| 34 | + |
| 35 | + _default = None |
| 36 | + |
| 37 | + @classmethod |
| 38 | + def set_default(cls, default_cls): |
| 39 | + """ |
| 40 | + Register a default subclass for instantiation. |
| 41 | +
|
| 42 | + Args: |
| 43 | + default_cls: The subclass to register as default |
| 44 | +
|
| 45 | + Raises: |
| 46 | + TypeError: If `default_cls` is not a subclass of EELST8NWrapper |
| 47 | +
|
| 48 | + """ |
| 49 | + if not issubclass(default_cls, cls): |
| 50 | + raise TypeError(f"{default_cls.__name__} is not a subclass of {cls.__name__}") |
| 51 | + cls._default = default_cls |
| 52 | + |
| 53 | + @classmethod |
| 54 | + def default(cls, *args, **kwargs): |
| 55 | + """ |
| 56 | + Instantiate the registered default implementation. |
| 57 | +
|
| 58 | + Returns: |
| 59 | + Instance of the registered default subclass |
| 60 | +
|
| 61 | + Raises: |
| 62 | + RuntimeError: If no default implementation has been registered |
| 63 | +
|
| 64 | + """ |
| 65 | + if cls._default is None: |
| 66 | + raise RuntimeError("Default subclass not set!") |
| 67 | + return cls._default(*args, **kwargs) |
| 68 | + |
| 69 | + @abstractmethod |
| 70 | + def version(self): |
| 71 | + """Return the version string of the transition tool implementation.""" |
| 72 | + pass |
| 73 | + |
| 74 | + @abstractmethod |
| 75 | + def is_fork_supported(self, fork) -> bool: |
| 76 | + """Check if a specific fork is supported by the tool.""" |
| 77 | + pass |
| 78 | + |
| 79 | + @abstractmethod |
| 80 | + def _evaluate_eels_t8n( |
| 81 | + self, |
| 82 | + *, |
| 83 | + t8n_data: TransitionTool.TransitionToolData, |
| 84 | + debug_output_path: str = "", |
| 85 | + ) -> TransitionToolOutput: |
| 86 | + """ |
| 87 | + Execute the transition tool implementation (core functionality). |
| 88 | +
|
| 89 | + This must be implemented by concrete subclasses to provide the actual |
| 90 | + transition tool evaluation logic. |
| 91 | +
|
| 92 | + Args: |
| 93 | + t8n_data: Input data for the state transition |
| 94 | + debug_output_path: Optional path for writing debug output |
| 95 | +
|
| 96 | + Returns: |
| 97 | + TransitionToolOutput: Result of the state transition |
| 98 | +
|
| 99 | + """ |
| 100 | + pass |
| 101 | + |
| 102 | + def evaluate( |
| 103 | + self, |
| 104 | + *, |
| 105 | + alloc: Alloc, |
| 106 | + txs: List[Transaction], |
| 107 | + env: Environment, |
| 108 | + fork: Fork, |
| 109 | + chain_id: int, |
| 110 | + reward: int, |
| 111 | + blob_schedule: BlobSchedule | None, |
| 112 | + debug_output_path: str = "", |
| 113 | + state_test: bool = False, |
| 114 | + slow_request: bool = False, |
| 115 | + ) -> TransitionToolOutput: |
| 116 | + """ |
| 117 | + Execute the relevant evaluate method as required by the `t8n` tool. |
| 118 | +
|
| 119 | + If a client's `t8n` tool varies from the default behavior, this method |
| 120 | + can be overridden. |
| 121 | + """ |
| 122 | + fork_name = fork.transition_tool_name( |
| 123 | + block_number=env.number, |
| 124 | + timestamp=env.timestamp, |
| 125 | + ) |
| 126 | + if env.number == 0: |
| 127 | + reward = -1 |
| 128 | + t8n_data = self.TransitionToolData( |
| 129 | + alloc=alloc, |
| 130 | + txs=txs, |
| 131 | + env=env, |
| 132 | + fork_name=fork_name, |
| 133 | + chain_id=chain_id, |
| 134 | + reward=reward, |
| 135 | + blob_schedule=blob_schedule, |
| 136 | + state_test=state_test, |
| 137 | + ) |
| 138 | + |
| 139 | + return self._evaluate_eels_t8n(t8n_data=t8n_data, debug_output_path=debug_output_path) |
0 commit comments