@@ -73,12 +73,11 @@ def calc_difficulty(parent, timestamp):
73
73
o = int (max (parent .difficulty + offset * sign , min (parent .difficulty , config ['MIN_DIFF' ])))
74
74
period_count = (parent .number + 1 ) // config ['EXPDIFF_PERIOD' ]
75
75
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' ])
77
77
# print('Calculating difficulty of block %d, timestamp difference %d, parent diff %d, child diff %d' % (parent.number + 1, timestamp - parent.timestamp, parent.difficulty, o))
78
78
return o
79
79
80
80
81
-
82
81
class Account (rlp .Serializable ):
83
82
84
83
"""An Ethereum account.
@@ -396,7 +395,7 @@ def __init__(self, header, transaction_list=[], uncles=[], env=None,
396
395
parent = None , making = False ):
397
396
assert isinstance (env , Env ), "No Env object given"
398
397
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
400
399
self .db = env .db
401
400
self .config = env .config
402
401
@@ -442,7 +441,7 @@ def __init__(self, header, transaction_list=[], uncles=[], env=None,
442
441
raise ValueError ("Gas used exceeds gas limit" )
443
442
if self .timestamp <= parent .header .timestamp :
444
443
raise ValueError ("Timestamp equal to or before parent" )
445
- if self .timestamp >= 2 ** 256 :
444
+ if self .timestamp >= 2 ** 256 :
446
445
raise ValueError ("Timestamp waaaaaaaaaaayy too large" )
447
446
448
447
for uncle in uncles :
@@ -477,6 +476,7 @@ def __init__(self, header, transaction_list=[], uncles=[], env=None,
477
476
self .transaction_count = 0
478
477
self .gas_used = 0
479
478
# replay
479
+ self .initialize (parent )
480
480
for tx in transaction_list :
481
481
success , output = processblock .apply_transaction (self , tx )
482
482
self .finalize ()
@@ -530,7 +530,7 @@ def must_le(what, a, b):
530
530
if not self .check_fields ():
531
531
raise ValueError ("Block is invalid" )
532
532
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"
534
534
% default_config ['MAX_EXTRADATA_LENGTH' ])
535
535
if self .header .coinbase == '' :
536
536
raise ValueError ("Coinbase cannot be empty address" )
@@ -694,7 +694,7 @@ def get_ancestor_list(self, n):
694
694
if n == 0 or self .header .number == 0 :
695
695
return []
696
696
p = self .get_parent ()
697
- return [p ] + p .get_ancestor_list (n - 1 )
697
+ return [p ] + p .get_ancestor_list (n - 1 )
698
698
699
699
def get_ancestor_hash (self , n ):
700
700
assert n > 0
@@ -705,7 +705,7 @@ def get_ancestor_hash(self, n):
705
705
self .ancestor_hashes .append (
706
706
get_block (self .env ,
707
707
self .ancestor_hashes [- 1 ]).get_parent ().hash )
708
- return self .ancestor_hashes [n - 1 ]
708
+ return self .ancestor_hashes [n - 1 ]
709
709
710
710
# def get_ancestor(self, n):
711
711
# return self.get_block(self.get_ancestor_hash(n))
@@ -784,7 +784,7 @@ def _delta_item(self, address, param, value):
784
784
new_value = self ._get_acct_item (address , param ) + value
785
785
if new_value < 0 :
786
786
return False
787
- self ._set_acct_item (address , param , new_value % 2 ** 256 )
787
+ self ._set_acct_item (address , param , new_value % 2 ** 256 )
788
788
return True
789
789
790
790
def mk_transaction_receipt (self , tx ):
@@ -1162,6 +1162,18 @@ def revert(self, mysnapshot):
1162
1162
self ._get_transactions_cache = []
1163
1163
self .ether_delta = mysnapshot ['ether_delta' ]
1164
1164
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
+
1165
1177
def finalize (self ):
1166
1178
"""Apply rewards and commit."""
1167
1179
delta = int (self .config ['BLOCK_REWARD' ] + self .config ['NEPHEW_REWARD' ] * len (self .uncles ))
0 commit comments