Skip to content

Instantly share code, notes, and snippets.

@kernel1983
Created September 25, 2023 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kernel1983/f746c1470376e422a8efe3ee6782901d to your computer and use it in GitHub Desktop.
Save kernel1983/f746c1470376e422a8efe3ee6782901d to your computer and use it in GitHub Desktop.
trie and mpt test
import mpt
import rocksdb
class DBWrap:
def __init__(self, db) -> None:
self.db = db
def __setitem__(self, key, value):
self.db.put(key, value)
def __getitem__(self, key):
return self.db.get(key)
conn = rocksdb.DB('mpt.db', rocksdb.Options(create_if_missing=True))
storage = DBWrap(conn)
root_hash = conn.get(b'root_hash')
print('Prev root_hash', root_hash)
trie = mpt.MerklePatriciaTrie(storage, root_hash)
start = 0
while True:
for i in range(start, start+10000):
k = str(i).zfill(32).encode('utf8')
trie.update(k, k)
root_hash = trie.root_hash()
print(f"root_hash hex {root_hash.hex()}")
print(start)
start += 10000
if start > 10000000:
break
import rocksdb
conn = rocksdb.DB('trie.db', rocksdb.Options(create_if_missing=True))
start = 0
while True:
print(start)
for i in range(start, start+10000):
k = str(i).zfill(32).encode('utf8')
conn.put(k, k)
start += 10000
if start > 10000000:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment