@@ -19,6 +19,7 @@ import (
19
19
cmap "github.com/orcaman/concurrent-map/v2"
20
20
"github.com/pborman/uuid"
21
21
22
+ "github.com/taikoxyz/taiko-client/internal/metrics"
22
23
"github.com/taikoxyz/taiko-client/pkg/rpc"
23
24
)
24
25
@@ -59,6 +60,7 @@ type TxToConfirm struct {
59
60
Retrys uint64
60
61
CurrentTx * types.Transaction
61
62
Receipt * types.Receipt
63
+ CreatedAt time.Time
62
64
63
65
Err error
64
66
}
@@ -306,9 +308,10 @@ func (s *Sender) send(tx *TxToConfirm, resetNonce bool) error {
306
308
s .mu .Lock ()
307
309
defer s .mu .Unlock ()
308
310
309
- // Set the transaction ID
311
+ // Set the transaction ID and its creation time
310
312
if tx .ID == "" {
311
313
tx .ID = uuid .New ()
314
+ tx .CreatedAt = time .Now ()
312
315
}
313
316
314
317
originalTx := tx .originalTx
@@ -371,6 +374,8 @@ func (s *Sender) send(tx *TxToConfirm, resetNonce bool) error {
371
374
)
372
375
return err
373
376
}
377
+
378
+ metrics .TxSenderSentCounter .Inc (1 )
374
379
break
375
380
}
376
381
s .nonce ++
@@ -427,6 +432,7 @@ func (s *Sender) resendUnconfirmedTxs() {
427
432
continue
428
433
}
429
434
if err := s .send (unconfirmedTx , true ); err != nil {
435
+ metrics .TxSenderUnconfirmedCounter .Inc (1 )
430
436
log .Warn (
431
437
"Failed to resend the transaction" ,
432
438
"txId" , id ,
@@ -449,7 +455,8 @@ func (s *Sender) checkPendingTransactionsConfirmation() {
449
455
// Ignore the transaction if it is pending.
450
456
tx , isPending , err := s .client .TransactionByHash (s .ctx , pendingTx .CurrentTx .Hash ())
451
457
if err != nil {
452
- log .Warn ("Failed to fetch transaction" ,
458
+ log .Warn (
459
+ "Failed to fetch transaction" ,
453
460
"txId" , pendingTx .ID ,
454
461
"nonce" , pendingTx .CurrentTx .Nonce (),
455
462
"hash" , pendingTx .CurrentTx .Hash (),
@@ -474,15 +481,27 @@ func (s *Sender) checkPendingTransactionsConfirmation() {
474
481
log .Warn ("Failed to get the transaction receipt" , "hash" , pendingTx .CurrentTx .Hash (), "err" , err )
475
482
continue
476
483
}
484
+
485
+ // Record the gas fee metrics.
486
+ if receipt .BlobGasUsed == 0 {
487
+ metrics .TxSenderGasPriceGauge .Update (receipt .EffectiveGasPrice .Int64 ())
488
+ } else {
489
+ metrics .TxSenderBlobGasPriceGauge .Update (receipt .BlobGasPrice .Int64 ())
490
+ }
491
+
492
+ metrics .TxSenderTxIncludedTimeGauge .Update (int64 (time .Since (pendingTx .CreatedAt ).Seconds ()))
493
+
477
494
pendingTx .Receipt = receipt
478
495
if receipt .Status != types .ReceiptStatusSuccessful {
479
496
pendingTx .Err = fmt .Errorf ("transaction status is failed, hash: %s" , receipt .TxHash )
497
+ metrics .TxSenderConfirmedFailedCounter .Inc (1 )
480
498
s .releaseUnconfirmedTx (id )
481
499
continue
482
500
}
483
501
}
484
502
pendingTx .confirmations = s .head .Number .Uint64 () - pendingTx .Receipt .BlockNumber .Uint64 ()
485
503
if pendingTx .confirmations >= s .ConfirmationDepth {
504
+ metrics .TxSenderConfirmedSuccessfulCounter .Inc (1 )
486
505
s .releaseUnconfirmedTx (id )
487
506
}
488
507
}
0 commit comments