Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 1fb6f5a

Browse files
authored
Merge pull request #1993 from carver/berlin-fixups
Berlin fixups: Goerli & Ropsten blocks; type fixup
2 parents 406a743 + 2f0c478 commit 1fb6f5a

File tree

8 files changed

+31
-13
lines changed

8 files changed

+31
-13
lines changed

eth/abc.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
FrozenSet,
1212
Iterable,
1313
Iterator,
14+
List,
1415
MutableMapping,
1516
NamedTuple,
1617
Optional,
@@ -51,6 +52,9 @@
5152

5253
T = TypeVar('T')
5354

55+
# A decoded RLP object of unknown interpretation, with a maximum "depth" of 1.
56+
DecodedZeroOrOneLayerRLP = Union[bytes, List[bytes]]
57+
5458

5559
class MiningHeaderAPI(ABC):
5660
"""
@@ -241,7 +245,7 @@ class ReceiptBuilderAPI(ReceiptDecoderAPI):
241245

242246
@classmethod
243247
@abstractmethod
244-
def deserialize(cls, encoded: bytes) -> 'ReceiptAPI':
248+
def deserialize(cls, encoded: DecodedZeroOrOneLayerRLP) -> 'ReceiptAPI':
245249
"""
246250
Extract a receipt from an encoded RLP object.
247251
@@ -251,7 +255,7 @@ def deserialize(cls, encoded: bytes) -> 'ReceiptAPI':
251255

252256
@classmethod
253257
@abstractmethod
254-
def serialize(cls, obj: 'ReceiptAPI') -> bytes:
258+
def serialize(cls, obj: 'ReceiptAPI') -> DecodedZeroOrOneLayerRLP:
255259
"""
256260
Encode a receipt to a series of bytes used by RLP.
257261
@@ -448,7 +452,7 @@ class TransactionBuilderAPI(TransactionDecoderAPI):
448452

449453
@classmethod
450454
@abstractmethod
451-
def deserialize(cls, encoded: bytes) -> 'SignedTransactionAPI':
455+
def deserialize(cls, encoded: DecodedZeroOrOneLayerRLP) -> 'SignedTransactionAPI':
452456
"""
453457
Extract a transaction from an encoded RLP object.
454458
@@ -458,7 +462,7 @@ def deserialize(cls, encoded: bytes) -> 'SignedTransactionAPI':
458462

