From 7d5f2d9b4ee3d05c533eac56092ced0c55063c47 Mon Sep 17 00:00:00 2001 From: lash Date: Tue, 26 Apr 2022 08:32:56 +0000 Subject: [PATCH] Add memory state store --- CHANGELOG | 2 ++ eth_monitor/data/config/syncer.ini | 2 +- eth_monitor/runnable/sync.py | 29 +++++++++++++++++++---------- requirements.txt | 2 +- setup.cfg | 2 +- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3cc77b0..35b3f52 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +- 0.4.2 + * Implement non-persistent (in-memory) sync state - 0.4.1 * Correct too restrictive python version constraint - 0.4.0 diff --git a/eth_monitor/data/config/syncer.ini b/eth_monitor/data/config/syncer.ini index e0fbf04..2a27f58 100644 --- a/eth_monitor/data/config/syncer.ini +++ b/eth_monitor/data/config/syncer.ini @@ -1,3 +1,3 @@ [syncer] loop_interval = 5 -backend = fs +backend = mem diff --git a/eth_monitor/runnable/sync.py b/eth_monitor/runnable/sync.py index 778de15..6c96097 100644 --- a/eth_monitor/runnable/sync.py +++ b/eth_monitor/runnable/sync.py @@ -95,6 +95,7 @@ if args.list_backends: for v in [ 'fs', 'rocksdb', + 'mem', ]: print(v) sys.exit(0) @@ -396,20 +397,28 @@ def main(): syncer_store_module = None syncer_store_class = None - if config.get('SYNCER_BACKEND') == 'fs': - syncer_store_module = importlib.import_module('chainsyncer.store.fs') - syncer_store_class = getattr(syncer_store_module, 'SyncFsStore') - elif config.get('SYNCER_BACKEND') == 'rocksdb': - syncer_store_module = importlib.import_module('chainsyncer.store.rocksdb') - syncer_store_class = getattr(syncer_store_module, 'SyncRocksDbStore') + state_dir = None + if config.get('SYNCER_BACKEND') == 'mem': + syncer_store_module = importlib.import_module('chainsyncer.store.mem') + syncer_store_class = getattr(syncer_store_module, 'SyncMemStore') else: - syncer_store_module = importlib.import_module(config.get('SYNCER_BACKEND')) - syncer_store_class = getattr(syncer_store_module, 'SyncStore') + if config.get('SYNCER_BACKEND') == 'fs': + syncer_store_module = importlib.import_module('chainsyncer.store.fs') + syncer_store_class = getattr(syncer_store_module, 'SyncFsStore') + elif config.get('SYNCER_BACKEND') == 'rocksdb': + syncer_store_module = importlib.import_module('chainsyncer.store.rocksdb') + syncer_store_class = getattr(syncer_store_module, 'SyncRocksDbStore') + else: + syncer_store_module = importlib.import_module(config.get('SYNCER_BACKEND')) + syncer_store_class = getattr(syncer_store_module, 'SyncStore') + state_dir = os.path.join(config.get('_STATE_DIR'), config.get('SYNCER_BACKEND')) logg.info('using engine {} moduleĀ {}.{}'.format(config.get('SYNCER_BACKEND'), syncer_store_module.__file__, syncer_store_class.__name__)) - state_dir = os.path.join(config.get('_STATE_DIR'), config.get('SYNCER_BACKEND')) - sync_store = syncer_store_class(state_dir, session_id=config.get('_SESSION_ID'), state_event_callback=state_change_callback, filter_state_event_callback=filter_change_callback) + if state_dir == None: + sync_store = syncer_store_class(session_id=config.get('_SESSION_ID'), state_event_callback=state_change_callback, filter_state_event_callback=filter_change_callback) + else: + sync_store = syncer_store_class(state_dir, session_id=config.get('_SESSION_ID'), state_event_callback=state_change_callback, filter_state_event_callback=filter_change_callback) logg.info('session is {}'.format(sync_store.session_id)) for fltr in filters: diff --git a/requirements.txt b/requirements.txt index fd6b644..9f18757 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ chainlib-eth>=0.1.0b4,<0.2.0 chainlib>=0.1.0b1,<0.2.0 -chainsyncer~=0.3.2 +chainsyncer~=0.3.5 eth-erc20~=0.2.0 leveldir~=0.3.0 eth-cache~=0.1.0 diff --git a/setup.cfg b/setup.cfg index 65efed4..5466bc8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = eth-monitor -version = 0.4.1 +version = 0.4.2 description = Monitor and cache transactions using match filters author = Louis Holbrook author_email = dev@holbrook.no