@@ -347,7 +347,7 @@ func (ec *Confirmer[CID, HEAD, ADDR, THASH, BHASH, R, SEQ, FEE]) ProcessIncluded
347347 continue
348348 }
349349 confirmedTxIDs = append (confirmedTxIDs , tx .ID )
350- observeUntilTxConfirmed (ctx , ec .metrics , tx . TxAttempts , head )
350+ observeUntilTxConfirmed (ctx , ec .metrics , tx , head )
351351 }
352352 // Mark the transactions included on-chain with a purge attempt as fatal error with the terminally stuck error message
353353 if err := ec .txStore .UpdateTxFatalError (ctx , purgeTxIDs , ec .stuckTxDetector .StuckTxFatalError ()); err != nil {
@@ -819,34 +819,35 @@ func (ec *Confirmer[CID, HEAD, ADDR, THASH, BHASH, R, SEQ, FEE]) sendEmptyTransa
819819 return txhash , nil
820820}
821821
822- // observeUntilTxConfirmed observes the promBlocksUntilTxConfirmed metric for each confirmed
823- // transaction.
822+ // observeUntilTxConfirmed observes the timeUntilTxConfirmed and blocksUntilTxConfirmed metrics for each confirmed transaction.
824823func observeUntilTxConfirmed [
825824 CHAIN_ID chains.ID ,
826825 ADDR chains.Hashable ,
827826 TX_HASH , BLOCK_HASH chains.Hashable ,
828827 SEQ chains.Sequence ,
829828 FEE fees.Fee ,
830- ](ctx context.Context , metrics confimerMetrics , attempts []types.TxAttempt [CHAIN_ID , ADDR , TX_HASH , BLOCK_HASH , SEQ , FEE ], head chains.Head [BLOCK_HASH ]) {
831- for _ , attempt := range attempts {
832- // We estimate the time until confirmation by subtracting from the time the tx (not the attempt)
833- // was created. We want to measure the amount of time taken from when a transaction is created
834- // via e.g Txm.CreateTransaction to when it is confirmed on-chain, regardless of how many attempts
835- // were needed to achieve this.
836- duration := time .Since (attempt .Tx .CreatedAt )
837- metrics .RecordTimeUntilTxConfirmed (ctx , float64 (duration ))
838-
839- // Since a tx can have many attempts, we take the number of blocks to confirm as the block number
840- // of the receipt minus the block number of the first ever broadcast for this transaction.
841- var minBroadcastBefore int64
842- for _ , a := range attempt .Tx .TxAttempts {
843- if b := a .BroadcastBeforeBlockNum ; b != nil && * b < minBroadcastBefore {
844- minBroadcastBefore = * b
845- }
846- }
847- if minBroadcastBefore > 0 {
848- blocksElapsed := head .BlockNumber () - minBroadcastBefore
849- metrics .RecordBlocksUntilTxConfirmed (ctx , float64 (blocksElapsed ))
829+ ](ctx context.Context , metrics confimerMetrics , tx * types.Tx [CHAIN_ID , ADDR , TX_HASH , BLOCK_HASH , SEQ , FEE ], head chains.Head [BLOCK_HASH ]) {
830+ if tx == nil {
831+ return
832+ }
833+ // We estimate the time until confirmation by subtracting from the time the tx (not the attempt)
834+ // was created. We want to measure the amount of time taken from when a transaction is created
835+ // via e.g Txm.CreateTransaction to when it is confirmed on-chain, regardless of how many attempts
836+ // were needed to achieve this.
837+ duration := time .Since (tx .CreatedAt )
838+ metrics .RecordTimeUntilTxConfirmed (ctx , float64 (duration ))
839+
840+ // Since a tx can have many attempts, we take the number of blocks to confirm as the current block number
841+ // minus the block number of the first ever broadcast for this transaction.
842+ var minBroadcastBefore int64
843+ for _ , a := range tx .TxAttempts {
844+ if b := a .BroadcastBeforeBlockNum ; b != nil && * b < minBroadcastBefore {
845+ minBroadcastBefore = * b
850846 }
851847 }
848+
849+ if minBroadcastBefore > 0 {
850+ blocksElapsed := head .BlockNumber () - minBroadcastBefore
851+ metrics .RecordBlocksUntilTxConfirmed (ctx , float64 (blocksElapsed ))
852+ }
852853}
0 commit comments