Compare commits
4 Commits
dev-0.2.4
...
dev-0.2.10
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
465d692956
|
||
|
|
81c1207828
|
||
|
|
f33ba13d74
|
||
|
|
5459d4c3f8
|
14
CHANGELOG
14
CHANGELOG
@@ -1,3 +1,17 @@
|
|||||||
|
- 0.2.10
|
||||||
|
* Upgrade shep to guarantee state lock atomicity
|
||||||
|
- 0.2.9
|
||||||
|
* Minimize instantiations of adapters in filter execution
|
||||||
|
- 0.2.8
|
||||||
|
* Upgrade chainsyncer
|
||||||
|
- 0.2.7
|
||||||
|
* Upgrade chainlib
|
||||||
|
- 0.2.6
|
||||||
|
* Deps upgrade
|
||||||
|
- 0.2.5
|
||||||
|
* Deps upgrade
|
||||||
|
- 0.2.4
|
||||||
|
* Allow omission of state store sync in queue store backend
|
||||||
- 0.2.2
|
- 0.2.2
|
||||||
* Fix missing symbol crashes related to race conditions
|
* Fix missing symbol crashes related to race conditions
|
||||||
- 0.2.1
|
- 0.2.1
|
||||||
|
|||||||
@@ -51,11 +51,11 @@ class ChaindFsAdapter(ChaindAdapter):
|
|||||||
logg.error('I am just a simple syncer and do not know how to handle the state which the tx {} is in: {}'.format(tx_hash, e))
|
logg.error('I am just a simple syncer and do not know how to handle the state which the tx {} is in: {}'.format(tx_hash, e))
|
||||||
return None
|
return None
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
logg.debug('queuestore get {} failed, possible race condition (will try again): {}'.format(tx_hash, e))
|
logg.debug('queuestore get (file missing) {} failed, possible race condition (will try again): {}'.format(tx_hash, e))
|
||||||
store_lock.again()
|
store_lock.again()
|
||||||
continue
|
continue
|
||||||
except StateLockedKey as e:
|
except StateLockedKey as e:
|
||||||
logg.debug('queuestore get {} failed, possible race condition (will try again): {}'.format(tx_hash, e))
|
logg.debug('queuestore get (statelock) {} failed, possible race condition (will try again): {}'.format(tx_hash, e))
|
||||||
store_lock.again()
|
store_lock.again()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -26,43 +26,69 @@ class StateFilter(SyncFilter):
|
|||||||
self.adapter_path = adapter_path
|
self.adapter_path = adapter_path
|
||||||
self.tx_adapter = tx_adapter
|
self.tx_adapter = tx_adapter
|
||||||
self.throttler = throttler
|
self.throttler = throttler
|
||||||
|
self.last_block_height = 0
|
||||||
|
self.adapter = None
|
||||||
|
self.store_lock = None
|
||||||
|
|
||||||
|
|
||||||
|
def __get_adapter(self, block, force_reload=False):
|
||||||
|
if self.store_lock == None:
|
||||||
|
self.store_lock = StoreLock()
|
||||||
|
|
||||||
|
reload = False
|
||||||
|
if block.number != self.last_block_height:
|
||||||
|
reload = True
|
||||||
|
elif self.adapter == None:
|
||||||
|
reload = True
|
||||||
|
elif force_reload:
|
||||||
|
reload = True
|
||||||
|
|
||||||
|
self.last_block_height = block.number
|
||||||
|
|
||||||
|
if reload:
|
||||||
|
while True:
|
||||||
|
logg.info('reloading adapter')
|
||||||
|
try:
|
||||||
|
self.adapter = ChaindFsAdapter(
|
||||||
|
self.chain_spec,
|
||||||
|
self.adapter_path,
|
||||||
|
self.tx_adapter,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
break
|
||||||
|
except BackendError as e:
|
||||||
|
logg.error('adapter instantiation failed: {}, one more try'.format(e))
|
||||||
|
self.store_lock.again()
|
||||||
|
continue
|
||||||
|
|
||||||
|
return self.adapter
|
||||||
|
|
||||||
|
|
||||||
def filter(self, conn, block, tx, session=None):
|
def filter(self, conn, block, tx, session=None):
|
||||||
cache_tx = None
|
cache_tx = None
|
||||||
store_lock = StoreLock()
|
queue_adapter = self.__get_adapter(block)
|
||||||
queue_adapter = None
|
|
||||||
|
self.store_lock.reset()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
|
||||||
queue_adapter = ChaindFsAdapter(
|
|
||||||
self.chain_spec,
|
|
||||||
self.adapter_path,
|
|
||||||
self.tx_adapter,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
except BackendError as e:
|
|
||||||
logg.error('adapter instantiation failed: {}, one more try'.format(e))
|
|
||||||
store_lock.again()
|
|
||||||
continue
|
|
||||||
|
|
||||||
store_lock.reset()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cache_tx = queue_adapter.get(tx.hash)
|
cache_tx = queue_adapter.get(tx.hash)
|
||||||
break
|
break
|
||||||
except NotLocalTxError:
|
except NotLocalTxError:
|
||||||
logg.debug('skipping not local transaction {}'.format(tx.hash))
|
logg.debug('skipping not local transaction {}'.format(tx.hash))
|
||||||
|
self.__stop_adapter()
|
||||||
return False
|
return False
|
||||||
except BackendError as e:
|
except BackendError as e:
|
||||||
logg.error('adapter instantiation failed: {}, one more try'.format(e))
|
logg.error('adapter get failed: {}, one more try'.format(e))
|
||||||
queue_adapter = None
|
self.store_lock.again()
|
||||||
store_lock.again()
|
queue_adapter = self.__get_adapter(block, force_reload=True)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if cache_tx == None:
|
if cache_tx == None:
|
||||||
raise NotLocalTxError(tx.hash)
|
raise NotLocalTxError(tx.hash)
|
||||||
|
|
||||||
store_lock = StoreLock()
|
self.store_lock.reset()
|
||||||
|
|
||||||
queue_lock = StoreLock(error=QueueLockError)
|
queue_lock = StoreLock(error=QueueLockError)
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@@ -76,15 +102,18 @@ class StateFilter(SyncFilter):
|
|||||||
queue_lock.again()
|
queue_lock.again()
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
logg.debug('queue item {} not found, possible race condition, will retry: {}'.format(tx.hash, e))
|
logg.debug('queue item {} not found, possible race condition, will retry: {}'.format(tx.hash, e))
|
||||||
store_lock.again()
|
self.store_lock.again()
|
||||||
|
queue_adapter = self.__get_adapter(block, force_reload=True)
|
||||||
continue
|
continue
|
||||||
except NotLocalTxError as e:
|
except NotLocalTxError as e:
|
||||||
logg.debug('queue item {} not found, possible race condition, will retry: {}'.format(tx.hash, e))
|
logg.debug('queue item {} not found, possible race condition, will retry: {}'.format(tx.hash, e))
|
||||||
store_lock.again()
|
self.store_lock.again()
|
||||||
|
queue_adapter = self.__get_adapter(block, force_reload=True)
|
||||||
continue
|
continue
|
||||||
except StateLockedKey as e:
|
except StateLockedKey as e:
|
||||||
logg.debug('queue item {} not found, possible race condition, will retry: {}'.format(tx.hash, e))
|
logg.debug('queue item {} not found, possible race condition, will retry: {}'.format(tx.hash, e))
|
||||||
store_lock.again()
|
self.store_lock.again()
|
||||||
|
queue_adapter = self.__get_adapter(block, force_reload=True)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
logg.info('filter registered {} for {} in {}'.format(tx.status.name, tx.hash, block))
|
logg.info('filter registered {} for {} in {}'.format(tx.status.name, tx.hash, block))
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import time
|
|||||||
from .error import BackendError
|
from .error import BackendError
|
||||||
|
|
||||||
BASE_DELAY = 0.01
|
BASE_DELAY = 0.01
|
||||||
BASE_DELAY_LIMIT = 3.0
|
BASE_DELAY_LIMIT = 10.0
|
||||||
|
|
||||||
|
|
||||||
class StoreLock:
|
class StoreLock:
|
||||||
|
|||||||
@@ -39,3 +39,9 @@ class MockTx:
|
|||||||
def __init__(self, tx_hash, status=TxStatus.SUCCESS):
|
def __init__(self, tx_hash, status=TxStatus.SUCCESS):
|
||||||
self.hash = tx_hash
|
self.hash = tx_hash
|
||||||
self.status = status
|
self.status = status
|
||||||
|
|
||||||
|
|
||||||
|
class MockBlock:
|
||||||
|
|
||||||
|
def __init__(self, number):
|
||||||
|
self.number = number
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
chainlib~=0.1.1
|
chainlib~=0.1.2
|
||||||
chainqueue~=0.1.10
|
chainqueue~=0.1.13
|
||||||
chainsyncer~=0.4.3
|
chainsyncer~=0.4.5
|
||||||
confini~=0.6.0
|
confini~=0.6.0
|
||||||
funga~=0.5.2
|
funga~=0.5.2
|
||||||
pyxdg~=0.26
|
pyxdg~=0.26
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = chaind
|
name = chaind
|
||||||
version = 0.2.4
|
version = 0.2.10
|
||||||
description = Base package for chain queue service
|
description = Base package for chain queue service
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from chaind.filter import StateFilter
|
|||||||
# test imports
|
# test imports
|
||||||
from chaind.unittest.common import (
|
from chaind.unittest.common import (
|
||||||
MockTx,
|
MockTx,
|
||||||
|
MockBlock,
|
||||||
MockCacheAdapter,
|
MockCacheAdapter,
|
||||||
MockDispatcher,
|
MockDispatcher,
|
||||||
)
|
)
|
||||||
@@ -76,7 +77,8 @@ class TestChaindFs(TestChaindFsBase):
|
|||||||
|
|
||||||
fltr = StateFilter(self.chain_spec, self.path, MockCacheAdapter)
|
fltr = StateFilter(self.chain_spec, self.path, MockCacheAdapter)
|
||||||
tx = MockTx(hsh)
|
tx = MockTx(hsh)
|
||||||
fltr.filter(None, None, tx)
|
block = MockBlock(42)
|
||||||
|
fltr.filter(None, block, tx)
|
||||||
|
|
||||||
|
|
||||||
def test_fs_filter_fail(self):
|
def test_fs_filter_fail(self):
|
||||||
@@ -87,7 +89,8 @@ class TestChaindFs(TestChaindFsBase):
|
|||||||
|
|
||||||
fltr = StateFilter(self.chain_spec, self.path, MockCacheAdapter)
|
fltr = StateFilter(self.chain_spec, self.path, MockCacheAdapter)
|
||||||
tx = MockTx(hsh, TxStatus.ERROR)
|
tx = MockTx(hsh, TxStatus.ERROR)
|
||||||
fltr.filter(None, None, tx)
|
block = MockBlock(42)
|
||||||
|
fltr.filter(None, block, tx)
|
||||||
|
|
||||||
|
|
||||||
def test_upcoming(self):
|
def test_upcoming(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user