Fix last(?) leak in syncer

Signed-off-by: nolash <dev@holbrook.no>
This commit is contained in:
Louis Holbrook
2021-02-19 07:06:05 +00:00
parent 2657ed58d3
commit fe499de1e4
16 changed files with 116 additions and 77 deletions

View File

@@ -37,7 +37,7 @@ class CallbackFilter(SyncFilter):
transfer_type,
int(rcpt.status == 0),
],
queue=tc.queue,
queue=self.queue,
)
# s_translate = celery.signature(
# 'cic_eth.ext.address.translate',
@@ -82,7 +82,7 @@ class CallbackFilter(SyncFilter):
return (transfer_type, transfer_data)
def filter(self, w3, tx, rcpt, chain_spec):
def filter(self, w3, tx, rcpt, chain_spec, session=None):
logg.debug('applying callback filter "{}:{}"'.format(self.queue, self.method))
chain_str = str(chain_spec)

View File

@@ -17,29 +17,31 @@ logg = logging.getLogger()
class GasFilter(SyncFilter):
def __init__(self, gas_provider):
def __init__(self, gas_provider, queue=None):
self.queue = queue
self.gas_provider = gas_provider
def filter(self, w3, tx, rcpt, chain_str):
def filter(self, w3, tx, rcpt, chain_str, session=None):
logg.debug('applying gas filter')
tx_hash_hex = tx.hash.hex()
if tx['value'] > 0:
logg.debug('gas refill tx {}'.format(tx_hash_hex))
session = SessionBase.create_session()
session = SessionBase.bind_session(session)
q = session.query(TxCache.recipient)
q = q.join(Otx)
q = q.filter(Otx.tx_hash==tx_hash_hex)
r = q.first()
session.close()
if r == None:
logg.warning('unsolicited gas refill tx {}'.format(tx_hash_hex))
SessionBase.release_session(session)
return
chain_spec = ChainSpec.from_chain_str(chain_str)
txs = get_paused_txs(StatusEnum.WAITFORGAS, r[0], chain_spec.chain_id())
txs = get_paused_txs(StatusEnum.WAITFORGAS, r[0], chain_spec.chain_id(), session=session)
SessionBase.release_session(session)
if len(txs) > 0:
logg.info('resuming gas-in-waiting txs for {}: {}'.format(r[0], txs.keys()))
@@ -49,6 +51,6 @@ class GasFilter(SyncFilter):
r[0],
0,
tx_hashes_hex=list(txs.keys()),
queue=queue,
queue=self.queue,
)
s.apply_async()

View File

@@ -15,7 +15,7 @@ account_registry_add_log_hash = '0x5ed3bdd47b9af629827a8d129aa39c870b10c03f0153f
class RegistrationFilter(SyncFilter):
def filter(self, w3, tx, rcpt, chain_spec):
def filter(self, w3, tx, rcpt, chain_spec, session=None):
logg.debug('applying registration filter')
registered_address = None
for l in rcpt['logs']:

View File

@@ -6,6 +6,7 @@ import celery
# local imports
from cic_eth.db.models.otx import Otx
from cic_eth.db.models.base import SessionBase
from .base import SyncFilter
logg = logging.getLogger()
@@ -17,15 +18,17 @@ class TxFilter(SyncFilter):
self.queue = queue
def filter(self, w3, tx, rcpt, chain_spec):
def filter(self, w3, tx, rcpt, chain_spec, session=None):
session = SessionBase.bind_session(session)
logg.debug('applying tx filter')
tx_hash_hex = tx.hash.hex()
otx = Otx.load(tx_hash_hex)
otx = Otx.load(tx_hash_hex, session=session)
SessionBase.release_session(session)
if otx == None:
logg.debug('tx {} not found locally, skipping'.format(tx_hash_hex))
return None
logg.info('otx found {}'.format(otx.tx_hash))
s = celery.siignature(
s = celery.signature(
'cic_eth.queue.tx.set_final_status',
[
tx_hash_hex,

View File

@@ -118,7 +118,7 @@ declarator = CICRegistry.get_contract(chain_spec, 'AddressDeclarator', interface
dsn = dsn_from_config(config)
SessionBase.connect(dsn)
SessionBase.connect(dsn, pool_size=1, debug=config.true('DATABASE_DEBUG'))
def main():
@@ -180,7 +180,7 @@ def main():
registration_filter = RegistrationFilter()
gas_filter = GasFilter(c.gas_provider())
gas_filter = GasFilter(c.gas_provider(), queue)
i = 0
for syncer in syncers:

View File

@@ -78,7 +78,7 @@ logg.debug('config loaded from {}:\n{}'.format(args.c, config))
# connect to database
dsn = dsn_from_config(config)
SessionBase.connect(dsn)
SessionBase.connect(dsn, pool_size=8, debug=config.true('DATABASE_DEBUG'))
# verify database connection with minimal sanity query
session = SessionBase.create_session()
@@ -179,7 +179,6 @@ def web3ext_constructor():
return (blockchain_provider, w3)
RpcClient.set_constructor(web3ext_constructor)
logg.info('ccc {}'.format(config.store['TASKS_TRACE_QUEUE_STATUS']))
Otx.tracing = config.true('TASKS_TRACE_QUEUE_STATUS')