Merge pull request #372 from b-mueller/refactor

Leveldb code cleanup
pull/374/head
Bernhard Mueller 6 years ago committed by GitHub
commit bcb051711f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      mythril/leveldb/accountindexing.py
  2. 3
      mythril/leveldb/client.py
  3. 2
      mythril/leveldb/eth_db.py

@ -1,18 +1,14 @@
import os
import hashlib
import transaction
from threading import Thread
import logging
from mythril import ether
import time
from ethereum.messages import Log
from ethereum.block import BlockHeader
import rlp
from rlp.sedes import big_endian_int, binary
from ethereum import utils
from ethereum.utils import hash32, address, int256
BATCH_SIZE = 8*4096
BATCH_SIZE = 8 * 4096
class CountableList(object):
"""A sedes for lists of arbitrary length.
@ -35,6 +31,7 @@ class CountableList(object):
except:
return []
class ReceiptForStorage(rlp.Serializable):
'''
Receipt format stored in levelDB
@ -50,6 +47,7 @@ class ReceiptForStorage(rlp.Serializable):
('gas_used', big_endian_int)
]
class AccountIndexer(object):
'''
Updates address index
@ -117,7 +115,7 @@ class AccountIndexer(object):
blockNum = 0
if self.lastProcessedBlock is not None:
blockNum = self.lastProcessedBlock+1
blockNum = self.lastProcessedBlock + 1
print("Updating hash-to-address index from block " + str(self.lastProcessedBlock))
else:
print("Starting hash-to-address index")
@ -136,20 +134,19 @@ class AccountIndexer(object):
# store new mappings
self.db.writer._start_writing()
count += len(results)
for address in results:
self.db.writer._store_account_address(address)
for addr in results:
self.db.writer._store_account_address(addr)
self.db.writer._commit_batch()
processed += BATCH_SIZE
blockNum = min(blockNum + BATCH_SIZE, self.lastBlock+1)
blockNum = min(blockNum + BATCH_SIZE, self.lastBlock + 1)
cost_time = time.time() - ether.start_time
print("%d blocks processed (in %d seconds), %d unique addresses found, next block: %d" % (processed, cost_time, count, min(self.lastBlock, blockNum)))
self.lastProcessedBlock = blockNum-1
self.lastProcessedBlock = blockNum - 1
self.db.writer._set_last_indexed_number(self.lastProcessedBlock)
print("Finished indexing")
self.lastBlock = self.lastProcessedBlock

@ -38,6 +38,7 @@ def _encode_hex(v):
'''
return '0x' + utils.encode_hex(v)
class LevelDBReader(object):
'''
level db reading interface, can be used with snapshot
@ -128,6 +129,7 @@ class LevelDBReader(object):
receipts = rlp.decode(receiptsData, sedes=CountableList(ReceiptForStorage))
return receipts
class LevelDBWriter(object):
'''
level db writing interface
@ -162,6 +164,7 @@ class LevelDBWriter(object):
addressKey = addressPrefix + utils.sha3(address)
self.wb.put(addressKey, address)
class EthLevelDB(object):
'''
Go-Ethereum LevelDB client class

@ -1,6 +1,6 @@
import plyvel
from ethereum.db import BaseDB
from ethereum import utils
class ETH_DB(BaseDB):
'''

Loading…
Cancel
Save