Skip to content

Commit 3ce11fa

Browse files
committed
Minor tweaks to recent VMs for clarity
- 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
1 parent 12f3bee commit 3ce11fa

File tree

8 files changed

+65
-37
lines changed

8 files changed

+65
-37
lines changed

eth/vm/forks/arrow_glacier/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ArrowGlacierVM(LondonVM):
2525

2626
# Methods
2727
create_header_from_parent = staticmethod( # type: ignore
28-
create_arrow_glacier_header_from_parent
28+
create_arrow_glacier_header_from_parent(compute_arrow_glacier_difficulty)
2929
)
3030
compute_difficulty = staticmethod(compute_arrow_glacier_difficulty) # type: ignore
3131
configure_header = configure_arrow_glacier_header

eth/vm/forks/arrow_glacier/headers.py

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
1+
from typing import Any, Callable, Optional
2+
3+
from toolz import curry
4+
5+
from eth.abc import BlockHeaderAPI
6+
from .blocks import (
7+
ArrowGlacierBlockHeader,
8+
)
19
from eth.vm.forks.london.headers import (
2-
create_header_from_parent,
10+
create_london_header_from_parent,
311
)
4-
from eth.vm.forks.petersburg.headers import (
12+
from eth.vm.forks.byzantium.headers import (
513
compute_difficulty,
614
)
7-
from eth.vm.forks.istanbul.headers import (
15+
from eth.vm.forks.byzantium.headers import (
816
configure_header,
917
)
1018

11-
1219
compute_arrow_glacier_difficulty = compute_difficulty(10_700_000)
20+
configure_arrow_glacier_header = configure_header(compute_arrow_glacier_difficulty)
1321

14-
create_arrow_glacier_header_from_parent = create_header_from_parent(
15-
compute_arrow_glacier_difficulty
16-
)
1722

18-
configure_arrow_glacier_header = configure_header(compute_arrow_glacier_difficulty)
23+
@curry
24+
def create_arrow_glacier_header_from_parent(
25+
difficulty_fn: Callable[[BlockHeaderAPI, int], int],
26+
parent_header: Optional[BlockHeaderAPI],
27+
**header_params: Any
28+
) -> BlockHeaderAPI:
29+
london_validated_header = create_london_header_from_parent(
30+
difficulty_fn, parent_header, **header_params
31+
)
32+
33+
# extract header params validated up to london (previous VM) and plug
34+
# into `ArrowGlacierBlockHeader` class
35+
all_fields = london_validated_header.as_dict()
36+
return ArrowGlacierBlockHeader(**all_fields)

eth/vm/forks/gray_glacier/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class GrayGlacierVM(ArrowGlacierVM):
2525

2626
# Methods
2727
create_header_from_parent = staticmethod( # type: ignore
28-
create_gray_glacier_header_from_parent
28+
create_gray_glacier_header_from_parent(compute_gray_glacier_difficulty)
2929
)
3030
compute_difficulty = staticmethod(compute_gray_glacier_difficulty) # type: ignore
3131
configure_header = configure_gray_glacier_header

eth/vm/forks/gray_glacier/headers.py

+29-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
1-
from eth.vm.forks.london.headers import (
2-
create_header_from_parent,
1+
from typing import Any, Callable, Optional
2+
3+
from toolz import curry
4+
5+
from .blocks import (
6+
GrayGlacierBlockHeader,
7+
)
8+
from eth.abc import (
9+
BlockHeaderAPI,
310
)
4-
from eth.vm.forks.petersburg.headers import (
11+
from eth.vm.forks.arrow_glacier.headers import (
12+
create_arrow_glacier_header_from_parent,
13+
)
14+
from eth.vm.forks.byzantium.headers import (
515
compute_difficulty,
616
)
7-
from eth.vm.forks.istanbul.headers import (
17+
from eth.vm.forks.byzantium.headers import (
818
configure_header,
919
)
1020

11-
1221
compute_gray_glacier_difficulty = compute_difficulty(11_400_000)
22+
configure_gray_glacier_header = configure_header(compute_gray_glacier_difficulty)
1323

14-
create_gray_glacier_header_from_parent = create_header_from_parent(
15-
compute_gray_glacier_difficulty
16-
)
1724

18-
configure_gray_glacier_header = configure_header(compute_gray_glacier_difficulty)
25+
@curry
26+
def create_gray_glacier_header_from_parent(
27+
difficulty_fn: Callable[[BlockHeaderAPI, int], int],
28+
parent_header: Optional[BlockHeaderAPI],
29+
**header_params: Any
30+
) -> BlockHeaderAPI:
31+
arrow_glacier_validated_header = create_arrow_glacier_header_from_parent(
32+
difficulty_fn, parent_header, **header_params
33+
)
34+
35+
# extract header params validated up to arrow glacier (previous VM) and plug
36+
# into `GrayGlacierBlockHeader` class
37+
all_fields = arrow_glacier_validated_header.as_dict()
38+
return GrayGlacierBlockHeader(**all_fields)

eth/vm/forks/london/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class LondonVM(BerlinVM):
3333
_state_class: Type[BaseState] = LondonState
3434

3535
# Methods
36-
create_header_from_parent = staticmethod(create_london_header_from_parent) # type: ignore
36+
create_header_from_parent = staticmethod( # type: ignore
37+
create_london_header_from_parent(compute_london_difficulty)
38+
)
3739
compute_difficulty = staticmethod(compute_london_difficulty) # type: ignore
3840
configure_header = configure_london_header
3941

eth/vm/forks/london/headers.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ def calculate_expected_base_fee_per_gas(parent_header: BlockHeaderAPI) -> int:
7676

7777

7878
@curry
79-
def create_header_from_parent(difficulty_fn: Callable[[BlockHeaderAPI, int], int],
80-
parent_header: Optional[BlockHeaderAPI],
81-
**header_params: Any) -> BlockHeaderAPI:
82-
79+
def create_london_header_from_parent(
80+
difficulty_fn: Callable[[BlockHeaderAPI, int], int],
81+
parent_header: Optional[BlockHeaderAPI],
82+
**header_params: Any
83+
) -> BlockHeaderAPI:
8384
if 'gas_limit' not in header_params:
8485
if parent_header is not None and not hasattr(parent_header, 'base_fee_per_gas'):
8586
# If the previous block was not a London block,
@@ -133,11 +134,6 @@ def create_header_from_parent(difficulty_fn: Callable[[BlockHeaderAPI, int], int
133134

134135

135136
compute_london_difficulty = compute_difficulty(9700000)
136-
137-
create_london_header_from_parent = create_header_from_parent(
138-
compute_london_difficulty
139-
)
140-
141137
configure_london_header = configure_header(compute_london_difficulty)
142138

143139

eth/vm/forks/london/state.py

-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
)
77

88
from eth.abc import (
9-
AccountDatabaseAPI,
109
ComputationAPI,
1110
MessageAPI,
1211
SignedTransactionAPI,
@@ -17,9 +16,6 @@
1716
from eth.constants import (
1817
CREATE_CONTRACT_ADDRESS,
1918
)
20-
from eth.db.account import (
21-
AccountDB
22-
)
2319
from eth.vm.message import (
2420
Message,
2521
)
@@ -100,7 +96,6 @@ def calculate_gas_refund(cls,
10096

10197

10298
class LondonState(BerlinState):
103-
account_db_class: Type[AccountDatabaseAPI] = AccountDB
10499
computation_class = LondonComputation
105100
transaction_executor_class: Type[TransactionExecutorAPI] = LondonTransactionExecutor
106101

tests/json-fixtures/blockchain/test_blockchain.py

-3
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,6 @@ def blockchain_fixture_mark_fn(fixture_path, fixture_name, fixture_fork):
326326
"Skipped failing tests in v11.1 update to get Merge-related changes in. "
327327
"Turn these back on and fix after the Merge is implemented."
328328
)
329-
elif "Merge" in fixture_name:
330-
# TODO: Implement changes for the Merge and turn these tests on
331-
return pytest.mark.skip("The Merge has not yet been implemented.")
332329
elif fixture_id in SLOWEST_TESTS:
333330
if should_run_slow_tests():
334331
return

0 commit comments

Comments
 (0)