459463
@classmethod
460464
@abstractmethod
461-
def serialize(cls, obj: 'SignedTransactionAPI') -> bytes:
465+
def serialize(cls, obj: 'SignedTransactionAPI') -> DecodedZeroOrOneLayerRLP:
462466
"""
463467
Encode a transaction to a series of bytes used by RLP.
464468

eth/chains/goerli/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from eth_utils import decode_hex
22

33
from .constants import (
4+
BERLIN_GOERLI_BLOCK,
45
ISTANBUL_GOERLI_BLOCK,
56
PETERSBURG_GOERLI_BLOCK,
67
)
@@ -9,13 +10,15 @@
910

1011
from eth.rlp.headers import BlockHeader
1112
from eth.vm.forks import (
13+
BerlinVM,
1214
IstanbulVM,
1315
PetersburgVM,
1416
)
1517

1618
GOERLI_VM_CONFIGURATION = (
1719
(PETERSBURG_GOERLI_BLOCK, PetersburgVM),
1820
(ISTANBUL_GOERLI_BLOCK, IstanbulVM),
21+
(BERLIN_GOERLI_BLOCK, BerlinVM),
1922
)
2023

2124

eth/chains/goerli/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@
1414
# Istanbul
1515
#
1616
ISTANBUL_GOERLI_BLOCK = BlockNumber(1561651)
17+
18+
BERLIN_GOERLI_BLOCK = BlockNumber(4460644)

eth/chains/ropsten/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from eth_utils import decode_hex
44

55
from .constants import (
6+
BERLIN_ROPSTEN_BLOCK,
67
BYZANTIUM_ROPSTEN_BLOCK,
78
CONSTANTINOPLE_ROPSTEN_BLOCK,
89
ISTANBUL_ROPSTEN_BLOCK,
@@ -18,6 +19,7 @@
1819
from eth.chains.base import Chain
1920
from eth.rlp.headers import BlockHeader
2021
from eth.vm.forks import (
22+
BerlinVM,
2123
ByzantiumVM,
2224
ConstantinopleVM,
2325
IstanbulVM,
@@ -36,7 +38,8 @@
3638
(CONSTANTINOPLE_ROPSTEN_BLOCK, ConstantinopleVM),
3739
(PETERSBURG_ROPSTEN_BLOCK, PetersburgVM),
3840
(ISTANBUL_ROPSTEN_BLOCK, IstanbulVM),
39-
(MUIR_GLACIER_ROPSTEN_BLOCK, MuirGlacierVM)
41+
(MUIR_GLACIER_ROPSTEN_BLOCK, MuirGlacierVM),
42+
(BERLIN_ROPSTEN_BLOCK, BerlinVM),
4043
)
4144

4245

eth/chains/ropsten/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@
5757
# Muir Glacier Block
5858
#
5959
MUIR_GLACIER_ROPSTEN_BLOCK = BlockNumber(7117117)
60+
BERLIN_ROPSTEN_BLOCK = BlockNumber(9812189)

eth/vm/forks/berlin/receipts.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
)
1818

1919
from eth.abc import (
20+
DecodedZeroOrOneLayerRLP,
2021
LogAPI,
2122
ReceiptAPI,
2223
ReceiptBuilderAPI,
@@ -76,13 +77,13 @@ def get_payload_codec(cls, type_id: int) -> Type[ReceiptDecoderAPI]:
7677
raise ValidationError(f"Cannot build typed receipt with {hex(type_id)} >= 0x80")
7778

7879
@classmethod
79-
def deserialize(cls, encoded_unchecked: bytes) -> ReceiptAPI:
80+
def deserialize(cls, encoded_unchecked: DecodedZeroOrOneLayerRLP) -> ReceiptAPI:
8081
# binary checks a few basics, like the length of the bytes
8182
encoded = cls.rlp_type.deserialize(encoded_unchecked)
8283
return cls.decode(encoded)
8384

8485
@classmethod
85-
def serialize(cls, obj: 'TypedReceipt') -> bytes:
86+
def serialize(cls, obj: 'TypedReceipt') -> DecodedZeroOrOneLayerRLP:
8687
encoded = obj.encode()
8788
return cls.rlp_type.serialize(encoded)
8889

@@ -136,12 +137,12 @@ def decode(cls, encoded: bytes) -> ReceiptAPI:
136137
return rlp.decode(encoded, sedes=cls.legacy_sedes)
137138

138139
@classmethod
139-
def deserialize(cls, encoded: bytes) -> ReceiptAPI:
140+
def deserialize(cls, encoded: DecodedZeroOrOneLayerRLP) -> ReceiptAPI:
140141
if isinstance(encoded, bytes):
141142
return TypedReceipt.deserialize(encoded)
142143
else:
143144
return cls.legacy_sedes.deserialize(encoded)
144145

145146
@classmethod
146-
def serialize(cls, obj: ReceiptAPI) -> bytes:
147+
def serialize(cls, obj: ReceiptAPI) -> DecodedZeroOrOneLayerRLP:
147148
return cls.legacy_sedes.serialize(obj)

eth/vm/forks/berlin/transactions.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
)
2929

3030
from eth.abc import (
31+
DecodedZeroOrOneLayerRLP,
3132
ReceiptAPI,
3233
SignedTransactionAPI,
3334
TransactionBuilderAPI,
@@ -254,12 +255,12 @@ def decode(cls, encoded: bytes) -> SignedTransactionAPI:
254255
return cls(type_id, inner_transaction)
255256

256257
@classmethod
257-
def serialize(cls, obj: 'TypedTransaction') -> bytes:
258+
def serialize(cls, obj: 'TypedTransaction') -> DecodedZeroOrOneLayerRLP:
258259
encoded = obj.encode()
259260
return cls.rlp_type.serialize(encoded)
260261

261262
@classmethod
262-
def deserialize(cls, encoded_unchecked: bytes) -> SignedTransactionAPI:
263+
def deserialize(cls, encoded_unchecked: DecodedZeroOrOneLayerRLP) -> SignedTransactionAPI:
263264
# binary checks a few basics, like the length of the bytes
264265
encoded = cls.rlp_type.deserialize(encoded_unchecked)
265266
return cls.decode(encoded)
@@ -374,14 +375,14 @@ def decode(cls, encoded: bytes) -> SignedTransactionAPI:
374375
return rlp.decode(encoded, sedes=cls.legacy_signed)
375376

376377
@classmethod
377-
def deserialize(cls, encoded: bytes) -> SignedTransactionAPI:
378+
def deserialize(cls, encoded: DecodedZeroOrOneLayerRLP) -> SignedTransactionAPI:
378379
if isinstance(encoded, bytes):
379380
return TypedTransaction.deserialize(encoded)
380381
else:
381382
return cls.legacy_signed.deserialize(encoded)
382383

383384
@classmethod
384-
def serialize(cls, obj: SignedTransactionAPI) -> bytes:
385+
def serialize(cls, obj: SignedTransactionAPI) -> DecodedZeroOrOneLayerRLP:
385386
if isinstance(obj, TypedTransaction):
386387
return TypedTransaction.serialize(obj)
387388
else:

newsfragments/1993.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add Berlin block numbers for Goerli and Ropsten. Correct the type signature for
2+
TransactionBuilderAPI and ReceiptBuilderAPI, because it can take a list of bytes for the legacy
3+
types.

0 commit comments

Comments
 (0)