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

Commit 429dd8d

Browse files
author
Jan Xie
committed
make get_score more memory efficient
1 parent 9a3de4f commit 429dd8d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

ethereum/chain.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ def get_score(self, block):
203203

204204
fills = []
205205
while key not in self.db:
206-
fills.insert(0, block)
206+
fills.insert(0, (block.header.hash, block.difficulty))
207207
key = 'score:' + block.header.prevhash
208-
block = self.get_parent(fills[0])
208+
block = self.get_parent(block)
209209
score = int(self.db.get(key))
210-
for block in fills:
211-
key = 'score:' + block.header.hash
212-
score = score + block.difficulty + random.randrange(block.difficulty // 10**6 + 1)
210+
for h,d in fills:
211+
key = 'score:' + h
212+
score = score + d + random.randrange(d // 10**6 + 1)
213213
self.db.put(key, str(score))
214214

215215
return score

0 commit comments

Comments
 (0)