commit 2400084251f97ec739d65f81043b2d19f1f18ccf
parent 7b3cf4673284801970c4fd17ce5ece5286313990
Author: nolash <dev@holbrook.no>
Date: Fri, 16 Apr 2021 15:21:26 +0200
Handle ethtester return values in historysyncer driver getter and process
Diffstat:
4 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/chainsyncer/driver.py b/chainsyncer/driver.py
@@ -3,14 +3,19 @@ import uuid
import logging
import time
import signal
+import json
# external imports
-import sqlalchemy
from chainlib.eth.block import (
block_by_number,
Block,
)
-from chainlib.eth.tx import receipt
+from chainlib.eth.tx import (
+ receipt,
+ transaction,
+ Tx,
+ )
+from chainlib.error import JSONRPCException
# local imports
from chainsyncer.filter import SyncFilter
@@ -129,13 +134,19 @@ class HeadSyncer(BlockPollSyncer):
while True:
try:
tx = block.tx(i)
+ except AttributeError:
+ o = transaction(block.txs[i])
+ r = conn.do(o)
+ tx = Tx(Tx.src_normalize(r), block=block)
except IndexError as e:
logg.debug('index error syncer rcpt get {}'.format(e))
self.backend.set(block.number + 1, 0)
break
+ # TODO: Move specifics to eth subpackage, receipts are not a global concept
rcpt = conn.do(receipt(tx.hash))
- tx.apply_receipt(rcpt)
+ if rcpt != None:
+ tx.apply_receipt(Tx.src_normalize(rcpt))
self.process_single(conn, block, tx)
self.backend.reset_filter()
@@ -180,9 +191,13 @@ class HistorySyncer(HeadSyncer):
block_number = height[0]
block_hash = []
o = block_by_number(block_number)
- r = conn.do(o)
+ try:
+ r = conn.do(o)
+ # TODO: Disambiguate whether error is temporary or permanent, if permanent, SyncDone should be raised, because a historical sync is attempted into the future
+ except JSONRPCException:
+ r = None
if r == None:
- raise NoBlockForYou()
+ raise SyncDone() #NoBlockForYou()
b = Block(r)
return b
diff --git a/chainsyncer/filter.py b/chainsyncer/filter.py
@@ -1,9 +1,6 @@
# standard imports
import logging
-# external imports
-import sqlalchemy
-
# local imports
from .error import BackendError
@@ -12,8 +9,7 @@ logg = logging.getLogger(__name__)
class SyncFilter:
- def __init__(self, backend, safe=True):
- self.safe = safe
+ def __init__(self, backend):
self.filters = []
self.backend = backend
@@ -30,7 +26,7 @@ class SyncFilter:
session = None
try:
session = self.backend.connect()
- except sqlalchemy.exc.TimeoutError as e:
+ except TimeoutError as e:
self.backend.disconnect()
raise BackendError('database connection fail: {}'.format(e))
i = 0
diff --git a/requirements.txt b/requirements.txt
@@ -1,4 +1,4 @@
confini~=0.3.6rc3
semver==2.13.0
hexathon~=0.0.1a7
-chainlib~=0.0.2a6
+chainlib~=0.0.2a15
diff --git a/setup.cfg b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = chainsyncer
-version = 0.0.2a2
+version = 0.0.2a3
description = Generic blockchain syncer driver
author = Louis Holbrook
author_email = dev@holbrook.no