2022-04-21 00:41:19 +02:00
|
|
|
|
# standard imports
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
# external imports
|
|
|
|
|
from hexathon import (
|
|
|
|
|
add_0x,
|
|
|
|
|
strip_0x,
|
|
|
|
|
)
|
|
|
|
|
from chainlib.eth.tx import unpack
|
|
|
|
|
from chainqueue.db.enum import StatusBits
|
2022-04-23 11:58:17 +02:00
|
|
|
|
#from chainqueue.db.models.tx import TxCache
|
|
|
|
|
#from chainqueue.db.models.otx import Otx
|
2022-04-21 00:41:19 +02:00
|
|
|
|
from chainlib.eth.address import to_checksum_address
|
2022-04-23 11:58:17 +02:00
|
|
|
|
#from cic_eth.db.models.base import SessionBase
|
|
|
|
|
from cic_eth.queue.query import get_account_tx_local
|
2022-04-21 00:41:19 +02:00
|
|
|
|
from cic_eth.eth.gas import create_check_gas_task
|
|
|
|
|
from cic_eth.queue.query import get_paused_tx
|
2022-04-23 11:58:17 +02:00
|
|
|
|
|
|
|
|
|
# local imports
|
2022-04-21 00:41:19 +02:00
|
|
|
|
from cic_eth.encode import tx_normalize
|
|
|
|
|
from .base import SyncFilter
|
|
|
|
|
|
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GasFilter(SyncFilter):
|
|
|
|
|
|
2022-04-23 11:58:17 +02:00
|
|
|
|
def filter(self, conn, block, tx):
|
|
|
|
|
super(GasFilter, self).filter(conn, block, tx)
|
2022-04-21 00:41:19 +02:00
|
|
|
|
if tx.value > 0 or len(tx.payload) == 0:
|
|
|
|
|
tx_hash_hex = add_0x(tx.hash)
|
|
|
|
|
|
|
|
|
|
sender_target = tx_normalize.wallet_address(tx.inputs[0])
|
2022-04-23 11:58:17 +02:00
|
|
|
|
txc = get_account_tx_local(self.chain_spec, sender_target, as_recipient=False)
|
2022-04-21 00:41:19 +02:00
|
|
|
|
|
|
|
|
|
logline = None
|
2022-04-23 11:58:17 +02:00
|
|
|
|
if len(txc) == 0:
|
|
|
|
|
logline = 'unsolicited gas refill tx {}; cannot find {} among senders'.format(tx_hash_hex, sender_target)
|
2022-04-21 00:41:19 +02:00
|
|
|
|
logline = self.to_logline(block, tx, logline)
|
|
|
|
|
logg.info(logline)
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
self.register_match()
|
|
|
|
|
|
2022-04-23 11:58:17 +02:00
|
|
|
|
txs = get_paused_tx(self.chain_spec, status=StatusBits.GAS_ISSUES, sender=sender_target, decoder=unpack)
|
2022-04-21 00:41:19 +02:00
|
|
|
|
|
|
|
|
|
t = None
|
|
|
|
|
address = to_checksum_address(sender_target)
|
|
|
|
|
if len(txs) > 0:
|
|
|
|
|
s = create_check_gas_task(
|
|
|
|
|
list(txs.values()),
|
|
|
|
|
self.chain_spec,
|
|
|
|
|
address,
|
|
|
|
|
0,
|
|
|
|
|
tx_hashes_hex=list(txs.keys()),
|
|
|
|
|
queue=self.queue,
|
|
|
|
|
)
|
|
|
|
|
t = s.apply_async()
|
|
|
|
|
logline = 'resuming {} gas-in-waiting txs for {}'.format(len(txs), sender_target)
|
|
|
|
|
else:
|
|
|
|
|
logline = 'gas refill tx {}'.format(tx)
|
|
|
|
|
|
|
|
|
|
logline = self.to_logline(block, tx, logline)
|
|
|
|
|
logg.info(logline)
|
|
|
|
|
return t
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
return 'gasfilter'
|