Last active
August 29, 2015 14:26
-
-
Save heikoheiko/688aa868a82a976044f0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 sys | |
from ethereum import trie | |
from ethereum.securetrie import SecureTrie | |
from ethereum import blocks | |
import ethereum.chain | |
from pyethapp.leveldb_service import LevelDB | |
from ethereum.utils import big_endian_to_int | |
db = LevelDB(sys.argv[1]) | |
# monkeypatch to old non pruning trie implementation | |
ethereum.chain.trie = trie | |
blocks.trie = trie | |
blocks.Trie = trie.Trie | |
def nonce_storage(blk, address): | |
account = blk._get_acct(address) | |
storage_keys = 0 | |
storage_trie = SecureTrie(trie.Trie(blk.db, account.storage)) | |
for k, v in storage_trie.iter_branch(): | |
if v is not None: | |
storage_keys += 1 | |
return account.nonce, storage_keys | |
chain = ethereum.chain.Chain(db) | |
head = chain.head | |
print "chain head", head | |
class MDict(dict): | |
_len = 5 | |
def add(self, value, address): | |
if len(self) < self._len: | |
self[value] = address | |
return True | |
s = min(self.keys()) | |
if value > s: | |
del self[s] | |
self[value] = address | |
return True | |
assert s >= value | |
def __repr__(self): | |
return repr(sorted(self.items(), reverse=True)) | |
highest_nonce = MDict() | |
most_storage_keys = MDict() | |
lowest_address = MDict() | |
for num_accounts, (address, v) in enumerate(head.state.iter_branch()): | |
if num_accounts % 1000 == 0: | |
print "processed accounts", num_accounts, len(db.uncommitted) | |
if len(db.uncommitted) > 50 * 1000 * 1000: | |
db.uncommitted = {} # delete cache | |
a = blocks.encode_hex(address) | |
nonce, num_keys = nonce_storage(head, address) | |
if highest_nonce.add(nonce, a): | |
print 'best nonces', highest_nonce | |
if most_storage_keys.add(num_keys, a): | |
print 'most storage keys', most_storage_keys | |
db.uncommitted = {} | |
address = big_endian_to_int(address) | |
if nonce > 0 and address > 4 and lowest_address.add(2**256 - address, a): | |
print 'lowest addresses', lowest_address | |
print "DONE", "-" * 30 | |
print "chain head", head | |
print "iterated over %d accounts" % num_accounts | |
print 'best nonce', highest_nonce | |
print 'most storage keys', most_storage_keys | |
print 'lowest address', lowest_address |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment