Skip to content

Commit 1aa06da

Browse files
authored
Move mainnet DAO fork config into mainnet configuration (#1433)
* Move mainnet DAO fork config into mainnet configuration * make explicit configuration of dao fork required * make dao_fork_block_number property private
1 parent 51d59fb commit 1aa06da

File tree

11 files changed

+36
-21
lines changed

11 files changed

+36
-21
lines changed

eth/chains/mainnet/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
HOMESTEAD_MAINNET_BLOCK,
1414
SPURIOUS_DRAGON_MAINNET_BLOCK,
1515
DAO_FORK_MAINNET_EXTRA_DATA,
16+
DAO_FORK_MAINNET_BLOCK,
1617
)
1718
from eth import constants as eth_constants
1819

@@ -39,7 +40,8 @@ def validate_header(cls, header, previous_header, check_seal=True):
3940
super().validate_header(header, previous_header, check_seal) # type: ignore
4041

4142
# The special extra_data is set on the ten headers starting at the fork
42-
extra_data_block_nums = range(cls.dao_fork_block_number, cls.dao_fork_block_number + 10)
43+
dao_fork_at = cls.get_dao_fork_block_number()
44+
extra_data_block_nums = range(dao_fork_at, dao_fork_at + 10)
4345

4446
if header.block_number in extra_data_block_nums:
4547
if cls.support_dao_fork and header.extra_data != DAO_FORK_MAINNET_EXTRA_DATA:
@@ -60,7 +62,7 @@ def validate_header(cls, header, previous_header, check_seal=True):
6062

6163

6264
class MainnetHomesteadVM(MainnetDAOValidatorVM, HomesteadVM):
63-
pass
65+
_dao_fork_block_number = DAO_FORK_MAINNET_BLOCK
6466

6567

