Skip to content

Commit

Permalink
Minor tweaks to recent VMs for clarity
Browse files Browse the repository at this point in the history
- Use the block header class for the appropriate VM by validating up to the previous VM, extracting the params, and plugging into the appropriate VM class.
- Remove unnecessary fields in London state since they are already inheritted and do not need to be re-imported / overwritten
  • Loading branch information
fselmo committed Sep 14, 2022
1 parent 2f036eb commit 0350ced
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 35 deletions.
34 changes: 26 additions & 8 deletions eth/vm/forks/arrow_glacier/headers.py
Original file line number Diff line number Diff line change
@@ -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) # type: ignore
38 changes: 29 additions & 9 deletions eth/vm/forks/gray_glacier/headers.py
Original file line number Diff line number Diff line change
@@ -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) # type: ignore
4 changes: 3 additions & 1 deletion eth/vm/forks/london/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 5 additions & 9 deletions eth/vm/forks/london/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)


Expand Down
5 changes: 0 additions & 5 deletions eth/vm/forks/london/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
)

from eth.abc import (
AccountDatabaseAPI,
ComputationAPI,
MessageAPI,
SignedTransactionAPI,
Expand All @@ -17,9 +16,6 @@
from eth.constants import (
CREATE_CONTRACT_ADDRESS,
)
from eth.db.account import (
AccountDB
)
from eth.vm.message import (
Message,
)
Expand Down Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions tests/json-fixtures/blockchain/test_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,6 @@ def blockchain_fixture_mark_fn(fixture_path, fixture_name, fixture_fork):
"Skipped failing tests in v11.1 update to get Merge-related changes in. "
"Turn these back on and fix after the Merge is implemented."
)
elif "Merge" in fixture_name:
# TODO: Implement changes for the Merge and turn these tests on
return pytest.mark.skip("The Merge has not yet been implemented.")
elif fixture_id in SLOWEST_TESTS:
if should_run_slow_tests():
return
Expand Down

0 comments on commit 0350ced

Please sign in to comment.