Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit cd24f18

Browse files
authored
Merge pull request #383 from ethereum/metropolis_config
Add metropolis config
2 parents 1d2a0cb + 1c35ecc commit cd24f18

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

ethereum/blocks.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,11 @@ def calc_difficulty(parent, timestamp):
7373
o = int(max(parent.difficulty + offset * sign, min(parent.difficulty, config['MIN_DIFF'])))
7474
period_count = (parent.number + 1) // config['EXPDIFF_PERIOD']
7575
if period_count >= config['EXPDIFF_FREE_PERIODS']:
76-
o = max(o + 2**(period_count - config['EXPDIFF_FREE_PERIODS']), config['MIN_DIFF'])
76+
o = max(o + 2 ** (period_count - config['EXPDIFF_FREE_PERIODS']), config['MIN_DIFF'])
7777
# print('Calculating difficulty of block %d, timestamp difference %d, parent diff %d, child diff %d' % (parent.number + 1, timestamp - parent.timestamp, parent.difficulty, o))
7878
return o
7979

8080

81-
8281
class Account(rlp.Serializable):
8382

8483
"""An Ethereum account.
@@ -396,7 +395,7 @@ def __init__(self, header, transaction_list=[], uncles=[], env=None,
396395
parent=None, making=False):
397396
assert isinstance(env, Env), "No Env object given"
398397
assert isinstance(env.db, BaseDB), "No database object given"
399-
self.env = env # don't re-set after init
398+
self.env = env # don't re-set after init
400399
self.db = env.db
401400
self.config = env.config
402401

@@ -442,7 +441,7 @@ def __init__(self, header, transaction_list=[], uncles=[], env=None,
442441
raise ValueError("Gas used exceeds gas limit")
443442
if self.timestamp <= parent.header.timestamp:
444443
raise ValueError("Timestamp equal to or before parent")
445-
if self.timestamp >= 2**256:
444+
if self.timestamp >= 2 ** 256:
446445
raise ValueError("Timestamp waaaaaaaaaaayy too large")
447446

448447
for uncle in uncles:
@@ -477,6 +476,7 @@ def __init__(self, header, transaction_list=[], uncles=[], env=None,
477476
self.transaction_count = 0
478477
self.gas_used = 0
479478
# replay
479+
self.initialize(parent)
480480
for tx in transaction_list:
481481
success, output = processblock.apply_transaction(self, tx)
482482
self.finalize()
@@ -530,7 +530,7 @@ def must_le(what, a, b):
530530
if not self.check_fields():
531531
raise ValueError("Block is invalid")
532532
if len(to_string(self.header.extra_data)) > self.config['MAX_EXTRADATA_LENGTH']:
533-
raise ValueError("Extra data cannot exceed %d bytes" \
533+
raise ValueError("Extra data cannot exceed %d bytes"
534534
% default_config['MAX_EXTRADATA_LENGTH'])
535535
if self.header.coinbase == '':
536536
raise ValueError("Coinbase cannot be empty address")
@@ -694,7 +694,7 @@ def get_ancestor_list(self, n):
694694
if n == 0 or self.header.number == 0:
695695
return []
696696
p = self.get_parent()
697-
return [p] + p.get_ancestor_list(n-1)
697+
return [p] + p.get_ancestor_list(n - 1)
698698

699699
def get_ancestor_hash(self, n):
700700
assert n > 0
@@ -705,7 +705,7 @@ def get_ancestor_hash(self, n):
705705
self.ancestor_hashes.append(
706706
get_block(self.env,
707707
self.ancestor_hashes[-1]).get_parent().hash)
708-
return self.ancestor_hashes[n-1]
708+
return self.ancestor_hashes[n - 1]
709709

710710
# def get_ancestor(self, n):
711711
# return self.get_block(self.get_ancestor_hash(n))
@@ -784,7 +784,7 @@ def _delta_item(self, address, param, value):
784784
new_value = self._get_acct_item(address, param) + value
785785
if new_value < 0:
786786
return False
787-
self._set_acct_item(address, param, new_value % 2**256)
787+
self._set_acct_item(address, param, new_value % 2 ** 256)
788788
return True
789789

790790
def mk_transaction_receipt(self, tx):
@@ -1162,6 +1162,18 @@ def revert(self, mysnapshot):
11621162
self._get_transactions_cache = []
11631163
self.ether_delta = mysnapshot['ether_delta']
11641164

1165+
def initialize(self, parent):
1166+
if self.number == self.config["METROPOLIS_FORK_BLKNUM"]:
1167+
self.set_code(utils.normalize_address(self.config["METROPOLIS_STATEROOT_STORE"]), self.config["METROPOLIS_GETTER_CODE"])
1168+
self.set_code(utils.normalize_address(self.config["METROPOLIS_BLOCKHASH_STORE"]), self.config["METROPOLIS_GETTER_CODE"])
1169+
if self.number >= self.config["METROPOLIS_FORK_BLKNUM"]:
1170+
self.set_storage_data(utils.normalize_address(self.config["METROPOLIS_STATEROOT_STORE"]),
1171+
self.number % self.config["METROPOLIS_WRAPAROUND"],
1172+
parent.state_root)
1173+
self.set_storage_data(utils.normalize_address(self.config["METROPOLIS_BLOCKHASH_STORE"]),
1174+
self.number % self.config["METROPOLIS_WRAPAROUND"],
1175+
self.prevhash)
1176+
11651177
def finalize(self):
11661178
"""Apply rewards and commit."""
11671179
delta = int(self.config['BLOCK_REWARD'] + self.config['NEPHEW_REWARD'] * len(self.uncles))

ethereum/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from rlp.utils import decode_hex
12
from ethereum import utils
23
from ethereum.db import BaseDB
34

@@ -46,6 +47,13 @@
4647
# Homestead fork
4748
HOMESTEAD_FORK_BLKNUM=1150000,
4849
HOMESTEAD_DIFF_ADJUSTMENT_CUTOFF=10,
50+
# Metropolis fork
51+
METROPOLIS_FORK_BLKNUM=9999999,
52+
METROPOLIS_ENTRY_POINT=2 ** 160 - 1,
53+
METROPOLIS_STATEROOT_STORE=0x10,
54+
METROPOLIS_BLOCKHASH_STORE=0x20,
55+
METROPOLIS_WRAPAROUND=65536,
56+
METROPOLIS_GETTER_CODE=decode_hex('6000355460205260206020f3'),
4957
)
5058
assert default_config['NEPHEW_REWARD'] == \
5159
default_config['BLOCK_REWARD'] // 32

0 commit comments

Comments
 (0)