commit 7ff4e8faa087dbcb3a1d91fb2fb5b8cad83785e5
parent 5f2809c39417104f18049136b10b0ff51b992175
Author: lash <dev@holbrook.no>
Date: Sat, 19 Mar 2022 00:59:55 +0000
Add target serialization to first state
Diffstat:
2 files changed, 7 insertions(+), 13 deletions(-)
diff --git a/chainsyncer/store/fs.py b/chainsyncer/store/fs.py
@@ -32,8 +32,8 @@ class SyncFsItem:
logg.debug('get key {}'.format(self.state_key))
v = self.sync_state.get(self.state_key)
- self.cursor = int.from_bytes(v[:4], 'big')
- self.tx_cursor = int.from_bytes(v[4:], 'big')
+
+ (self.cursor, self.tx_cursor, self.target) = sync_state_deserialize(v)
if self.filter_state.state(self.state_key) & self.filter_state.from_name('LOCK') and not ignore_invalid:
raise LockError(s)
@@ -244,17 +244,13 @@ class SyncFsStore:
self.__load(target)
if self.first:
- block_number = offset
- state_bytes = block_number.to_bytes(4, 'big')
- tx_index = 0
- state_bytes += tx_index.to_bytes(4, 'big')
- block_number_str = str(block_number)
+ state_bytes = sync_state_serialize(offset, 0, target)
+ block_number_str = str(offset)
self.state.put(block_number_str, state_bytes)
self.filter_state.put(block_number_str)
- o = SyncFsItem(block_number, target, self.state, self.filter_state)
- self.items[block_number] = o
- self.item_keys.append(block_number)
- logg.debug('added first {}'.format(o))
+ o = SyncFsItem(offset, target, self.state, self.filter_state)
+ self.items[offset] = o
+ self.item_keys.append(offset)
elif offset > 0:
logg.warning('block number argument {} for start ignored for already initiated sync {}'.format(offset, self.session_id))
self.started = True
diff --git a/tests/test_fs.py b/tests/test_fs.py
@@ -193,13 +193,11 @@ class TestFs(unittest.TestCase):
session = SyncSession(store)
session.start()
- logg.debug('list {} {} {}'.format(store.state.list(store.state.SYNC), store.state.list(store.state.DONE), store.state.list(store.state.NEW)))
o = session.get(0)
o.next(advance_block=True)
o.next(advance_block=True)
session.stop(o)
- logg.debug('list {} {} {}'.format(store.state.list(store.state.SYNC), store.state.list(store.state.DONE), store.state.list(store.state.NEW)))
store = SyncFsStore(self.path, session_id='foo')
store.start()
o = store.get(2)