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 Nov 8, 2022
1 parent f83866d commit 7611d4e
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 34 deletions.
2 changes: 1 addition & 1 deletion eth/vm/forks/arrow_glacier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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)
2 changes: 1 addition & 1 deletion eth/vm/forks/gray_glacier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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)
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

0 comments on commit 7611d4e

Please sign in to comment.