Skip to content

Commit bd0c5cb

Browse files
committed
Skip all the default values for the genesis header
The alternative is to modify create_header_from_parent to accept and assign all the rest of the header fields. Since none of these values are important to customize, I'm going with this easier/smaller change.
1 parent 42da4c9 commit bd0c5cb

File tree

5 files changed

+36
-45
lines changed

5 files changed

+36
-45
lines changed

eth/_utils/headers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def fill_header_params_from_parent(
4343
parent_hash = GENESIS_PARENT_HASH
4444
block_number = GENESIS_BLOCK_NUMBER
4545
if state_root is None:
46-
raise ValueError(f"Must set state root on genesis block")
46+
state_root = BLANK_ROOT_HASH
4747
else:
4848
parent_hash = parent.hash
4949
block_number = parent.block_number + 1

eth/tools/builder/chain/builders.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,19 @@ def dao_fork_at(dao_fork_block_number: BlockNumber,
244244

245245
GENESIS_DEFAULTS = cast(
246246
Tuple[Tuple[str, Union[BlockNumber, int, None, bytes, Address, Hash32]], ...],
247+
# values that will automatically be default are commented out
247248
(
248249
('difficulty', 1),
249250
('extra_data', constants.GENESIS_EXTRA_DATA),
250251
('gas_limit', constants.GENESIS_GAS_LIMIT),
251-
('gas_used', 0),
252-
('bloom', 0),
252+
# ('gas_used', 0),
253+
# ('bloom', 0),
253254
('mix_hash', constants.ZERO_HASH32),
254255
('nonce', constants.GENESIS_NONCE),
255-
('block_number', constants.GENESIS_BLOCK_NUMBER),
256-
('parent_hash', constants.GENESIS_PARENT_HASH),
256+
# ('block_number', constants.GENESIS_BLOCK_NUMBER),
257+
# ('parent_hash', constants.GENESIS_PARENT_HASH),
257258
('receipt_root', constants.BLANK_ROOT_HASH),
258-
('uncles_hash', constants.EMPTY_UNCLE_HASH),
259+
# ('uncles_hash', constants.EMPTY_UNCLE_HASH),
259260
('state_root', constants.BLANK_ROOT_HASH),
260261
('transaction_root', constants.BLANK_ROOT_HASH),
261262
)

scripts/benchmark/_utils/chain_plumbing.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,10 @@
6060
SECOND_ADDRESS = Address(SECOND_ADDRESS_PRIVATE_KEY.public_key.to_canonical_address())
6161

6262
GENESIS_PARAMS = {
63-
'parent_hash': constants.GENESIS_PARENT_HASH,
64-
'uncles_hash': constants.EMPTY_UNCLE_HASH,
6563
'coinbase': constants.ZERO_ADDRESS,
6664
'transaction_root': constants.BLANK_ROOT_HASH,
6765
'receipt_root': constants.BLANK_ROOT_HASH,
6866
'difficulty': 1,
69-
'block_number': constants.GENESIS_BLOCK_NUMBER,
7067
'gas_limit': 3141592,
7168
'extra_data': constants.GENESIS_EXTRA_DATA,
7269
'nonce': constants.GENESIS_NONCE

tests/conftest.py

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,27 @@ def funded_address_initial_balance():
122122
return to_wei(1000, 'ether')
123123

124124

125+
# wrapped in a method so that different callers aren't using (and modifying) the same dict
126+
def _get_genesis_defaults():
127+
# values that are not yet customizeable (and will automatically be default) are commented out
128+
return {
129+
'difficulty': constants.GENESIS_DIFFICULTY,
130+
'gas_limit': 3141592,
131+
'coinbase': constants.GENESIS_COINBASE,
132+
'nonce': constants.GENESIS_NONCE,
133+
'mix_hash': constants.GENESIS_MIX_HASH,
134+
'extra_data': constants.GENESIS_EXTRA_DATA,
135+
'timestamp': 1501851927,
136+
# 'block_number': constants.GENESIS_BLOCK_NUMBER,
137+
# 'parent_hash': constants.GENESIS_PARENT_HASH,
138+
# "bloom": 0,
139+
# "gas_used": 0,
140+
# "uncles_hash": decode_hex("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347") # noqa: E501
141+
# "receipt_root": decode_hex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"), # noqa: E501
142+
# "transaction_root": decode_hex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"), # noqa: E501
143+
}
144+
145+
125146
def _chain_with_block_validation(VM, base_db, genesis_state, chain_cls=Chain):
126147
"""
127148
Return a Chain object containing just the genesis block.
@@ -134,32 +155,14 @@ def _chain_with_block_validation(VM, base_db, genesis_state, chain_cls=Chain):
134155
importing arbitrarily constructe, not finalized blocks, use the
135156
chain_without_block_validation fixture instead.
136157
"""
137-
# values that are the same as the default are commented out
138-
genesis_params = {
139-
# "bloom": 0,
140-
"coinbase": to_canonical_address("8888f1f195afa192cfee860698584c030f4c9db1"),
141-
"difficulty": 131072,
142-
"extra_data": b"B",
143-
"gas_limit": 3141592,
144-
# "gas_used": 0,
145-
"mix_hash": decode_hex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"), # noqa: E501
146-
"nonce": decode_hex("0102030405060708"),
147-
# "block_number": 0,
148-
# "parent_hash": decode_hex("0000000000000000000000000000000000000000000000000000000000000000"), # noqa: E501
149-
"receipt_root": decode_hex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"), # noqa: E501
150-
"timestamp": 1422494849,
151-
"transaction_root": decode_hex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"), # noqa: E501
152-
# "uncles_hash": decode_hex("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347") # noqa: E501
153-
}
154-
155158
klass = chain_cls.configure(
156159
__name__='TestChain',
157160
vm_configuration=(
158161
(constants.GENESIS_BLOCK_NUMBER, VM.configure(consensus_class=PowConsensus)),
159162
),
160163
chain_id=1337,
161164
)
162-
chain = klass.from_genesis(base_db, genesis_params, genesis_state)
165+
chain = klass.from_genesis(base_db, _get_genesis_defaults(), genesis_state)
163166
return chain
164167

165168

@@ -225,18 +228,7 @@ def _chain_without_block_validation(request, VM, base_db, genesis_state):
225228
chain_id=1337,
226229
**overrides,
227230
)
228-
genesis_params = {
229-
'block_number': constants.GENESIS_BLOCK_NUMBER,
230-
'difficulty': constants.GENESIS_DIFFICULTY,
231-
'gas_limit': 3141592,
232-
'parent_hash': constants.GENESIS_PARENT_HASH,
233-
'coinbase': constants.GENESIS_COINBASE,
234-
'nonce': constants.GENESIS_NONCE,
235-
'mix_hash': constants.GENESIS_MIX_HASH,
236-
'extra_data': constants.GENESIS_EXTRA_DATA,
237-
'timestamp': 1501851927,
238-
}
239-
chain = klass.from_genesis(base_db, genesis_params, genesis_state)
231+
chain = klass.from_genesis(base_db, _get_genesis_defaults(), genesis_state)
240232
return chain
241233

242234

tests/core/consensus/test_clique_consensus.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@
7171
)
7272

7373
# Genesis params are dervived from the genesis header
74+
# values that are not yet customizeable (and will automatically be default) are commented out
7475
PARAGON_GENESIS_PARAMS = {
75-
'parent_hash': PARAGON_GENESIS_HEADER.parent_hash,
76-
'uncles_hash': PARAGON_GENESIS_HEADER.uncles_hash,
76+
# 'parent_hash': PARAGON_GENESIS_HEADER.parent_hash,
77+
# 'uncles_hash': PARAGON_GENESIS_HEADER.uncles_hash,
7778
'coinbase': PARAGON_GENESIS_HEADER.coinbase,
78-
'transaction_root': PARAGON_GENESIS_HEADER.transaction_root,
79-
'receipt_root': PARAGON_GENESIS_HEADER.receipt_root,
79+
# 'transaction_root': PARAGON_GENESIS_HEADER.transaction_root,
80+
# 'receipt_root': PARAGON_GENESIS_HEADER.receipt_root,
8081
'difficulty': PARAGON_GENESIS_HEADER.difficulty,
81-
'block_number': PARAGON_GENESIS_HEADER.block_number,
82+
# 'block_number': PARAGON_GENESIS_HEADER.block_number,
8283
'timestamp': PARAGON_GENESIS_HEADER.timestamp,
8384
'gas_limit': PARAGON_GENESIS_HEADER.gas_limit,
8485
'extra_data': PARAGON_GENESIS_HEADER.extra_data,

0 commit comments

Comments
 (0)