2022-04-21 00:41:19 +02:00
|
|
|
|
# standard imports
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
# external imports
|
|
|
|
|
import celery
|
|
|
|
|
from chainqueue.error import TxStateChangeError
|
|
|
|
|
from hexathon import to_int as hex_to_int
|
|
|
|
|
from chainlib.eth.gas import balance
|
2022-04-23 12:28:22 +02:00
|
|
|
|
from cic_eth.queue.query import get_tx_cache_local
|
2022-04-23 13:29:35 +02:00
|
|
|
|
from cic_eth.queue.state import (
|
|
|
|
|
obsolete_local,
|
|
|
|
|
set_fubar_local,
|
|
|
|
|
)
|
2022-04-21 00:41:19 +02:00
|
|
|
|
from chainqueue.enum import StatusBits
|
|
|
|
|
|
2022-04-23 09:09:48 +02:00
|
|
|
|
# local imports
|
|
|
|
|
from .base import SyncFilter
|
2022-04-21 00:41:19 +02:00
|
|
|
|
|
2022-04-23 09:09:48 +02:00
|
|
|
|
logg = logging.getLogger()
|
2022-04-21 00:41:19 +02:00
|
|
|
|
|
|
|
|
|
|
2022-04-23 09:09:48 +02:00
|
|
|
|
class StragglerFilter(SyncFilter):
|
2022-04-21 00:41:19 +02:00
|
|
|
|
|
2022-04-23 09:09:48 +02:00
|
|
|
|
gas_balance_threshold = 0
|
2022-04-21 00:41:19 +02:00
|
|
|
|
|
2022-04-23 11:58:17 +02:00
|
|
|
|
def filter(self, conn, block, tx):
|
2022-04-23 12:28:22 +02:00
|
|
|
|
txc = get_tx_cache_local(self.chain_spec, tx.hash)
|
2022-04-21 00:41:19 +02:00
|
|
|
|
if txc['status_code'] & StatusBits.GAS_ISSUES > 0:
|
|
|
|
|
o = balance(tx.outputs[0])
|
|
|
|
|
r = conn.do(o)
|
|
|
|
|
gas_balance = hex_to_int(r)
|
|
|
|
|
|
|
|
|
|
t = None
|
|
|
|
|
if gas_balance < self.gas_balance_threshold:
|
|
|
|
|
logg.debug('WAITFORGAS tx ignored since gas balance {} is below threshold {}'.format(gas_balance, self.gas_balance_threshold))
|
|
|
|
|
s_touch = celery.signature(
|
|
|
|
|
'cic_eth.queue.state.set_checked',
|
|
|
|
|
[
|
|
|
|
|
self.chain_spec.asdict(),
|
|
|
|
|
tx.hash,
|
|
|
|
|
],
|
|
|
|
|
queue=self.queue,
|
|
|
|
|
)
|
|
|
|
|
t = s_touch.apply_async()
|
|
|
|
|
return t
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
2022-04-23 13:29:35 +02:00
|
|
|
|
obsolete_local(self.chain_spec, tx.hash, False)
|
2022-04-21 00:41:19 +02:00
|
|
|
|
except TxStateChangeError:
|
2022-04-23 13:29:35 +02:00
|
|
|
|
set_fubar_local(self.chain_spec, tx.hash, session=db_session)
|
2022-04-21 00:41:19 +02:00
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
s_send = celery.signature(
|
|
|
|
|
'cic_eth.eth.gas.resend_with_higher_gas',
|
|
|
|
|
[
|
|
|
|
|
tx.hash,
|
|
|
|
|
self.chain_spec.asdict(),
|
|
|
|
|
],
|
|
|
|
|
queue=self.queue,
|
|
|
|
|
)
|
|
|
|
|
t = s_send.apply_async()
|
|
|
|
|
return t
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
return 'stragglerfilter'
|