Skip to content

Commit 8ebdfd8

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 8ebdfd8

File tree

9 files changed

+42
-80
lines changed

9 files changed

+42
-80
lines changed

docs/cookbook/index.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,7 @@ state.
7979
... }
8080

8181
>>> GENESIS_PARAMS = {
82-
... 'parent_hash': constants.GENESIS_PARENT_HASH,
83-
... 'uncles_hash': constants.EMPTY_UNCLE_HASH,
84-
... 'coinbase': constants.ZERO_ADDRESS,
85-
... 'transaction_root': constants.BLANK_ROOT_HASH,
86-
... 'receipt_root': constants.BLANK_ROOT_HASH,
8782
... 'difficulty': constants.GENESIS_DIFFICULTY,
88-
... 'block_number': constants.GENESIS_BLOCK_NUMBER,
89-
... 'gas_limit': constants.GENESIS_GAS_LIMIT,
90-
... 'extra_data': constants.GENESIS_EXTRA_DATA,
91-
... 'nonce': constants.GENESIS_NONCE
9283
... }
9384

9485
>>> chain = MainnetChain.from_genesis(AtomicDB(), GENESIS_PARAMS, GENESIS_STATE)

docs/guides/building_an_app_that_uses_pyevm.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,7 @@ Next, we'll create a new directory ``app`` and create a file ``main.py`` inside.
8383
>>> DEFAULT_INITIAL_BALANCE = to_wei(10000, 'ether')
8484

8585
>>> GENESIS_PARAMS = {
86-
... 'parent_hash': constants.GENESIS_PARENT_HASH,
87-
... 'uncles_hash': constants.EMPTY_UNCLE_HASH,
88-
... 'coinbase': constants.ZERO_ADDRESS,
89-
... 'transaction_root': constants.BLANK_ROOT_HASH,
90-
... 'receipt_root': constants.BLANK_ROOT_HASH,
9186
... 'difficulty': constants.GENESIS_DIFFICULTY,
92-
... 'block_number': constants.GENESIS_BLOCK_NUMBER,
93-
... 'gas_limit': constants.GENESIS_GAS_LIMIT,
94-
... 'extra_data': constants.GENESIS_EXTRA_DATA,
95-
... 'nonce': constants.GENESIS_NONCE
9687
... }
9788

9889
>>> GENESIS_STATE = {

docs/guides/understanding_the_mining_process.rst

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,9 @@ Let's start off by defining the ``GENESIS_PARAMS``.
146146
from eth import constants
147147

148148
GENESIS_PARAMS = {
149-
'parent_hash': constants.GENESIS_PARENT_HASH,
150-
'uncles_hash': constants.EMPTY_UNCLE_HASH,
151-
'coinbase': constants.ZERO_ADDRESS,
152-
'transaction_root': constants.BLANK_ROOT_HASH,
153-
'receipt_root': constants.BLANK_ROOT_HASH,
154149
'difficulty': 1,
155-
'block_number': constants.GENESIS_BLOCK_NUMBER,
156150
'gas_limit': 3141592,
157151
'timestamp': 1514764800,
158-
'extra_data': constants.GENESIS_EXTRA_DATA,
159-
'nonce': constants.GENESIS_NONCE
160152
}
161153

162154
Next, we'll create the chain itself using the defined ``GENESIS_PARAMS`` and the latest
@@ -327,17 +319,11 @@ zero value transfer transaction.
327319

328320

329321
>>> GENESIS_PARAMS = {
330-
... 'parent_hash': constants.GENESIS_PARENT_HASH,
331-
... 'uncles_hash': constants.EMPTY_UNCLE_HASH,
332-
... 'coinbase': constants.ZERO_ADDRESS,
333-
... 'transaction_root': constants.BLANK_ROOT_HASH,
334-
... 'receipt_root': constants.BLANK_ROOT_HASH,
335322
... 'difficulty': 1,
336-
... 'block_number': constants.GENESIS_BLOCK_NUMBER,
337323
... 'gas_limit': 3141592,
324+
... # We set the timestamp, just to make this documented example reproducible.
325+
... # In common usage, we remove the field to let py-evm choose a reasonable default.
338326
... 'timestamp': 1514764800,
339-
... 'extra_data': constants.GENESIS_EXTRA_DATA,
340-
... 'nonce': constants.GENESIS_NONCE
341327
... }
342328

343329
>>> SENDER_PRIVATE_KEY = keys.PrivateKey(

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
)

eth/vm/forks/london/headers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ def create_header_from_parent(difficulty_fn: Callable[[BlockHeaderAPI, int], int
8888

8989
if 'difficulty' not in header_params:
9090
if parent_header is None:
91-
raise ValueError("Must set difficulty when creating a new genesis header (no parent)")
91+
raise ValueError(
92+
"Must set difficulty when creating a new genesis header (no parent)."
93+
" Consider 1 for easy mining or eth.constants.GENESIS_DIFFICULTY for consistency."
94+
)
9295
else:
9396
header_params['difficulty'] = difficulty_fn(
9497
parent_header,

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)