Skip to content

Commit ace9d7d

Browse files
committed
Fix old usages of BlockHeader() and .from_parent()
Direct invocation of the header object is not allowed anymore, because different VMs now have different header types (as of EIP-1559 in London). So we must always invoke header creation through the VM. Remove the BlockHeader() init in test_blockchain. Removed HeaderChain, which seems to be completely unused in the code base. Ugly fix for header db, because it only tests chains that are London-style header. Should test a variety of configs.
1 parent bd0c5cb commit ace9d7d

File tree

8 files changed

+96
-191
lines changed

8 files changed

+96
-191
lines changed

eth/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@
161161
GENESIS_NONCE = b'\x00\x00\x00\x00\x00\x00\x00B' # 0x42 encoded as big-endian-integer
162162
GENESIS_MIX_HASH = ZERO_HASH32
163163
GENESIS_EXTRA_DATA = b''
164+
GENESIS_BLOOM = 0
165+
GENESIS_GAS_USED = 0
166+
164167
#
165168
# Sha3 Keccak
166169
#

eth/tools/fixtures/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
)
99
from .helpers import ( # noqa: F401
1010
new_chain_from_fixture,
11+
genesis_fields_from_fixture,
1112
genesis_params_from_fixture,
1213
apply_fixture_block_to_chain,
1314
setup_state,

eth/tools/fixtures/helpers.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
StateAPI,
2525
VirtualMachineAPI,
2626
)
27+
from eth import constants
2728
from eth.db.atomic import AtomicDB
2829
from eth.chains.mainnet import (
2930
MainnetDAOValidatorVM,
@@ -165,7 +166,11 @@ def chain_vm_configuration(fixture: Dict[str, Any]) -> Iterable[Tuple[int, Type[
165166
raise ValueError(f"Network {network} does not match any known VM rules")
166167

167168

168-
def genesis_params_from_fixture(fixture: Dict[str, Any]) -> Dict[str, Any]:
169+
def genesis_fields_from_fixture(fixture: Dict[str, Any]) -> Dict[str, Any]:
170+
"""
171+
Convert all genesis fields in a fixture to a dictionary of header fields and values.
172+
"""
173+
169174
return {
170175
'parent_hash': fixture['genesisBlockHeader']['parentHash'],
171176
'uncles_hash': fixture['genesisBlockHeader']['uncleHash'],
@@ -185,6 +190,34 @@ def genesis_params_from_fixture(fixture: Dict[str, Any]) -> Dict[str, Any]:
185190
}
186191

187192

193+
def genesis_params_from_fixture(fixture: Dict[str, Any]) -> Dict[str, Any]:
194+
"""
195+
Convert a genesis fixture into a dict of the configurable header fields and values.
196+
197+
Some fields cannot be explicitly set when creating a new header, like
198+
parent_hash, which is automatically set to the empty hash.
199+
"""
200+
201+
params = genesis_fields_from_fixture(fixture)
202+
203+
# Confirm that (currently) non-configurable defaults are set correctly,
204+
# then remove them because they cannot be configured on the header.
205+
defaults = (
206+
('parent_hash', constants.GENESIS_PARENT_HASH),
207+
('uncles_hash', constants.EMPTY_UNCLE_HASH),
208+
('bloom', constants.GENESIS_BLOOM),
209+
('block_number', constants.GENESIS_BLOCK_NUMBER),
210+
('gas_used', constants.GENESIS_GAS_USED),
211+
)
212+
213+
for key, default_val in defaults:
214+
supplied_val = params.pop(key)
215+
if supplied_val != default_val:
216+
raise ValueError(f"Unexpected genesis {key}: {supplied_val}, expected: {default_val}")
217+
218+
return params
219+
220+
188221
def new_chain_from_fixture(fixture: Dict[str, Any],
189222
chain_cls: Type[ChainAPI] = MainnetChain) -> ChainAPI:
190223
base_db = AtomicDB()

eth/tools/rlp.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
)
99

1010

11-
assert_imported_genesis_header_unchanged = replace_exceptions({
12-
ValidationError: AssertionError,
13-
})(validate_rlp_equal(obj_a_name='genesis header', obj_b_name='imported header'))
14-
15-
1611
assert_mined_block_unchanged = replace_exceptions({
1712
ValidationError: AssertionError,
1813
})(validate_rlp_equal(obj_a_name='provided block', obj_b_name='executed block'))

tests/core/chain-object/test_header_chain.py

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)