From a628eaa3b68aa8bb961c96e5c16ba943ff923854 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Mon, 22 Mar 2021 13:04:34 -0700 Subject: [PATCH 1/3] Add goerli and ropsten Berlin block numbers --- eth/chains/goerli/__init__.py | 3 +++ eth/chains/goerli/constants.py | 2 ++ eth/chains/ropsten/__init__.py | 5 ++++- eth/chains/ropsten/constants.py | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/eth/chains/goerli/__init__.py b/eth/chains/goerli/__init__.py index 76c2b95cd4..584e0d6258 100644 --- a/eth/chains/goerli/__init__.py +++ b/eth/chains/goerli/__init__.py @@ -1,6 +1,7 @@ from eth_utils import decode_hex from .constants import ( + BERLIN_GOERLI_BLOCK, ISTANBUL_GOERLI_BLOCK, PETERSBURG_GOERLI_BLOCK, ) @@ -9,6 +10,7 @@ from eth.rlp.headers import BlockHeader from eth.vm.forks import ( + BerlinVM, IstanbulVM, PetersburgVM, ) @@ -16,6 +18,7 @@ GOERLI_VM_CONFIGURATION = ( (PETERSBURG_GOERLI_BLOCK, PetersburgVM), (ISTANBUL_GOERLI_BLOCK, IstanbulVM), + (BERLIN_GOERLI_BLOCK, BerlinVM), ) diff --git a/eth/chains/goerli/constants.py b/eth/chains/goerli/constants.py index cd73543fa2..807096a9bb 100644 --- a/eth/chains/goerli/constants.py +++ b/eth/chains/goerli/constants.py @@ -14,3 +14,5 @@ # Istanbul # ISTANBUL_GOERLI_BLOCK = BlockNumber(1561651) + +BERLIN_GOERLI_BLOCK = BlockNumber(4460644) diff --git a/eth/chains/ropsten/__init__.py b/eth/chains/ropsten/__init__.py index 6f1d5b164a..87287b11b8 100644 --- a/eth/chains/ropsten/__init__.py +++ b/eth/chains/ropsten/__init__.py @@ -3,6 +3,7 @@ from eth_utils import decode_hex from .constants import ( + BERLIN_ROPSTEN_BLOCK, BYZANTIUM_ROPSTEN_BLOCK, CONSTANTINOPLE_ROPSTEN_BLOCK, ISTANBUL_ROPSTEN_BLOCK, @@ -18,6 +19,7 @@ from eth.chains.base import Chain from eth.rlp.headers import BlockHeader from eth.vm.forks import ( + BerlinVM, ByzantiumVM, ConstantinopleVM, IstanbulVM, @@ -36,7 +38,8 @@ (CONSTANTINOPLE_ROPSTEN_BLOCK, ConstantinopleVM), (PETERSBURG_ROPSTEN_BLOCK, PetersburgVM), (ISTANBUL_ROPSTEN_BLOCK, IstanbulVM), - (MUIR_GLACIER_ROPSTEN_BLOCK, MuirGlacierVM) + (MUIR_GLACIER_ROPSTEN_BLOCK, MuirGlacierVM), + (BERLIN_ROPSTEN_BLOCK, BerlinVM), ) diff --git a/eth/chains/ropsten/constants.py b/eth/chains/ropsten/constants.py index d21507726b..9fe0bbe456 100644 --- a/eth/chains/ropsten/constants.py +++ b/eth/chains/ropsten/constants.py @@ -57,3 +57,4 @@ # Muir Glacier Block # MUIR_GLACIER_ROPSTEN_BLOCK = BlockNumber(7117117) +BERLIN_ROPSTEN_BLOCK = BlockNumber(9812189) From 3e91d981e2dc0f3d279f7d38747bfd5c14b707fc Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Mon, 22 Mar 2021 14:51:14 -0700 Subject: [PATCH 2/3] Fix deserialize type signature for receipt and txn --- eth/abc.py | 12 ++++++++---- eth/vm/forks/berlin/receipts.py | 9 +++++---- eth/vm/forks/berlin/transactions.py | 9 +++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/eth/abc.py b/eth/abc.py index 446f4ef37e..74f9e564e2 100644 --- a/eth/abc.py +++ b/eth/abc.py @@ -11,6 +11,7 @@ FrozenSet, Iterable, Iterator, + List, MutableMapping, NamedTuple, Optional, @@ -51,6 +52,9 @@ T = TypeVar('T') +# A decoded RLP object of unknown interpretation, with a maximum "depth" of 1. +DecodedZeroOrOneLayerRLP = Union[bytes, List[bytes]] + class MiningHeaderAPI(ABC): """ @@ -241,7 +245,7 @@ class ReceiptBuilderAPI(ReceiptDecoderAPI): @classmethod @abstractmethod - def deserialize(cls, encoded: bytes) -> 'ReceiptAPI': + def deserialize(cls, encoded: DecodedZeroOrOneLayerRLP) -> 'ReceiptAPI': """ Extract a receipt from an encoded RLP object. @@ -251,7 +255,7 @@ def deserialize(cls, encoded: bytes) -> 'ReceiptAPI': @classmethod @abstractmethod - def serialize(cls, obj: 'ReceiptAPI') -> bytes: + def serialize(cls, obj: 'ReceiptAPI') -> DecodedZeroOrOneLayerRLP: """ Encode a receipt to a series of bytes used by RLP. @@ -448,7 +452,7 @@ class TransactionBuilderAPI(TransactionDecoderAPI): @classmethod @abstractmethod - def deserialize(cls, encoded: bytes) -> 'SignedTransactionAPI': + def deserialize(cls, encoded: DecodedZeroOrOneLayerRLP) -> 'SignedTransactionAPI': """ Extract a transaction from an encoded RLP object. @@ -458,7 +462,7 @@ def deserialize(cls, encoded: bytes) -> 'SignedTransactionAPI': @classmethod @abstractmethod - def serialize(cls, obj: 'SignedTransactionAPI') -> bytes: + def serialize(cls, obj: 'SignedTransactionAPI') -> DecodedZeroOrOneLayerRLP: """ Encode a transaction to a series of bytes used by RLP. diff --git a/eth/vm/forks/berlin/receipts.py b/eth/vm/forks/berlin/receipts.py index dc57df3533..fc6dbd51a0 100644 --- a/eth/vm/forks/berlin/receipts.py +++ b/eth/vm/forks/berlin/receipts.py @@ -17,6 +17,7 @@ ) from eth.abc import ( + DecodedZeroOrOneLayerRLP, LogAPI, ReceiptAPI, ReceiptBuilderAPI, @@ -76,13 +77,13 @@ def get_payload_codec(cls, type_id: int) -> Type[ReceiptDecoderAPI]: raise ValidationError(f"Cannot build typed receipt with {hex(type_id)} >= 0x80") @classmethod - def deserialize(cls, encoded_unchecked: bytes) -> ReceiptAPI: + def deserialize(cls, encoded_unchecked: DecodedZeroOrOneLayerRLP) -> ReceiptAPI: # binary checks a few basics, like the length of the bytes encoded = cls.rlp_type.deserialize(encoded_unchecked) return cls.decode(encoded) @classmethod - def serialize(cls, obj: 'TypedReceipt') -> bytes: + def serialize(cls, obj: 'TypedReceipt') -> DecodedZeroOrOneLayerRLP: encoded = obj.encode() return cls.rlp_type.serialize(encoded) @@ -136,12 +137,12 @@ def decode(cls, encoded: bytes) -> ReceiptAPI: return rlp.decode(encoded, sedes=cls.legacy_sedes) @classmethod - def deserialize(cls, encoded: bytes) -> ReceiptAPI: + def deserialize(cls, encoded: DecodedZeroOrOneLayerRLP) -> ReceiptAPI: if isinstance(encoded, bytes): return TypedReceipt.deserialize(encoded) else: return cls.legacy_sedes.deserialize(encoded) @classmethod - def serialize(cls, obj: ReceiptAPI) -> bytes: + def serialize(cls, obj: ReceiptAPI) -> DecodedZeroOrOneLayerRLP: return cls.legacy_sedes.serialize(obj) diff --git a/eth/vm/forks/berlin/transactions.py b/eth/vm/forks/berlin/transactions.py index 96a87b5c6a..d4d573a218 100644 --- a/eth/vm/forks/berlin/transactions.py +++ b/eth/vm/forks/berlin/transactions.py @@ -28,6 +28,7 @@ ) from eth.abc import ( + DecodedZeroOrOneLayerRLP, ReceiptAPI, SignedTransactionAPI, TransactionBuilderAPI, @@ -254,12 +255,12 @@ def decode(cls, encoded: bytes) -> SignedTransactionAPI: return cls(type_id, inner_transaction) @classmethod - def serialize(cls, obj: 'TypedTransaction') -> bytes: + def serialize(cls, obj: 'TypedTransaction') -> DecodedZeroOrOneLayerRLP: encoded = obj.encode() return cls.rlp_type.serialize(encoded) @classmethod - def deserialize(cls, encoded_unchecked: bytes) -> SignedTransactionAPI: + def deserialize(cls, encoded_unchecked: DecodedZeroOrOneLayerRLP) -> SignedTransactionAPI: # binary checks a few basics, like the length of the bytes encoded = cls.rlp_type.deserialize(encoded_unchecked) return cls.decode(encoded) @@ -374,14 +375,14 @@ def decode(cls, encoded: bytes) -> SignedTransactionAPI: return rlp.decode(encoded, sedes=cls.legacy_signed) @classmethod - def deserialize(cls, encoded: bytes) -> SignedTransactionAPI: + def deserialize(cls, encoded: DecodedZeroOrOneLayerRLP) -> SignedTransactionAPI: if isinstance(encoded, bytes): return TypedTransaction.deserialize(encoded) else: return cls.legacy_signed.deserialize(encoded) @classmethod - def serialize(cls, obj: SignedTransactionAPI) -> bytes: + def serialize(cls, obj: SignedTransactionAPI) -> DecodedZeroOrOneLayerRLP: if isinstance(obj, TypedTransaction): return TypedTransaction.serialize(obj) else: From 2f0c478e8344c473c7b96519da158630298c4e25 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Mon, 22 Mar 2021 15:00:19 -0700 Subject: [PATCH 3/3] Add release notes #1993 --- newsfragments/1993.bugfix.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 newsfragments/1993.bugfix.rst diff --git a/newsfragments/1993.bugfix.rst b/newsfragments/1993.bugfix.rst new file mode 100644 index 0000000000..b415512cc0 --- /dev/null +++ b/newsfragments/1993.bugfix.rst @@ -0,0 +1,3 @@ +Add Berlin block numbers for Goerli and Ropsten. Correct the type signature for +TransactionBuilderAPI and ReceiptBuilderAPI, because it can take a list of bytes for the legacy +types.