chainsyncer

Blockchain syncer driver
Log | Files | Refs | LICENSE

commit 78bd6ca538d6e20e29ac7bb254c92701133e063a
parent 18f16d878f3cbecc5305b062fde02eba4eca07f2
Author: lash <dev@holbrook.no>
Date:   Fri, 18 Mar 2022 00:02:18 +0000

Move filter registration to session store

Diffstat:
Mchainsyncer/session.py | 11++++++-----
Mchainsyncer/state/base.py | 4++++
Mchainsyncer/store/fs.py | 7++++++-
Mtests/test_filter.py | 8++++----
Mtests/test_fs.py | 16++++++++--------
Mtests/test_session.py | 2+-
6 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/chainsyncer/session.py b/chainsyncer/session.py @@ -14,13 +14,14 @@ class SyncSession: self.get = self.session_store.get self.next = self.session_store.next_item self.item = None + self.filters = self.session_store.filters - def register(self, fltr): - if self.started: - raise RuntimeError('filters cannot be changed after syncer start') - self.session_store.register(fltr) - self.filters.append(fltr) +# def register(self, fltr): +# if self.started: +# raise RuntimeError('filters cannot be changed after syncer start') +# self.session_store.register(fltr) +# self.filters.append(fltr) def start(self, offset=0, target=-1): diff --git a/chainsyncer/state/base.py b/chainsyncer/state/base.py @@ -84,3 +84,7 @@ class SyncState: def next_item(self): return None + + + def filters(self): + return [] diff --git a/chainsyncer/store/fs.py b/chainsyncer/store/fs.py @@ -151,9 +151,14 @@ class SyncFsStore: factory = SimpleFileStoreFactory(base_filter_path, binary=True) filter_state_backend = PersistedState(factory.add, 0, check_alias=False) self.filter_state = SyncState(filter_state_backend) - self.register = self.filter_state.register + self.filters = [] + def register(self, fltr): + self.filters.append(fltr) + self.filter_state.register(fltr) + + def __create_path(self, base_path, default_path, session_id=None): logg.debug('fs store path {} does not exist, creating'.format(self.session_path)) if session_id == None: diff --git a/tests/test_filter.py b/tests/test_filter.py @@ -41,9 +41,9 @@ class TestFilter(unittest.TestCase): def test_filter_basic(self): fltr_one = MockFilter('foo') - self.session.register(fltr_one) + self.store.register(fltr_one) fltr_two = MockFilter('bar') - self.session.register(fltr_two) + self.store.register(fltr_two) tx_hash = os.urandom(32).hex() tx = MockTx(42, tx_hash) @@ -57,9 +57,9 @@ class TestFilter(unittest.TestCase): def test_filter_interrupt(self): fltr_one = MockFilter('foo', brk=True) - self.session.register(fltr_one) + self.store.register(fltr_one) fltr_two = MockFilter('bar') - self.session.register(fltr_two) + self.store.register(fltr_two) tx_hash = os.urandom(32).hex() tx = MockTx(42, tx_hash) diff --git a/tests/test_fs.py b/tests/test_fs.py @@ -95,7 +95,7 @@ class TestFs(unittest.TestCase): session = SyncSession(store) fltr_one = MockFilter('foo') - session.register(fltr_one) + store.register(fltr_one) session.start() o = session.get(0) @@ -108,9 +108,9 @@ class TestFs(unittest.TestCase): session = SyncSession(store) fltr_one = MockFilter('foo') - session.register(fltr_one) + store.register(fltr_one) fltr_two = MockFilter('two') - session.register(fltr_two) + store.register(fltr_two) session.start() o = session.get(0) @@ -131,9 +131,9 @@ class TestFs(unittest.TestCase): session = SyncSession(store) fltr_one = MockFilter('foo') - session.register(fltr_one) + store.register(fltr_one) fltr_two = MockFilter('bar') - session.register(fltr_two) + store.register(fltr_two) session.start() o = session.get(0) @@ -148,9 +148,9 @@ class TestFs(unittest.TestCase): session = SyncSession(store) fltr_one = MockFilter('foo') - session.register(fltr_one) + store.register(fltr_one) fltr_two = MockFilter('bar') - session.register(fltr_two) + store.register(fltr_two) session.start() o = session.get(0) @@ -175,7 +175,7 @@ class TestFs(unittest.TestCase): session = SyncSession(store) fltr_one = MockFilter('foo') - session.register(fltr_one) + store.register(fltr_one) session.start(target=0) o = session.get(0) diff --git a/tests/test_session.py b/tests/test_session.py @@ -43,7 +43,7 @@ class TestFilter(unittest.TestCase): session = SyncSession(self.store) session.start(target=1) fltr_one = MockFilter('foo') - session.register(fltr_one) + self.store.register(fltr_one) tx_hash = os.urandom(32).hex() tx = MockTx(42, tx_hash)