Skip to content

Commit

Permalink
Add new status metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
badrogger committed Apr 25, 2024
1 parent 276b22d commit 70b1bfb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 4 additions & 0 deletions transaction_manager/attempt_manager/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
MIN_PRIORITY_FEE
)
from ..eth import Eth
from ..resources import stdc
from ..structures import Attempt, Fee, Tx

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -165,8 +166,11 @@ def make(self, tx: Tx) -> None:
last.fee.max_fee_per_gas, # type: ignore
min_fee=estimated_base_fee
)
stdc.gauge('tm.max_priority_fee', tip)
stdc.gauge('tm.max_fee_per_gas', gap)
next_fee = Fee(max_priority_fee_per_gas=tip, max_fee_per_gas=gap)
next_wait_time = self.next_waiting_time(next_index)
stdc.gauge('tm.next_wating_time', gap)

logger.info('Next fee %s', next_fee)
tx.fee, tx.nonce = next_fee, nonce
Expand Down
5 changes: 3 additions & 2 deletions transaction_manager/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
MAX_WAITING_TIME,
TARGET_REWARD_PERCENTILE
)
from .resources import w3 as gw3
from .resources import stdc, w3 as gw3
from .structures import Tx

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -83,7 +83,8 @@ def block_gas_limit(self) -> int:

@cached_property
def chain_id(self) -> int:
return self.w3.eth.chain_id
with stdc.timer('tm.chain_id_request'):
return self.w3.eth.chain_id

def get_balance(self, address: str) -> int:
checksum_addres = self.w3.to_checksum_address(address)
Expand Down
11 changes: 5 additions & 6 deletions transaction_manager/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
is_replacement_underpriced,
ReceiptTimeoutError
)
from .resources import stcd
from .resources import stdc
from .structures import Tx, TxStatus
from .txpool import TxPool

Expand Down Expand Up @@ -92,7 +92,6 @@ def send(self, tx: Tx) -> None:

if tx_hash is None:
tx.status = TxStatus.UNSENT
stcd.increase('tm.transaction.unsent')
raise SendingError(err)

tx.set_as_sent(tx_hash)
Expand All @@ -115,7 +114,6 @@ def wait(self, tx: Tx, max_time: int) -> Optional[int]:
except ReceiptTimeoutError as err:
logger.info(f'{tx.tx_id} is not mined within {max_time}')
tx.status = TxStatus.TIMEOUT
stcd.increase('tm.transaction.timeout')
raise WaitTimeoutError(err)

rstatus = self.eth.wait_for_receipt(
Expand All @@ -141,7 +139,6 @@ def confirm(self, tx: Tx) -> None:
h, r = self.get_exec_data(tx)
if h is None or r not in (0, 1):
tx.status = TxStatus.UNCONFIRMED
stcd.increase('tm.transaction.unconfirmed')
raise ConfirmationError('Tx is not confirmed')
logger.info('Setting tx %s as completed, result %d', tx.tx_id, r)
tx.set_as_completed(h, r)
Expand Down Expand Up @@ -195,6 +192,8 @@ def acquire_tx(self, tx: Tx) -> Generator[Tx, None, None]:
try:
yield tx
finally:
stdc.gauge('tm.attempt', tx.attempts)
stdc.increase(f'tm.transaction.{tx.status.name}')
if tx.is_sent():
self.attempt_manager.save()
if not tx.is_completed() and tx.is_last_attempt():
Expand All @@ -214,13 +213,13 @@ def process_next(self) -> None:
with self.acquire_tx(tx) as tx:
logger.info(
'Previous attempt %s', self.attempt_manager.current)
with stcd.timer("tm.transaction.time"):
with stdc.timer('tm.transaction.time'):
self.process(tx)

def run(self) -> None:
while True:
try:
stcd.gauge('tm.pool.size', self.pool.size)
stdc.gauge('tm.pool.size', self.pool.size)
self.process_next()
except Exception:
logger.exception('Failed to process tx')
Expand Down
2 changes: 1 addition & 1 deletion transaction_manager/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
cpool: redis.ConnectionPool = redis.ConnectionPool.from_url(REDIS_URI)
rs: redis.Redis = redis.Redis(connection_pool=cpool)
w3: Web3 = init_web3(ENDPOINT, ts_diff=ALLOWED_TS_DIFF)
stcd: statsd.StatsClient = statsd.StatsClient(STATSD_HOST, STATSD_PORT)
stdc: statsd.StatsClient = statsd.StatsClient(STATSD_HOST, STATSD_PORT)

0 comments on commit 70b1bfb

Please sign in to comment.