6668
MAINNET_FORK_BLOCKS = (

eth/chains/mainnet/constants.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from eth_typing import BlockNumber
2+
3+
14
# https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md
25
MAINNET_CHAIN_ID = 1
36

@@ -13,7 +16,7 @@
1316
#
1417
# DAO Block
1518
#
16-
DAO_FORK_MAINNET_BLOCK = 1920000
19+
DAO_FORK_MAINNET_BLOCK = BlockNumber(1920000)
1720

1821
DAO_FORK_MAINNET_EXTRA_DATA = b'dao-hard-fork'
1922

eth/chains/tester/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ def _generate_vm_configuration(*fork_start_blocks: ForkStartBlocks,
120120
if dao_start_block is False:
121121
yield (start_block, vm_class.configure(support_dao_fork=False))
122122
elif dao_start_block is None:
123-
yield (start_block, vm_class.configure(dao_fork_block_number=start_block))
123+
yield (start_block, vm_class.configure(_dao_fork_block_number=start_block))
124124
elif isinstance(dao_start_block, int):
125125
validate_gte(dao_start_block, start_block)
126-
yield (start_block, vm_class.configure(dao_fork_block_number=dao_start_block))
126+
yield (start_block, vm_class.configure(_dao_fork_block_number=dao_start_block))
127127
else:
128128
raise Exception("Invariant: unreachable code path")
129129
else:

eth/tools/builder/chain/builders.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,20 @@ def disable_dao_fork(chain_class: BaseChain) -> type:
186186

187187

188188
@to_tuple
189-
def _set_vm_dao_fork_block_number(dao_fork_block_number: int,
189+
def _set_vm_dao_fork_block_number(dao_fork_block_number: BlockNumber,
190190
vm_configuration: VMConfiguration) -> VMConfiguration:
191191
for fork_block, vm_class in vm_configuration:
192192
if _is_homestead(vm_class):
193193
yield fork_block, vm_class.configure(
194194
support_dao_fork=True,
195-
dao_fork_block_number=dao_fork_block_number,
195+
_dao_fork_block_number=dao_fork_block_number,
196196
)
197197
else:
198198
yield fork_block, vm_class
199199

200200

201201
@curry
202-
def dao_fork_at(dao_fork_block_number: int, chain_class: BaseChain) -> type:
202+
def dao_fork_at(dao_fork_block_number: BlockNumber, chain_class: BaseChain) -> type:
203203
"""
204204
Set the block number on which the DAO fork will happen. Requires that a
205205
version of the :class:`~eth.vm.forks.homestead.HomesteadVM` is present in

eth/tools/fixtures/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def chain_vm_configuration(fixture):
115115
elif network == 'HomesteadToDaoAt5':
116116
HomesteadVM = BaseHomesteadVM.configure(
117117
support_dao_fork=True,
118-
dao_fork_block_number=5,
118+
_dao_fork_block_number=5,
119119
)
120120
return (
121121
(0, HomesteadVM),

eth/vm/forks/homestead/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from typing import Type # noqa: F401
1+
from typing import Optional, Type # noqa: F401
22
from eth.rlp.blocks import BaseBlock # noqa: F401
33
from eth.vm.state import BaseState # noqa: F401
44

5-
from eth.chains.mainnet.constants import (
6-
DAO_FORK_MAINNET_BLOCK
7-
)
5+
from eth_typing import BlockNumber
6+
87
from eth.vm.forks.frontier import FrontierVM
98

109
from .blocks import HomesteadBlock
@@ -18,7 +17,13 @@
1817

1918
class MetaHomesteadVM(FrontierVM):
2019
support_dao_fork = True
21-
dao_fork_block_number = DAO_FORK_MAINNET_BLOCK
20+
_dao_fork_block_number = None # type: Optional[BlockNumber]
21+
22+
@classmethod
23+
def get_dao_fork_block_number(cls) -> BlockNumber:
24+
if cls._dao_fork_block_number is None:
25+
raise TypeError("HomesteadVM must be configured with a valid `_dao_fork_block_number`")
26+
return cls._dao_fork_block_number
2227

2328

2429
class HomesteadVM(MetaHomesteadVM):

eth/vm/forks/homestead/headers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def configure_homestead_header(vm, **header_params):
7575
# get to that. Another alternative would be to do it in Block.mine(), but
7676
# there we'd need to manually instantiate the State and update
7777
# header.state_root after we're done.
78-
if vm.support_dao_fork and changeset.block_number == vm.dao_fork_block_number:
78+
if vm.support_dao_fork and changeset.block_number == vm.get_dao_fork_block_number():
7979
state = vm.state
8080

8181
for account in dao_drain_list:

tests/core/chain-object/test_chain_reorganization.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77

88
@pytest.fixture(params=api.mainnet_fork_at_fns)
99
def base_chain(request):
10+
if request.param is api.homestead_at:
11+
fork_fns = (request.param(0), api.dao_fork_at(0))
12+
else:
13+
fork_fns = (request.param(0),)
14+
1015
chain = api.build(
1116
MiningChain,
12-
request.param(0),
17+
*fork_fns,
1318
api.disable_pow_check(),
1419
api.genesis(),
1520
)

tests/core/tester/test_generate_vm_configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ def test_generate_vm_configuration(args, kwargs, expected):
129129
assert left_vm.support_dao_fork is False
130130
elif dao_start_block is None:
131131
assert left_vm.support_dao_fork is True
132-
assert left_vm.dao_fork_block_number == right_block
132+
assert left_vm.get_dao_fork_block_number() == right_block
133133
else:
134134
assert left_vm.support_dao_fork is True
135-
assert left_vm.dao_fork_block_number == dao_start_block
135+
assert left_vm.get_dao_fork_block_number() == dao_start_block
136136
elif right_vm == Forks.TangerineWhistle:
137137
assert 'TangerineWhistle' in left_vm.__name__
138138
elif right_vm == Forks.SpuriousDragon:

tests/trinity/json-fixtures-over-rpc/test_rpc_fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ async def test_rpc_against_fixtures(chain, ipc_server, chain_fixture, fixture_da
389389
rpc = RPCServer(MainnetFullChain(None))
390390

391391
setup_result, setup_error = await call_rpc(rpc, 'evm_resetToGenesisFixture', [chain_fixture])
392-
assert setup_error is None and setup_result is True, "cannot load chain for %r" % fixture_data
392+
assert setup_error is None and setup_result is True, "cannot load chain for {0}".format(fixture_data) # noqa: E501
393393

394394
await validate_accounts(rpc, chain_fixture['pre'])
395395

0 commit comments

Comments
 (0)