14
14
from ethereum .pruning_trie import Trie
15
15
from ethereum .securetrie import SecureTrie
16
16
from ethereum import utils
17
- from ethereum .utils import address , int256 , trie_root , hash32 , to_string
18
- from ethereum .utils import big_endian_to_int
17
+ from ethereum .utils import address , int256 , trie_root , hash32 , to_string , big_endian_to_int
19
18
from ethereum import processblock
20
19
from ethereum .transactions import Transaction
21
20
from ethereum import bloom
@@ -76,11 +75,11 @@ def calc_difficulty(parent, timestamp):
76
75
o = int (max (parent .difficulty + offset * sign , min (parent .difficulty , config ['MIN_DIFF' ])))
77
76
period_count = (parent .number + 1 ) // config ['EXPDIFF_PERIOD' ]
78
77
if period_count >= config ['EXPDIFF_FREE_PERIODS' ]:
79
- o = max (o + 2 ** (period_count - config ['EXPDIFF_FREE_PERIODS' ]), config ['MIN_DIFF' ])
78
+ o = max (o + 2 ** (period_count - config ['EXPDIFF_FREE_PERIODS' ]), config ['MIN_DIFF' ])
79
+ # print('Calculating difficulty of block %d, timestamp difference %d, parent diff %d, child diff %d' % (parent.number + 1, timestamp - parent.timestamp, parent.difficulty, o))
80
80
return o
81
81
82
82
83
-
84
83
class Account (rlp .Serializable ):
85
84
86
85
"""An Ethereum account.
@@ -333,7 +332,7 @@ def __eq__(self, other):
333
332
return isinstance (other , BlockHeader ) and self .hash == other .hash
334
333
335
334
def __hash__ (self ):
336
- return utils . big_endian_to_int (self .hash )
335
+ return big_endian_to_int (self .hash )
337
336
338
337
def __ne__ (self , other ):
339
338
return not self .__eq__ (other )
@@ -398,7 +397,7 @@ def __init__(self, header, transaction_list=[], uncles=[], env=None,
398
397
parent = None , making = False ):
399
398
assert isinstance (env , Env ), "No Env object given"
400
399
assert isinstance (env .db , BaseDB ), "No database object given"
401
- self .env = env # don't re-set after init
400
+ self .env = env # don't re-set after init
402
401
self .db = env .db
403
402
self .config = env .config
404
403
@@ -444,9 +443,12 @@ def __init__(self, header, transaction_list=[], uncles=[], env=None,
444
443
raise ValueError ("Gas used exceeds gas limit" )
445
444
if self .timestamp <= parent .header .timestamp :
446
445
raise ValueError ("Timestamp equal to or before parent" )
447
- if self .timestamp >= 2 ** 256 :
446
+ if self .timestamp >= 2 ** 256 :
448
447
raise ValueError ("Timestamp waaaaaaaaaaayy too large" )
449
448
449
+ if self .gas_limit > 2 ** 63 - 1 :
450
+ raise ValueError ("Block's gaslimit went too high!" )
451
+
450
452
for uncle in uncles :
451
453
assert isinstance (uncle , BlockHeader )
452
454
@@ -533,7 +535,7 @@ def must_le(what, a, b):
533
535
if not self .check_fields ():
534
536
raise ValueError ("Block is invalid" )
535
537
if len (to_string (self .header .extra_data )) > self .config ['MAX_EXTRADATA_LENGTH' ]:
536
- raise ValueError ("Extra data cannot exceed %d bytes" \
538
+ raise ValueError ("Extra data cannot exceed %d bytes"
537
539
% default_config ['MAX_EXTRADATA_LENGTH' ])
538
540
if self .header .coinbase == '' :
539
541
raise ValueError ("Coinbase cannot be empty address" )
@@ -697,7 +699,7 @@ def get_ancestor_list(self, n):
697
699
if n == 0 or self .header .number == 0 :
698
700
return []
699
701
p = self .get_parent ()
700
- return [p ] + p .get_ancestor_list (n - 1 )
702
+ return [p ] + p .get_ancestor_list (n - 1 )
701
703
702
704
def get_ancestor_hash (self , n ):
703
705
assert n > 0
@@ -708,7 +710,7 @@ def get_ancestor_hash(self, n):
708
710
self .ancestor_hashes .append (
709
711
get_block (self .env ,
710
712
self .ancestor_hashes [- 1 ]).get_parent ().hash )
711
- return self .ancestor_hashes [n - 1 ]
713
+ return self .ancestor_hashes [n - 1 ]
712
714
713
715
# def get_ancestor(self, n):
714
716
# return self.get_block(self.get_ancestor_hash(n))
@@ -787,7 +789,7 @@ def _delta_item(self, address, param, value):
787
789
new_value = self ._get_acct_item (address , param ) + value
788
790
if new_value < 0 :
789
791
return False
790
- self ._set_acct_item (address , param , new_value % 2 ** 256 )
792
+ self ._set_acct_item (address , param , new_value % 2 ** 256 )
791
793
return True
792
794
793
795
def mk_transaction_receipt (self , tx ):
@@ -965,7 +967,7 @@ def reset_storage(self, address):
965
967
for k in self .caches [CACHE_KEY ]:
966
968
self .set_and_journal (CACHE_KEY , k , 0 )
967
969
968
- def get_storage_bytes (self , address , index ):
970
+ def get_storage_data (self , address , index ):
969
971
"""Get a specific item in the storage of an account.
970
972
971
973
:param address: the address of the account (binary or hex string)
@@ -981,16 +983,9 @@ def get_storage_bytes(self, address, index):
981
983
key = utils .zpad (utils .coerce_to_bytes (index ), 32 )
982
984
storage = self .get_storage (address ).get (key )
983
985
if storage :
984
- return rlp .decode (storage )
985
- else :
986
- return b''
987
-
988
- def get_storage_data (self , address , index ):
989
- bytez = self .get_storage_bytes (address , index )
990
- if len (bytez ) >= 32 :
991
- return big_endian_to_int (bytez [- 32 :])
986
+ return rlp .decode (storage , big_endian_int )
992
987
else :
993
- return big_endian_to_int ( bytez )
988
+ return 0
994
989
995
990
def set_storage_data (self , address , index , value ):
996
991
"""Set a specific item in the storage of an account.
@@ -1006,7 +1001,6 @@ def set_storage_data(self, address, index, value):
1006
1001
if CACHE_KEY not in self .caches :
1007
1002
self .caches [CACHE_KEY ] = {}
1008
1003
self .set_and_journal ('all' , address , True )
1009
- assert isinstance (value , (str , bytes ))
1010
1004
self .set_and_journal (CACHE_KEY , index , value )
1011
1005
1012
1006
def account_exists (self , address ):
@@ -1108,12 +1102,12 @@ def account_to_dict(self, address, with_storage_root=False,
1108
1102
for kk in list (subcache .keys ())]
1109
1103
for k in list (d .keys ()) + subkeys :
1110
1104
v = d .get (k , None )
1111
- v2 = subcache .get (utils . big_endian_to_int (k ), None )
1105
+ v2 = subcache .get (big_endian_to_int (k ), None )
1112
1106
hexkey = b'0x' + encode_hex (utils .zunpad (k ))
1113
1107
if v2 is not None :
1114
- if v2 != b'' :
1108
+ if v2 != 0 :
1115
1109
med_dict ['storage' ][hexkey ] = \
1116
- b'0x' + encode_hex (v2 )
1110
+ b'0x' + encode_hex (utils . int_to_big_endian ( v2 ) )
1117
1111
elif v is not None :
1118
1112
med_dict ['storage' ][hexkey ] = b'0x' + encode_hex (rlp .decode (v ))
1119
1113
@@ -1177,14 +1171,6 @@ def revert(self, mysnapshot):
1177
1171
self .ether_delta = mysnapshot ['ether_delta' ]
1178
1172
1179
1173
def initialize (self , parent ):
1180
- # DAO fork
1181
- if self .number == self .config ["DAO_FORK_BLKNUM" ]:
1182
- dao_main_addr = utils .normalize_address (self .config ["DAO_MAIN_ADDR" ])
1183
- for acct in map (utils .normalize_address , self .config ["DAO_ADDRESS_LIST" ]):
1184
- self .delta_balance (dao_main_addr , self .get_balance (addr ))
1185
- self .set_balance (addr , 0 )
1186
- self .set_code (dao_main_addr , self .config ["DAO_NEWCODE" ])
1187
- # Likely metropolis changes
1188
1174
if self .number == self .config ["METROPOLIS_FORK_BLKNUM" ]:
1189
1175
self .set_code (utils .normalize_address (self .config ["METROPOLIS_STATEROOT_STORE" ]), self .config ["METROPOLIS_GETTER_CODE" ])
1190
1176
self .set_code (utils .normalize_address (self .config ["METROPOLIS_BLOCKHASH_STORE" ]), self .config ["METROPOLIS_GETTER_CODE" ])
@@ -1308,7 +1294,7 @@ def __eq__(self, other):
1308
1294
return isinstance (other , (Block , CachedBlock )) and self .hash == other .hash
1309
1295
1310
1296
def __hash__ (self ):
1311
- return utils . big_endian_to_int (self .hash )
1297
+ return big_endian_to_int (self .hash )
1312
1298
1313
1299
def __ne__ (self , other ):
1314
1300
return not self .__eq__ (other )
@@ -1366,7 +1352,7 @@ def commit_state(self):
1366
1352
pass
1367
1353
1368
1354
def __hash__ (self ):
1369
- return utils . big_endian_to_int (self .hash )
1355
+ return big_endian_to_int (self .hash )
1370
1356
1371
1357
@property
1372
1358
def hash (self ):
@@ -1454,9 +1440,8 @@ def genesis(env, **kwargs):
1454
1440
block .set_nonce (addr , utils .parse_int_or_hex (data ['nonce' ]))
1455
1441
if 'storage' in data :
1456
1442
for k , v in data ['storage' ].items ():
1457
- block .set_storage_data (addr ,
1458
- utils .big_endian_to_int (decode_hex (k [2 :])),
1459
- decode_hex (v [2 :]))
1443
+ block .set_storage_data (addr , big_endian_to_int (decode_hex (k [2 :])),
1444
+ big_endian_to_int (decode_hex (v [2 :])))
1460
1445
block .commit_state ()
1461
1446
block .state .db .commit ()
1462
1447
# genesis block has predefined state root (so no additional finalization
0 commit comments