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

Commit 7d86e38

Browse files
author
Jan Xie
committed
better uncommitted control
1 parent 429dd8d commit 7d86e38

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ethereum/snapshot.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,20 @@ def load_state(env, alloc):
147147
count = 0
148148
print "Start loading state from snapshot"
149149
for addr in alloc:
150+
print "[%d] loading account %s" % (count, addr)
150151
account = alloc[addr]
151152
acct = Account.blank_account(db, env.config['ACCOUNT_INITIAL_NONCE'])
152153
if len(account['storage']) > 0:
153154
t = SecureTrie(Trie(db, BLANK_ROOT))
155+
c = 0
154156
for k in account['storage']:
155157
v = account['storage'][k]
156158
enckey = zpad(decode_hex(k), 32)
157159
t.update(enckey, decode_hex(v))
160+
c += 1
161+
if c % 1000 and len(db.db_service.uncommitted) > 50000:
162+
print "%d uncommitted. committing..." % len(db.db_service.uncommitted)
163+
db.commit()
158164
acct.storage = t.root_hash
159165
if account['nonce']:
160166
acct.nonce = int(account['nonce'])
@@ -164,9 +170,6 @@ def load_state(env, alloc):
164170
acct.code = decode_hex(account['code'])
165171
state.update(decode_hex(addr), rlp.encode(acct))
166172
count += 1
167-
if count % 1000 == 0:
168-
db.commit()
169-
print "[%d] loaded account %s" % (count, addr)
170173
db.commit()
171174
return state
172175

0 commit comments

Comments
 (0)