Skip to content

Commit 51d59fb

Browse files
authored
Fix mainnet genesis configuration (#1434)
* Update mainnet genesis constants * update gas estimations to account for new genesis difficulty * more test updates to account for genesis constants change * fix gas limit for benchmark tests
1 parent ae15430 commit 51d59fb

File tree

8 files changed

+26
-23
lines changed

8 files changed

+26
-23
lines changed

docs/guides/eth/understanding_the_mining_process.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,19 @@ cookbook.
4747
from eth.db.atomic import AtomicDB
4848
from eth.chains.mainnet import MAINNET_GENESIS_HEADER
4949

50+
# increase the gas limit
51+
genesis_header = MAINNET_GENESIS_HEADER.copy(gas_limit=3141592)
52+
5053
# initialize a fresh chain
51-
chain = chain_class.from_genesis_header(AtomicDB(), MAINNET_GENESIS_HEADER)
54+
chain = chain_class.from_genesis_header(AtomicDB(), genesis_header)
5255

5356
Since we decided to not add any transactions to our block let's just call
5457
:func:`~~eth.chains.base.MiningChain.mine_block` and see what happens.
5558

5659
::
5760

5861
# initialize a fresh chain
59-
chain = chain_class.from_genesis_header(AtomicDB(), MAINNET_GENESIS_HEADER)
62+
chain = chain_class.from_genesis_header(AtomicDB(), genesis_header)
6063

6164
chain.mine_block()
6265

@@ -150,7 +153,7 @@ Let's start off by defining the ``GENESIS_PARAMS``.
150153
'receipt_root': constants.BLANK_ROOT_HASH,
151154
'difficulty': 1,
152155
'block_number': constants.GENESIS_BLOCK_NUMBER,
153-
'gas_limit': constants.GENESIS_GAS_LIMIT,
156+
'gas_limit': 3141592,
154157
'timestamp': 1514764800,
155158
'extra_data': constants.GENESIS_EXTRA_DATA,
156159
'nonce': constants.GENESIS_NONCE
@@ -330,7 +333,7 @@ zero value transfer transaction.
330333
... 'receipt_root': constants.BLANK_ROOT_HASH,
331334
... 'difficulty': 1,
332335
... 'block_number': constants.GENESIS_BLOCK_NUMBER,
333-
... 'gas_limit': constants.GENESIS_GAS_LIMIT,
336+
... 'gas_limit': 3141592,
334337
... 'timestamp': 1514764800,
335338
... 'extra_data': constants.GENESIS_EXTRA_DATA,
336339
... 'nonce': constants.GENESIS_NONCE

eth/chains/mainnet/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
SPURIOUS_DRAGON_MAINNET_BLOCK,
1515
DAO_FORK_MAINNET_EXTRA_DATA,
1616
)
17-
from eth import constants
17+
from eth import constants as eth_constants
1818

