Skip to content

Commit

Permalink
Cleanup based on self PR review for #2093
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed Apr 6, 2023
1 parent f23c2cb commit ea07ae6
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 48 deletions.
41 changes: 6 additions & 35 deletions eth/db/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,7 +35,8 @@
ReceiptAPI,
ReceiptDecoderAPI,
SignedTransactionAPI,
TransactionDecoderAPI, WithdrawalAPI,
TransactionDecoderAPI,
WithdrawalAPI,
)
from eth.constants import (
EMPTY_UNCLE_HASH,
Expand Down Expand Up @@ -317,7 +320,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():
Expand Down Expand Up @@ -477,24 +480,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,
Expand All @@ -516,20 +501,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,
Expand Down
3 changes: 2 additions & 1 deletion eth/db/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

from eth.abc import (
ReceiptAPI,
SignedTransactionAPI, WithdrawalAPI,
SignedTransactionAPI,
WithdrawalAPI,
)
from eth.constants import (
BLANK_ROOT_HASH,
Expand Down
1 change: 0 additions & 1 deletion eth/rlp/sedes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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((
Expand Down
3 changes: 2 additions & 1 deletion eth/vm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
StateAPI,
TransactionBuilderAPI,
UnsignedTransactionAPI,
VirtualMachineAPI, WithdrawalAPI,
VirtualMachineAPI,
WithdrawalAPI,
)
from eth.consensus.pow import (
PowConsensus,
Expand Down
3 changes: 2 additions & 1 deletion eth/vm/forks/london/blocks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import (
List,
Optional, Type,
Optional,
Type,
cast,
)

Expand Down
17 changes: 8 additions & 9 deletions eth/vm/state.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import contextlib
from typing import (
Iterator,
Sequence, Tuple,
Sequence,
Tuple,
Type,
)

Expand All @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2093.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``Shanghai`` hard fork support.

0 comments on commit ea07ae6

Please sign in to comment.