Handle ethtester return values in historysyncer driver getter and process

This commit is contained in:
nolash 2021-04-16 15:21:26 +02:00
parent 7b3cf46732
commit 2400084251
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 24 additions and 13 deletions

View File

@ -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)
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

View File

@ -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

View File

@ -1,4 +1,4 @@
confini~=0.3.6rc3
semver==2.13.0
hexathon~=0.0.1a7
chainlib~=0.0.2a6
chainlib~=0.0.2a15

View File

@ -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