Created
September 25, 2023 09:01
-
-
Save kernel1983/f746c1470376e422a8efe3ee6782901d to your computer and use it in GitHub Desktop.
trie and mpt test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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