Skip to content

Commit 5440994

Browse files
authored
Merge pull request #183 from marioevz/execution-payload-in-fixtures
feature: Add engine API execution payload information in fixtures
2 parents 09716f0 + 266c350 commit 5440994

File tree

10 files changed

+273
-3
lines changed

10 files changed

+273
-3
lines changed

src/ethereum_test_forks/base_fork.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Abstract base class for Ethereum forks
33
"""
44
from abc import ABC, ABCMeta, abstractmethod
5-
from typing import Type
5+
from typing import Optional, Type
66

77

88
class BaseForkMeta(ABCMeta):
@@ -30,6 +30,7 @@ class BaseFork(ABC, metaclass=BaseForkMeta):
3030
Must contain all the methods used by every fork.
3131
"""
3232

33+
# Header information abstract methods
3334
@classmethod
3435
@abstractmethod
3536
def header_base_fee_required(cls, block_number: int, timestamp: int) -> bool:
@@ -86,6 +87,25 @@ def get_reward(cls, block_number: int, timestamp: int) -> int:
8687
"""
8788
pass
8889

90+
# Engine API information abstract methods
91+
@classmethod
92+
@abstractmethod
93+
def engine_new_payload_version(cls, block_number: int, timestamp: int) -> Optional[int]:
94+
"""
95+
Returns `None` if this fork's payloads cannot be sent over the engine API,
96+
or the payload version if it can.
97+
"""
98+
pass
99+
100+
@classmethod
101+
@abstractmethod
102+
def engine_new_payload_blob_hashes(cls, block_number: int, timestamp: int) -> bool:
103+
"""
104+
Returns true if the engine api version requires new payload calls to include blob hashes.
105+
"""
106+
pass
107+
108+
# Meta information about the fork
89109
@classmethod
90110
def name(cls) -> str:
91111
"""

src/ethereum_test_forks/forks/forks.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
All Ethereum fork class definitions.
33
"""
4+
from typing import Optional
5+
46
from ..base_fork import BaseFork
57

68

@@ -52,6 +54,20 @@ def header_data_gas_used_required(cls, block_number: int, timestamp: int) -> boo
5254
"""
5355
return False
5456

57+
@classmethod
58+
def engine_new_payload_version(cls, block_number: int, timestamp: int) -> Optional[int]:
59+
"""
60+
At genesis, payloads cannot be sent through the engine API
61+
"""
62+
return None
63+
64+
@classmethod
65+
def engine_new_payload_blob_hashes(cls, block_number: int, timestamp: int) -> bool:
66+
"""
67+
At genesis, payloads do not have blob hashes.
68+
"""
69+
return False
70+
5571
@classmethod
5672
def get_reward(cls, block_number: int, timestamp: int) -> int:
5773
"""
@@ -186,6 +202,13 @@ def get_reward(cls, block_number: int, timestamp: int) -> int:
186202
"""
187203
return 0
188204

205+
@classmethod
206+
def engine_new_payload_version(cls, block_number: int, timestamp: int) -> Optional[int]:
207+
"""
208+
Starting at the merge, payloads can be sent through the engine API
209+
"""
210+
return 1
211+
189212

190213
class Shanghai(Merge):
191214
"""
@@ -199,6 +222,13 @@ def header_withdrawals_required(cls, block_number: int, timestamp: int) -> bool:
199222
"""
200223
return True
201224

225+
@classmethod
226+
def engine_new_payload_version(cls, block_number: int, timestamp: int) -> Optional[int]:
227+
"""
228+
Starting at Shanghai, new payload calls must use version 2
229+
"""
230+
return 2
231+
202232

203233
class Cancun(Shanghai):
204234
"""
@@ -226,3 +256,17 @@ def header_data_gas_used_required(cls, block_number: int, timestamp: int) -> boo
226256
Data gas used is required starting from Cancun.
227257
"""
228258
return True
259+
260+
@classmethod
261+
def engine_new_payload_version(cls, block_number: int, timestamp: int) -> Optional[int]:
262+
"""
263+
Starting at Cancun, new payload calls must use version 3
264+
"""
265+
return 3
266+
267+
@classmethod
268+
def engine_new_payload_blob_hashes(cls, block_number: int, timestamp: int) -> bool:
269+
"""
270+
Starting at Cancun, payloads must have blob hashes.
271+
"""
272+
return True

