commit 80a5b344f8a4e4d84d0203b027b879c704690506
parent 819b07f1730a4c1e631635887811248aeffea02b
Author: nolash <dev@holbrook.no>
Date: Sun, 13 Jun 2021 13:07:58 +0200
multiprocessing in synceR
Diffstat:
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,5 @@
+__pycache__
+*.pyc
+dist/
+build/
+*.egg-info/
diff --git a/examples/dump.py b/examples/dump.py
@@ -31,6 +31,7 @@ logging.basicConfig(level=logging.INFO)
logg = logging.getLogger()
logging.getLogger('eth_cache.store').setLevel(logging.DEBUG)
logging.getLogger('chainsyncer.driver.thread').setLevel(logging.DEBUG)
+logging.getLogger('chainsyncer.driver.head').setLevel(logging.DEBUG)
#logging.getLogger('chainsyncer.backend.memory').setLevel(logging.DEBUG)
root_dir = tempfile.mkdtemp(dir=os.path.join('/tmp/ethsync'))
@@ -52,7 +53,9 @@ backend = PointerHexDir(data_dir, 32)
backend.register_pointer('address')
store = TxFileStore(chain_spec, backend)
-rpc = EthHTTPConnection('http://localhost:8545')
+def conn_factory():
+ return EthHTTPConnection('http://localhost:8545')
+rpc = conn_factory()
#start = 8534365
start = 12423900
@@ -60,7 +63,7 @@ start = 12423900
o = block_latest()
r = rpc.do(o)
stop = int(r, 16)
-stop = start + 200
+stop = start + 50
syncer_backend = MemBackend(chain_spec, None, target_block=stop)
syncer_backend.set(start, 0)
@@ -105,13 +108,18 @@ class MonitorFilter:
def filter(self, rpc, block, tx, session=None):
- s = '{} sync block {} tx {}/{}'.format(self.name, block.number, tx.index, len(block.txs))
+ if tx == None:
+ s = '{} sync block error in tx lookup ({})'.format(self.name, block.number, len(block.txs))
+ else:
+ s = '{} sync block {} tx {}/{}'.format(self.name, block.number, tx.index, len(block.txs))
sys.stdout.write('{:<100s}\r'.format(s))
fltr = StoreFilter(store, account_registry)
-syncer = ThreadedHistorySyncer(10, syncer_backend, chain_interface)
-syncer.add_filter(MonitorFilter())
-syncer.add_filter(fltr)
-syncer.loop(0, rpc)
+if __name__ == '__main__':
+ ThreadedHistorySyncer.yield_delay = 0
+ syncer = ThreadedHistorySyncer(conn_factory, 50, syncer_backend, chain_interface)
+ syncer.add_filter(MonitorFilter())
+ syncer.add_filter(fltr)
+ syncer.loop(0, rpc)