Skip not local transaction in sync

This commit is contained in:
lash 2022-04-10 16:21:52 +00:00
parent 8c2905b801
commit d0dbaad1f2
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
1 changed files with 14 additions and 2 deletions

View File

@ -1,8 +1,14 @@
# standard imports
import logging
# external imports
from chainlib.status import Status as TxStatus
from chainsyncer.filter import SyncFilter
from chainqueue.error import NotLocalTxError
logg = logging.getLogger(__name__)
class StateFilter:
class StateFilter(SyncFilter):
def __init__(self, adapter, throttler=None):
self.adapter = adapter
@ -10,10 +16,16 @@ class StateFilter:
def filter(self, conn, block, tx, session=None):
cache_tx = self.adapter.get(tx.hash)
try:
cache_tx = self.adapter.get(tx.hash)
except NotLocalTxError:
logg.debug('skipping not local transaction {}'.format(tx.hash))
return False
if tx.status == TxStatus.SUCCESS:
self.adapter.succeed(block, tx)
else:
self.adapter.fail(block, tx)
if self.throttler != None:
self.throttler.dec(tx.hash)
return False