src/ethereum_test_forks/forks/transition.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
List of all transition fork definitions.
33
"""
4+
from typing import Optional
5+
46
from ..transition_base_fork import transition_fork
57
from .forks import Berlin, Cancun, London, Merge, Shanghai
68

@@ -33,6 +35,13 @@ def header_withdrawals_required(cls, _: int, timestamp: int) -> bool:
3335
"""
3436
return timestamp >= 15_000
3537

38+
@classmethod
39+
def engine_new_payload_version(cls, block_number: int, timestamp: int) -> Optional[int]:
40+
"""
41+
Starting at Shanghai, new payload calls must use version 2
42+
"""
43+
return 2 if timestamp >= 15_000 else 1
44+
3645

3746
@transition_fork(to_fork=Cancun)
3847
class ShanghaiToCancunAtTime15k(Shanghai):
@@ -46,3 +55,17 @@ def header_excess_data_gas_required(cls, _: int, timestamp: int) -> bool:
4655
Excess data gas is required if transitioning to Cancun.
4756
"""
4857
return timestamp >= 15_000
58+
59+
@classmethod
60+
def engine_new_payload_version(cls, block_number: int, timestamp: int) -> Optional[int]:
61+
"""
62+
Starting at Cancun, new payload calls must use version 3
63+
"""
64+
return 3 if timestamp >= 15_000 else 2
65+
66+
@classmethod
67+
def engine_new_payload_blob_hashes(cls, block_number: int, timestamp: int) -> bool:
68+
"""
69+
Starting at Cancun, payloads must have blob hashes.
70+
"""
71+
return timestamp >= 15_000

src/ethereum_test_tools/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
Account,
1010
Auto,
1111
Block,
12+
EngineAPIError,
1213
Environment,
1314
Fixture,
15+
FixtureEngineNewPayload,
1416
Header,
1517
JSONEncoder,
1618
Storage,
@@ -46,8 +48,10 @@
4648
"BlockchainTestFiller",
4749
"Code",
4850
"CodeGasMeasure",
51+
"EngineAPIError",
4952
"Environment",
5053
"Fixture",
54+
"FixtureEngineNewPayload",
5155
"Header",
5256
"Initcode",
5357
"JSONEncoder",

src/ethereum_test_tools/common/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
AddrAA,
66
AddrBB,
77
EmptyTrieRoot,
8+
EngineAPIError,
89
TestAddress,
910
TestAddress2,
1011
TestPrivateKey,
@@ -30,6 +31,7 @@
3031
Environment,
3132
Fixture,
3233
FixtureBlock,
34+
FixtureEngineNewPayload,
3335
FixtureHeader,
3436
Header,
3537
JSONEncoder,
@@ -51,10 +53,12 @@
5153
"AddrBB",
5254
"Auto",
5355
"Block",
56+
"EngineAPIError",
5457
"EmptyTrieRoot",
5558
"Environment",
5659
"Fixture",
5760
"FixtureBlock",
61+
"FixtureEngineNewPayload",
5862
"FixtureHeader",
5963
"Header",
6064
"JSONEncoder",

src/ethereum_test_tools/common/constants.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Common values used in Ethereum tests.
33
"""
44

5+
from enum import IntEnum
6+
57
TestAddress = "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"
68
TestAddress2 = "0x8a0A19589531694250d570040a0c4B74576919B8"
79

@@ -17,3 +19,21 @@
1719
EmptyHash = bytes([0] * 32)
1820
EmptyNonce = bytes([0] * 8)
1921
ZeroAddress = bytes([0] * 20)
22+
23+
24+
class EngineAPIError(IntEnum):
25+
"""
26+
List of Engine API errors
27+
"""
28+
29+
ParseError = -32700
30+
InvalidRequest = -32600
31+
MethodNotFound = -32601
32+
InvalidParams = -32602
33+
InternalError = -32603
34+
ServerError = -32000
35+
UnknownPayload = -38001
36+
InvalidForkchoiceState = -38002
37+
InvalidPayloadAttributes = -38003
38+
TooLargeRequest = -38004
39+
UnsupportedFork = -38005

0 commit comments

Comments
 (0)