diff --git a/eth/vm/forks/arrow_glacier/__init__.py b/eth/vm/forks/arrow_glacier/__init__.py index 1f81db0833..18403f26d9 100644 --- a/eth/vm/forks/arrow_glacier/__init__.py +++ b/eth/vm/forks/arrow_glacier/__init__.py @@ -25,7 +25,7 @@ class ArrowGlacierVM(LondonVM): # Methods create_header_from_parent = staticmethod( # type: ignore - create_arrow_glacier_header_from_parent + create_arrow_glacier_header_from_parent(compute_arrow_glacier_difficulty) ) compute_difficulty = staticmethod(compute_arrow_glacier_difficulty) # type: ignore configure_header = configure_arrow_glacier_header diff --git a/eth/vm/forks/arrow_glacier/headers.py b/eth/vm/forks/arrow_glacier/headers.py index a23e503c49..1f0c43e8fb 100644 --- a/eth/vm/forks/arrow_glacier/headers.py +++ b/eth/vm/forks/arrow_glacier/headers.py @@ -1,18 +1,36 @@ +from typing import Any, Callable, Optional + +from toolz import curry + +from eth.abc import BlockHeaderAPI +from .blocks import ( + ArrowGlacierBlockHeader, +) from eth.vm.forks.london.headers import ( - create_header_from_parent, + create_london_header_from_parent, ) -from eth.vm.forks.petersburg.headers import ( +from eth.vm.forks.byzantium.headers import ( compute_difficulty, ) -from eth.vm.forks.istanbul.headers import ( +from eth.vm.forks.byzantium.headers import ( configure_header, ) - compute_arrow_glacier_difficulty = compute_difficulty(10_700_000) +configure_arrow_glacier_header = configure_header(compute_arrow_glacier_difficulty) -create_arrow_glacier_header_from_parent = create_header_from_parent( - compute_arrow_glacier_difficulty -) -configure_arrow_glacier_header = configure_header(compute_arrow_glacier_difficulty) +@curry +def create_arrow_glacier_header_from_parent( + difficulty_fn: Callable[[BlockHeaderAPI, int], int], + parent_header: Optional[BlockHeaderAPI], + **header_params: Any +) -> BlockHeaderAPI: + london_validated_header = create_london_header_from_parent( + difficulty_fn, parent_header, **header_params + ) + + # extract header params validated up to london (previous VM) and plug + # into `ArrowGlacierBlockHeader` class + all_fields = london_validated_header.as_dict() + return ArrowGlacierBlockHeader(**all_fields) diff --git a/eth/vm/forks/gray_glacier/__init__.py b/eth/vm/forks/gray_glacier/__init__.py index 9f68e33aff..66beb96d17 100644 --- a/eth/vm/forks/gray_glacier/__init__.py +++ b/eth/vm/forks/gray_glacier/__init__.py @@ -25,7 +25,7 @@ class GrayGlacierVM(ArrowGlacierVM): # Methods create_header_from_parent = staticmethod( # type: ignore - create_gray_glacier_header_from_parent + create_gray_glacier_header_from_parent(compute_gray_glacier_difficulty) ) compute_difficulty = staticmethod(compute_gray_glacier_difficulty) # type: ignore configure_header = configure_gray_glacier_header diff --git a/eth/vm/forks/gray_glacier/headers.py b/eth/vm/forks/gray_glacier/headers.py index d8fbe21c8d..e9501ddd71 100644 --- a/eth/vm/forks/gray_glacier/headers.py +++ b/eth/vm/forks/gray_glacier/headers.py @@ -1,18 +1,38 @@ -from eth.vm.forks.london.headers import ( - create_header_from_parent, +from typing import Any, Callable, Optional + +from toolz import curry + +from .blocks import ( + GrayGlacierBlockHeader, +) +from eth.abc import ( + BlockHeaderAPI, ) -from eth.vm.forks.petersburg.headers import ( +from eth.vm.forks.arrow_glacier.headers import ( + create_arrow_glacier_header_from_parent, +) +from eth.vm.forks.byzantium.headers import ( compute_difficulty, ) -from eth.vm.forks.istanbul.headers import ( +from eth.vm.forks.byzantium.headers import ( configure_header, ) - compute_gray_glacier_difficulty = compute_difficulty(11_400_000) +configure_gray_glacier_header = configure_header(compute_gray_glacier_difficulty) -create_gray_glacier_header_from_parent = create_header_from_parent( - compute_gray_glacier_difficulty -) -configure_gray_glacier_header = configure_header(compute_gray_glacier_difficulty) +@curry +def create_gray_glacier_header_from_parent( + difficulty_fn: Callable[[BlockHeaderAPI, int], int], + parent_header: Optional[BlockHeaderAPI], + **header_params: Any +) -> BlockHeaderAPI: + arrow_glacier_validated_header = create_arrow_glacier_header_from_parent( + difficulty_fn, parent_header, **header_params + ) + + # extract header params validated up to arrow glacier (previous VM) and plug + # into `GrayGlacierBlockHeader` class + all_fields = arrow_glacier_validated_header.as_dict() + return GrayGlacierBlockHeader(**all_fields) diff --git a/eth/vm/forks/london/__init__.py b/eth/vm/forks/london/__init__.py index e68de6b355..72fc938e6d 100644 --- a/eth/vm/forks/london/__init__.py +++ b/eth/vm/forks/london/__init__.py @@ -33,7 +33,9 @@ class LondonVM(BerlinVM): _state_class: Type[BaseState] = LondonState # Methods - create_header_from_parent = staticmethod(create_london_header_from_parent) # type: ignore + create_header_from_parent = staticmethod( # type: ignore + create_london_header_from_parent(compute_london_difficulty) + ) compute_difficulty = staticmethod(compute_london_difficulty) # type: ignore configure_header = configure_london_header diff --git a/eth/vm/forks/london/headers.py b/eth/vm/forks/london/headers.py index ba2eb4d144..8a2a77c049 100644 --- a/eth/vm/forks/london/headers.py +++ b/eth/vm/forks/london/headers.py @@ -76,10 +76,11 @@ def calculate_expected_base_fee_per_gas(parent_header: BlockHeaderAPI) -> int: @curry -def create_header_from_parent(difficulty_fn: Callable[[BlockHeaderAPI, int], int], - parent_header: Optional[BlockHeaderAPI], - **header_params: Any) -> BlockHeaderAPI: - +def create_london_header_from_parent( + difficulty_fn: Callable[[BlockHeaderAPI, int], int], + parent_header: Optional[BlockHeaderAPI], + **header_params: Any +) -> BlockHeaderAPI: if 'gas_limit' not in header_params: if parent_header is not None and not hasattr(parent_header, 'base_fee_per_gas'): # If the previous block was not a London block, @@ -133,11 +134,6 @@ def create_header_from_parent(difficulty_fn: Callable[[BlockHeaderAPI, int], int compute_london_difficulty = compute_difficulty(9700000) - -create_london_header_from_parent = create_header_from_parent( - compute_london_difficulty -) - configure_london_header = configure_header(compute_london_difficulty) diff --git a/eth/vm/forks/london/state.py b/eth/vm/forks/london/state.py index 60489d6a1a..51c58be21f 100644 --- a/eth/vm/forks/london/state.py +++ b/eth/vm/forks/london/state.py @@ -6,7 +6,6 @@ ) from eth.abc import ( - AccountDatabaseAPI, ComputationAPI, MessageAPI, SignedTransactionAPI, @@ -17,9 +16,6 @@ from eth.constants import ( CREATE_CONTRACT_ADDRESS, ) -from eth.db.account import ( - AccountDB -) from eth.vm.message import ( Message, ) @@ -100,7 +96,6 @@ def calculate_gas_refund(cls, class LondonState(BerlinState): - account_db_class: Type[AccountDatabaseAPI] = AccountDB computation_class = LondonComputation transaction_executor_class: Type[TransactionExecutorAPI] = LondonTransactionExecutor