1414from ethereum .pruning_trie import Trie
1515from ethereum .securetrie import SecureTrie
1616from 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
1918from ethereum import processblock
2019from ethereum .transactions import Transaction
2120from ethereum import bloom
@@ -76,11 +75,11 @@ def calc_difficulty(parent, timestamp):
7675 o = int (max (parent .difficulty + offset * sign , min (parent .difficulty , config ['MIN_DIFF' ])))
7776 period_count = (parent .number + 1 ) // config ['EXPDIFF_PERIOD' ]
7877 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))
8080 return o
8181
8282
83-
8483class Account (rlp .Serializable ):
8584
8685 """An Ethereum account.
@@ -333,7 +332,7 @@ def __eq__(self, other):
333332 return isinstance (other , BlockHeader ) and self .hash == other .hash
334333
335334 def __hash__ (self ):
336- return utils . big_endian_to_int (self .hash )
335+ return big_endian_to_int (self .hash )
337336
338337 def __ne__ (self , other ):
339338 return not self .__eq__ (other )
@@ -398,7 +397,7 @@ def __init__(self, header, transaction_list=[], uncles=[], env=None,
398397 parent = None , making = False ):
399398 assert isinstance (env , Env ), "No Env object given"
400399 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
402401 self .db = env .db
403402 self .config = env .config
404403
@@ -444,9 +443,12 @@ def __init__(self, header, transaction_list=[], uncles=[], env=None,
444443 raise ValueError ("Gas used exceeds gas limit" )
445444 if self .timestamp <= parent .header .timestamp :
446445 raise ValueError ("Timestamp equal to or before parent" )
447- if self .timestamp >= 2 ** 256 :
446+ if self .timestamp >= 2 ** 256 :
448447 raise ValueError ("Timestamp waaaaaaaaaaayy too large" )
449448
449+ if self .gas_limit > 2 ** 63 - 1 :
450+ raise ValueError ("Block's gaslimit went too high!" )
451+
450452 for uncle in uncles :
451453 assert isinstance (uncle , BlockHeader )
452454
@@ -533,7 +535,7 @@ def must_le(what, a, b):
533535 if not self .check_fields ():
534536 raise ValueError ("Block is invalid" )
535537 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"
537539 % default_config ['MAX_EXTRADATA_LENGTH' ])
538540 if self .header .coinbase == '' :
539541 raise ValueError ("Coinbase cannot be empty address" )
@@ -697,7 +699,7 @@ def get_ancestor_list(self, n):
697699 if n == 0 or self .header .number == 0 :
698700 return []
699701 p = self .get_parent ()
700- return [p ] + p .get_ancestor_list (n - 1 )
702+ return [p ] + p .get_ancestor_list (n - 1 )
701703
702704 def get_ancestor_hash (self , n ):
703705 assert n > 0
@@ -708,7 +710,7 @@ def get_ancestor_hash(self, n):
708710 self .ancestor_hashes .append (
709711 get_block (self .env ,
710712 self .ancestor_hashes [- 1 ]).get_parent ().hash )
711- return self .ancestor_hashes [n - 1 ]
713+ return self .ancestor_hashes [n - 1 ]
712714
713715 # def get_ancestor(self, n):
714716 # return self.get_block(self.get_ancestor_hash(n))
@@ -787,7 +789,7 @@ def _delta_item(self, address, param, value):
787789 new_value = self ._get_acct_item (address , param ) + value
788790 if new_value < 0 :
789791 return False
790- self ._set_acct_item (address , param , new_value % 2 ** 256 )
792+ self ._set_acct_item (address , param , new_value % 2 ** 256 )
791793 return True
792794
793795 def mk_transaction_receipt (self , tx ):
@@ -965,7 +967,7 @@ def reset_storage(self, address):
965967 for k in self .caches [CACHE_KEY ]:
966968 self .set_and_journal (CACHE_KEY , k , 0 )
967969
968- def get_storage_bytes (self , address , index ):
970+ def get_storage_data (self , address , index ):
969971 """Get a specific item in the storage of an account.
970972
971973 :param address: the address of the account (binary or hex string)
@@ -981,16 +983,9 @@ def get_storage_bytes(self, address, index):
981983 key = utils .zpad (utils .coerce_to_bytes (index ), 32 )
982984 storage = self .get_storage (address ).get (key )
983985 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 )
992987 else :
993- return big_endian_to_int ( bytez )
988+ return 0
994989
995990 def set_storage_data (self , address , index , value ):
996991 """Set a specific item in the storage of an account.
@@ -1006,7 +1001,6 @@ def set_storage_data(self, address, index, value):
10061001 if CACHE_KEY not in self .caches :
10071002 self .caches [CACHE_KEY ] = {}
10081003 self .set_and_journal ('all' , address , True )
1009- assert isinstance (value , (str , bytes ))
10101004 self .set_and_journal (CACHE_KEY , index , value )
10111005
10121006 def account_exists (self , address ):
@@ -1108,12 +1102,12 @@ def account_to_dict(self, address, with_storage_root=False,
11081102 for kk in list (subcache .keys ())]
11091103 for k in list (d .keys ()) + subkeys :
11101104 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 )
11121106 hexkey = b'0x' + encode_hex (utils .zunpad (k ))
11131107 if v2 is not None :
1114- if v2 != b'' :
1108+ if v2 != 0 :
11151109 med_dict ['storage' ][hexkey ] = \
1116- b'0x' + encode_hex (v2 )
1110+ b'0x' + encode_hex (utils . int_to_big_endian ( v2 ) )
11171111 elif v is not None :
11181112 med_dict ['storage' ][hexkey ] = b'0x' + encode_hex (rlp .decode (v ))
11191113
@@ -1177,14 +1171,6 @@ def revert(self, mysnapshot):
11771171 self .ether_delta = mysnapshot ['ether_delta' ]
11781172
11791173 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
11881174 if self .number == self .config ["METROPOLIS_FORK_BLKNUM" ]:
11891175 self .set_code (utils .normalize_address (self .config ["METROPOLIS_STATEROOT_STORE" ]), self .config ["METROPOLIS_GETTER_CODE" ])
11901176 self .set_code (utils .normalize_address (self .config ["METROPOLIS_BLOCKHASH_STORE" ]), self .config ["METROPOLIS_GETTER_CODE" ])
@@ -1308,7 +1294,7 @@ def __eq__(self, other):
13081294 return isinstance (other , (Block , CachedBlock )) and self .hash == other .hash
13091295
13101296 def __hash__ (self ):
1311- return utils . big_endian_to_int (self .hash )
1297+ return big_endian_to_int (self .hash )
13121298
13131299 def __ne__ (self , other ):
13141300 return not self .__eq__ (other )
@@ -1366,7 +1352,7 @@ def commit_state(self):
13661352 pass
13671353
13681354 def __hash__ (self ):
1369- return utils . big_endian_to_int (self .hash )
1355+ return big_endian_to_int (self .hash )
13701356
13711357 @property
13721358 def hash (self ):
@@ -1454,9 +1440,8 @@ def genesis(env, **kwargs):
14541440 block .set_nonce (addr , utils .parse_int_or_hex (data ['nonce' ]))
14551441 if 'storage' in data :
14561442 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 :])))
14601445 block .commit_state ()
14611446 block .state .db .commit ()
14621447 # genesis block has predefined state root (so no additional finalization
0 commit comments