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

Commit 4c14bb5

Browse files
committed
use floored division
1 parent 4affaec commit 4c14bb5

File tree

9 files changed

+20
-17
lines changed

9 files changed

+20
-17
lines changed

ethereum/abi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,12 @@ def decode_single(typ, data):
494494
return (o - 2**int(sub)) if o >= 2**(int(sub) - 1) else o
495495
elif base == 'ureal':
496496
high, low = [int(x) for x in sub.split('x')]
497-
return big_endian_to_int(data) * 1.0 / 2**low
497+
return big_endian_to_int(data) * 1.0 // 2**low
498498
elif base == 'real':
499499
high, low = [int(x) for x in sub.split('x')]
500500
o = big_endian_to_int(data)
501501
i = (o - 2**(high+low)) if o >= 2**(high+low-1) else o
502-
return (i * 1.0 / 2**low)
502+
return (i * 1.0 // 2**low)
503503
elif base == 'bool':
504504
return bool(int(encode_hex(data), 16))
505505

ethereum/blocks.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,10 +1169,13 @@ def finalize(self):
11691169
self.ether_delta += delta
11701170

11711171
for uncle in self.uncles:
1172-
r = self.config['BLOCK_REWARD'] * \
1173-
(self.config['UNCLE_DEPTH_PENALTY_FACTOR'] + uncle.number - self.number) \
1174-
/ self.config['UNCLE_DEPTH_PENALTY_FACTOR']
1175-
r = int(r)
1172+
br = self.config['BLOCK_REWARD']
1173+
udpf = self.config['UNCLE_DEPTH_PENALTY_FACTOR']
1174+
un = uncle.number
1175+
bn = self.number
1176+
1177+
r = int(br * (udpf + un - bn) // udpf)
1178+
11761179
self.delta_balance(uncle.coinbase, r)
11771180
self.ether_delta += r
11781181
self.commit_state()
@@ -1307,7 +1310,7 @@ def calc_gaslimit(parent):
13071310

13081311
def check_gaslimit(parent, gas_limit):
13091312
config = parent.config
1310-
# block.gasLimit - parent.gasLimit <= parent.gasLimit / GasLimitBoundDivisor
1313+
# block.gasLimit - parent.gasLimit <= parent.gasLimit // GasLimitBoundDivisor
13111314
gl = parent.gas_limit // config['GASLIMIT_ADJMAX_FACTOR']
13121315
a = bool(abs(gas_limit - parent.gas_limit) <= gl)
13131316
b = bool(gas_limit >= config['MIN_GAS_LIMIT'])

ethereum/ethash_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def deserialize_cache(ds):
9494
class ListWrapper(list):
9595
def __init__(self, data):
9696
self.data = data
97-
self.len = len(data) / HASH_BYTES
97+
self.len = len(data) // HASH_BYTES
9898

9999
def __len__(self):
100100
return self.len
@@ -122,14 +122,14 @@ def isprime(x):
122122
def get_cache_size(block_number):
123123
sz = CACHE_BYTES_INIT + CACHE_BYTES_GROWTH * (block_number // EPOCH_LENGTH)
124124
sz -= HASH_BYTES
125-
while not isprime(sz / HASH_BYTES):
125+
while not isprime(sz // HASH_BYTES):
126126
sz -= 2 * HASH_BYTES
127127
return sz
128128

129129

130130
def get_full_size(block_number):
131131
sz = DATASET_BYTES_INIT + DATASET_BYTES_GROWTH * (block_number // EPOCH_LENGTH)
132132
sz -= MIX_BYTES
133-
while not isprime(sz / MIX_BYTES):
133+
while not isprime(sz // MIX_BYTES):
134134
sz -= 2 * MIX_BYTES
135135
return sz

ethereum/ethpow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def check_pow(block_number, header_hash, mixhash, nonce, difficulty):
7171
mining_output = hashimoto_light(block_number, cache, header_hash, nonce)
7272
if mining_output[b'mix digest'] != mixhash:
7373
return False
74-
return utils.big_endian_to_int(mining_output[b'result']) <= 2**256 / (difficulty or 1)
74+
return utils.big_endian_to_int(mining_output[b'result']) <= 2**256 // (difficulty or 1)
7575

7676

7777
class Miner():

ethereum/keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def big_endian_to_int(value):
247247
if sys.version_info.major == 3:
248248

249249
def int_to_big_endian(value):
250-
byte_length = ceil(value.bit_length() / 8)
250+
byte_length = ceil(value.bit_length() // 8)
251251
return (value).to_bytes(byte_length, byteorder='big')
252252

253253
def big_endian_to_int(value):

ethereum/tests/bintrie.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ def test(n, m=100):
282282
o = {
283283
'total_db_size': sum([len(val) for key, val in l1.kv.items()]),
284284
'avg_proof_size': sum([len(val) for key, val in l1.kv.items()]),
285-
'avg_compressed_proof_size': (p / min(n, m)),
286-
'avg_branch_size': (q / min(n, m)),
285+
'avg_compressed_proof_size': (p // min(n, m)),
286+
'avg_branch_size': (q // min(n, m)),
287287
'compressed_db_size': len(compress_db(l1))
288288
}
289289
return o

ethereum/tests/test_chain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def test_reward_uncles(db):
525525
assert blk2 == chain.head
526526
assert chain.head.get_balance(local_coinbase) == \
527527
2 * chain.env.config['BLOCK_REWARD'] + chain.env.config['NEPHEW_REWARD']
528-
assert chain.head.get_balance(uncle_coinbase) == chain.env.config['BLOCK_REWARD'] * 7 / 8
528+
assert chain.head.get_balance(uncle_coinbase) == chain.env.config['BLOCK_REWARD'] * 7 // 8
529529

530530

531531
# TODO ##########################################

ethereum/tests/test_logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_tracebacks(caplog):
7171

7272
def div(a, b):
7373
try:
74-
_ = a / b
74+
_ = a // b
7575
log.error('heres the stack', stack_info=True)
7676
except Exception as e:
7777
log.error('an Exception trace should preceed this msg', exc_info=True)

ethereum/transactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def __structlog__(self):
195195
# The >= operator is replaced by > because the integer division N/2 always produces the value
196196
# which is by 0.5 less than the real N/2
197197
def check_low_s(self):
198-
if self.s > N / 2 or self.s == 0:
198+
if self.s > N // 2 or self.s == 0:
199199
raise InvalidTransaction("Invalid signature S value!")
200200

201201

0 commit comments

Comments
 (0)