2021-02-17 09:19:42 +01:00
|
|
|
# standard imports
|
|
|
|
import logging
|
|
|
|
|
|
|
|
# third-party imports
|
|
|
|
from cic_registry.chain import ChainSpec
|
2021-03-01 21:15:17 +01:00
|
|
|
from hexathon import add_0x
|
2021-02-17 09:19:42 +01:00
|
|
|
|
|
|
|
# local imports
|
2021-02-21 16:41:37 +01:00
|
|
|
from cic_eth.db.enum import StatusBits
|
2021-02-17 09:19:42 +01:00
|
|
|
from cic_eth.db.models.base import SessionBase
|
|
|
|
from cic_eth.db.models.tx import TxCache
|
2021-02-21 16:41:37 +01:00
|
|
|
from cic_eth.db.models.otx import Otx
|
2021-02-17 09:19:42 +01:00
|
|
|
from cic_eth.queue.tx import get_paused_txs
|
|
|
|
from cic_eth.eth.task import create_check_gas_and_send_task
|
|
|
|
from .base import SyncFilter
|
|
|
|
|
2021-03-01 21:15:17 +01:00
|
|
|
logg = logging.getLogger(__name__)
|
2021-02-17 09:19:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
class GasFilter(SyncFilter):
|
|
|
|
|
2021-03-01 21:15:17 +01:00
|
|
|
def __init__(self, chain_spec, queue=None):
|
2021-02-19 08:06:05 +01:00
|
|
|
self.queue = queue
|
2021-03-01 21:15:17 +01:00
|
|
|
self.chain_spec = chain_spec
|
2021-02-17 09:19:42 +01:00
|
|
|
|
|
|
|
|
2021-03-01 21:15:17 +01:00
|
|
|
def filter(self, conn, block, tx, session): #rcpt, chain_str, session=None):
|
|
|
|
tx_hash_hex = add_0x(tx.hash)
|
|
|
|
if tx.value > 0:
|
2021-02-17 09:19:42 +01:00
|
|
|
logg.debug('gas refill tx {}'.format(tx_hash_hex))
|
2021-02-19 08:06:05 +01:00
|
|
|
session = SessionBase.bind_session(session)
|
2021-02-17 09:19:42 +01:00
|
|
|
q = session.query(TxCache.recipient)
|
|
|
|
q = q.join(Otx)
|
|
|
|
q = q.filter(Otx.tx_hash==tx_hash_hex)
|
|
|
|
r = q.first()
|
|
|
|
|
|
|
|
if r == None:
|
2021-03-01 21:15:17 +01:00
|
|
|
logg.debug('unsolicited gas refill tx {}'.format(tx_hash_hex))
|
2021-02-19 08:06:05 +01:00
|
|
|
SessionBase.release_session(session)
|
2021-02-17 09:19:42 +01:00
|
|
|
return
|
|
|
|
|
2021-03-01 21:15:17 +01:00
|
|
|
txs = get_paused_txs(StatusBits.GAS_ISSUES, r[0], self.chain_spec.chain_id(), session=session)
|
2021-02-19 08:06:05 +01:00
|
|
|
|
|
|
|
SessionBase.release_session(session)
|
2021-02-17 09:19:42 +01:00
|
|
|
|
2021-03-01 21:15:17 +01:00
|
|
|
logg.info('resuming gas-in-waiting txs for {}'.format(r[0]))
|
2021-02-17 09:19:42 +01:00
|
|
|
if len(txs) > 0:
|
|
|
|
s = create_check_gas_and_send_task(
|
|
|
|
list(txs.values()),
|
2021-03-01 21:15:17 +01:00
|
|
|
str(self.chain_spec),
|
2021-02-17 09:19:42 +01:00
|
|
|
r[0],
|
|
|
|
0,
|
|
|
|
tx_hashes_hex=list(txs.keys()),
|
2021-02-19 08:06:05 +01:00
|
|
|
queue=self.queue,
|
2021-02-17 09:19:42 +01:00
|
|
|
)
|
|
|
|
s.apply_async()
|
2021-03-01 21:15:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return 'eic-eth gasfilter'
|