From 94e932316c42f6da55a0fbd6a243781b30d16fa8 Mon Sep 17 00:00:00 2001 From: fselmo Date: Mon, 27 Feb 2023 16:17:03 -0700 Subject: [PATCH] Cleanup based on self PR review for #2093 --- eth/db/chain.py | 41 +++++----------------------------- eth/db/trie.py | 3 ++- eth/rlp/sedes.py | 1 - eth/vm/base.py | 3 ++- eth/vm/forks/london/blocks.py | 3 ++- eth/vm/state.py | 17 +++++++------- newsfragments/2093.feature.rst | 1 + 7 files changed, 21 insertions(+), 48 deletions(-) create mode 100644 newsfragments/2093.feature.rst diff --git a/eth/db/chain.py b/eth/db/chain.py index 98ffe8b280..71b6419619 100644 --- a/eth/db/chain.py +++ b/eth/db/chain.py @@ -10,7 +10,9 @@ cast, ) -from eth.vm.forks.shanghai.withdrawals import Withdrawal +from eth.vm.forks.shanghai.withdrawals import ( + Withdrawal, +) from eth_typing import ( BlockNumber, Hash32 @@ -33,7 +35,8 @@ ReceiptAPI, ReceiptDecoderAPI, SignedTransactionAPI, - TransactionDecoderAPI, WithdrawalAPI, + TransactionDecoderAPI, + WithdrawalAPI, ) from eth.constants import ( EMPTY_UNCLE_HASH, @@ -313,7 +316,7 @@ def _get_block_data_from_root_hash( """ Returns iterable of the encoded items from a root hash in a block. This can be useful for retrieving encoded transactions or withdrawals from the - transaction_root or withdrawals_root of a black. + transaction_root or withdrawals_root of a block. """ item_db = HexaryTrie(db, root_hash=block_root_hash) for item_idx in itertools.count(): @@ -473,24 +476,6 @@ def _add_transaction_to_canonical_chain(db: DatabaseAPI, # # Withdrawals API # - - def persist_withdrawals( - self, - withdrawals: Tuple[WithdrawalAPI]) -> Hash32: - return self._persist_withdrawals(self.db, withdrawals) - - @staticmethod - def _persist_withdrawals( - db: DatabaseAPI, - withdrawals: Tuple[WithdrawalAPI, ...]) -> Hash32: - - withdrawals_root = keccak(rlp.encode(withdrawals)) - db.set( - withdrawals_root, - rlp.encode(withdrawals, sedes=rlp.sedes.CountableList(Withdrawal)), - ) - return cast(Hash32, withdrawals_root) - def get_block_withdrawals( self, header: BlockHeaderAPI, @@ -512,20 +497,6 @@ def _get_block_withdrawals( ): yield rlp.decode(encoded_withdrawal, sedes=Withdrawal) - @classmethod - @to_tuple - def _get_block_withdrawal_hashes( - cls, - db: DatabaseAPI, - block_header: BlockHeaderAPI - ) -> Iterable[Hash32]: - all_encoded_withdrawals = cls._get_block_data_from_root_hash( - db, - block_header.withdrawals_root, - ) - for encoded_withdrawal in all_encoded_withdrawals: - yield cast(Hash32, keccak(encoded_withdrawal)) - @staticmethod def _add_withdrawal_to_canonical_chain( db: DatabaseAPI, diff --git a/eth/db/trie.py b/eth/db/trie.py index 81332796b1..f529a5b848 100644 --- a/eth/db/trie.py +++ b/eth/db/trie.py @@ -10,7 +10,8 @@ from eth.abc import ( ReceiptAPI, - SignedTransactionAPI, WithdrawalAPI, + SignedTransactionAPI, + WithdrawalAPI, ) from eth.constants import ( BLANK_ROOT_HASH, diff --git a/eth/rlp/sedes.py b/eth/rlp/sedes.py index 68aa37a9ec..333bfd039a 100644 --- a/eth/rlp/sedes.py +++ b/eth/rlp/sedes.py @@ -8,7 +8,6 @@ address = Binary.fixed_length(20, allow_empty=True) hash32 = Binary.fixed_length(32) uint32 = BigEndianInt(32) -uint64 = BigEndianInt(64) uint256 = BigEndianInt(256) trie_root = Binary.fixed_length(32, allow_empty=True) chain_gaps = rlp.sedes.List(( diff --git a/eth/vm/base.py b/eth/vm/base.py index 8e46c721cb..aba5c8f6d9 100644 --- a/eth/vm/base.py +++ b/eth/vm/base.py @@ -43,7 +43,8 @@ StateAPI, TransactionBuilderAPI, UnsignedTransactionAPI, - VirtualMachineAPI, WithdrawalAPI, + VirtualMachineAPI, + WithdrawalAPI, ) from eth.consensus.pow import ( PowConsensus, diff --git a/eth/vm/forks/london/blocks.py b/eth/vm/forks/london/blocks.py index 3de613697f..97832906f7 100644 --- a/eth/vm/forks/london/blocks.py +++ b/eth/vm/forks/london/blocks.py @@ -1,6 +1,7 @@ from typing import ( List, - Optional, Type, + Optional, + Type, cast, ) diff --git a/eth/vm/state.py b/eth/vm/state.py index 28a6f4f295..cf561ed0b2 100644 --- a/eth/vm/state.py +++ b/eth/vm/state.py @@ -1,7 +1,8 @@ import contextlib from typing import ( Iterator, - Sequence, Tuple, + Sequence, + Tuple, Type, ) @@ -19,14 +20,16 @@ from eth.abc import ( AccountDatabaseAPI, AtomicDatabaseAPI, - BlockHeaderAPI, ComputationAPI, + BlockHeaderAPI, + ComputationAPI, ExecutionContextAPI, MessageAPI, SignedTransactionAPI, StateAPI, TransactionContextAPI, TransactionExecutorAPI, - MetaWitnessAPI, WithdrawalAPI, + MetaWitnessAPI, + WithdrawalAPI, ) from eth.constants import ( MAX_PREV_HEADER_DEPTH, @@ -295,20 +298,16 @@ def get_transaction_context(self, # def apply_withdrawal(self, withdrawal: WithdrawalAPI) -> None: + # withdrawals not implemented until the Shanghai hard fork pass - # raise NotImplementedError( - # "Withdrawals not implemented until the Shanghai hard fork." - # ) def apply_all_withdrawals( self, withdrawals: Sequence[WithdrawalAPI], base_header: BlockHeaderAPI, ) -> None: + # withdrawals not implemented until the Shanghai hard fork pass - # raise NotImplementedError( - # "Withdrawals not implemented until the Shanghai hard fork." - # ) class BaseTransactionExecutor(TransactionExecutorAPI): diff --git a/newsfragments/2093.feature.rst b/newsfragments/2093.feature.rst new file mode 100644 index 0000000000..ac1d353835 --- /dev/null +++ b/newsfragments/2093.feature.rst @@ -0,0 +1 @@ +Add ``Shanghai`` hard fork support.