1919
from eth.chains.base import (
2020
Chain,
@@ -91,18 +91,18 @@ class MainnetChain(BaseMainnetChain, Chain):
9191

9292

9393
MAINNET_GENESIS_HEADER = BlockHeader(
94-
difficulty=17179869184,
94+
difficulty=eth_constants.GENESIS_DIFFICULTY,
9595
extra_data=decode_hex("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"),
96-
gas_limit=5000,
96+
gas_limit=eth_constants.GENESIS_GAS_LIMIT,
9797
gas_used=0,
9898
bloom=0,
99-
mix_hash=constants.ZERO_HASH32,
100-
nonce=constants.GENESIS_NONCE,
99+
mix_hash=eth_constants.ZERO_HASH32,
100+
nonce=eth_constants.GENESIS_NONCE,
101101
block_number=0,
102-
parent_hash=constants.ZERO_HASH32,
103-
receipt_root=constants.BLANK_ROOT_HASH,
104-
uncles_hash=constants.EMPTY_UNCLE_HASH,
102+
parent_hash=eth_constants.ZERO_HASH32,
103+
receipt_root=eth_constants.BLANK_ROOT_HASH,
104+
uncles_hash=eth_constants.EMPTY_UNCLE_HASH,
105105
state_root=decode_hex("0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"),
106106
timestamp=0,
107-
transaction_root=constants.BLANK_ROOT_HASH,
107+
transaction_root=eth_constants.BLANK_ROOT_HASH,
108108
)

eth/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@
152152
# Genesis Data
153153
#
154154
GENESIS_BLOCK_NUMBER = 0
155-
GENESIS_DIFFICULTY = 131072
156-
GENESIS_GAS_LIMIT = 3141592
155+
GENESIS_DIFFICULTY = 17179869184
156+
GENESIS_GAS_LIMIT = 5000
157157
GENESIS_PARENT_HASH = ZERO_HASH32
158158
GENESIS_COINBASE = ZERO_ADDRESS
159159
GENESIS_NONCE = b'\x00\x00\x00\x00\x00\x00\x00B' # 0x42 encoded as big-endian-integer

scripts/benchmark/utils/chain_plumbing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
'receipt_root': constants.BLANK_ROOT_HASH,
7070
'difficulty': 1,
7171
'block_number': constants.GENESIS_BLOCK_NUMBER,
72-
'gas_limit': constants.GENESIS_GAS_LIMIT,
72+
'gas_limit': 3141592,
7373
'extra_data': constants.GENESIS_EXTRA_DATA,
7474
'nonce': constants.GENESIS_NONCE
7575
}

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def chain_without_block_validation(
176176
genesis_params = {
177177
'block_number': constants.GENESIS_BLOCK_NUMBER,
178178
'difficulty': constants.GENESIS_DIFFICULTY,
179-
'gas_limit': constants.GENESIS_GAS_LIMIT,
179+
'gas_limit': 3141592,
180180
'parent_hash': constants.GENESIS_PARENT_HASH,
181181
'coinbase': constants.GENESIS_COINBASE,
182182
'nonce': constants.GENESIS_NONCE,

tests/core/chain-object/test_gas_estimation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def chain(chain_without_block_validation):
3030
(b'\xff' * 10, None, ADDR_1010, True, 21680),
3131
(b'\xff' * 10, None, ADDR_1010, False, 21680),
3232
# sha3 precompile
33-
(b'\xff' * 32, None, ADDRESS_2, True, 35381),
34-
(b'\xff' * 32, None, ADDRESS_2, False, 35369),
35-
(b'\xff' * 320, None, ADDRESS_2, True, 54888),
33+
(b'\xff' * 32, None, ADDRESS_2, True, 35333),
34+
(b'\xff' * 32, None, ADDRESS_2, False, 35345),
35+
(b'\xff' * 320, None, ADDRESS_2, True, 54840),
3636
# 1000_tolerance binary search
37-
(b'\xff' * 32, binary_gas_search_1000_tolerance, ADDRESS_2, True, 23938),
37+
(b'\xff' * 32, binary_gas_search_1000_tolerance, ADDRESS_2, True, 23935),
3838
),
3939
ids=[
4040
'simple default pending',

tests/trinity/core/json-rpc/test_ipc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ async def test_network_id_ipc_request(
265265
build_request('eth_estimateGas', params=[{
266266
'data': '0x3838533838f3',
267267
}, 'latest']),
268-
{'result': hex(65483), 'id': 3, 'jsonrpc': '2.0'},
268+
{'result': hex(65459), 'id': 3, 'jsonrpc': '2.0'},
269269
),
270270
(
271271
# specifying v,r,s is invalid

tests/trinity/core/p2p-proto/test_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def chaindb_fresh():
193193
'bloom': 0,
194194
'difficulty': 5,
195195
'block_number': constants.GENESIS_BLOCK_NUMBER,
196-
'gas_limit': constants.GENESIS_GAS_LIMIT,
196+
'gas_limit': 3141592,
197197
'gas_used': 0,
198198
'timestamp': 1514764800,
199199
'extra_data': constants.GENESIS_EXTRA_DATA,

0 commit comments

Comments
 (0)