@@ -8,21 +8,10 @@ import (
88 "sync"
99 "time"
1010
11- "github.com/prometheus/client_golang/prometheus"
12- "github.com/prometheus/client_golang/prometheus/promauto"
13-
1411 "github.com/smartcontractkit/chainlink-common/pkg/logger"
1512 "github.com/smartcontractkit/chainlink-common/pkg/services"
1613)
1714
18- var (
19- // PromMultiNodeInvariantViolations reports violation of our assumptions
20- PromMultiNodeInvariantViolations = promauto .NewCounterVec (prometheus.CounterOpts {
21- Name : "multi_node_invariant_violations" ,
22- Help : "The number of invariant violations" ,
23- }, []string {"network" , "chainId" , "invariant" })
24- )
25-
2615type sendTxResult [RESULT any ] struct {
2716 res RESULT
2817 code SendTxReturnCode
@@ -37,11 +26,16 @@ type SendTxRPCClient[TX any, RESULT any] interface {
3726 SendTransaction (ctx context.Context , tx TX ) (RESULT , SendTxReturnCode , error )
3827}
3928
29+ type transactionSenderMetrics interface {
30+ IncrementInvariantViolations (ctx context.Context , invariant string )
31+ }
32+
4033func NewTransactionSender [TX any , RESULT any , CHAIN_ID ID , RPC SendTxRPCClient [TX , RESULT ]](
4134 lggr logger.Logger ,
4235 chainID CHAIN_ID ,
4336 chainFamily string ,
4437 multiNode * MultiNode [CHAIN_ID , RPC ],
38+ metrics transactionSenderMetrics ,
4539 classifyErr func (err error ) SendTxReturnCode ,
4640 sendTxSoftTimeout time.Duration ,
4741) * TransactionSender [TX , RESULT , CHAIN_ID , RPC ] {
@@ -52,6 +46,7 @@ func NewTransactionSender[TX any, RESULT any, CHAIN_ID ID, RPC SendTxRPCClient[T
5246 chainID : chainID ,
5347 chainFamily : chainFamily ,
5448 lggr : logger .Sugared (lggr ).Named ("TransactionSender" ).With ("chainID" , chainID .String ()),
49+ metrics : metrics ,
5550 multiNode : multiNode ,
5651 classifyErr : classifyErr ,
5752 sendTxSoftTimeout : sendTxSoftTimeout ,
@@ -64,6 +59,7 @@ type TransactionSender[TX any, RESULT any, CHAIN_ID ID, RPC SendTxRPCClient[TX,
6459 chainID CHAIN_ID
6560 chainFamily string
6661 lggr logger.SugaredLogger
62+ metrics transactionSenderMetrics
6763 multiNode * MultiNode [CHAIN_ID , RPC ]
6864 classifyErr func (err error ) SendTxReturnCode
6965 sendTxSoftTimeout time.Duration // defines max waiting time from first response til responses evaluation
@@ -199,7 +195,9 @@ func (txSender *TransactionSender[TX, RESULT, CHAIN_ID, RPC]) reportSendTxAnomal
199195 _ , criticalErr := aggregateTxResults (resultsByCode )
200196 if criticalErr != nil {
201197 txSender .lggr .Criticalw ("observed invariant violation on SendTransaction" , "tx" , tx , "resultsByCode" , resultsByCode , "err" , criticalErr )
202- PromMultiNodeInvariantViolations .WithLabelValues (txSender .chainFamily , txSender .chainID .String (), criticalErr .Error ()).Inc ()
198+ ctx , cancel := txSender .chStop .NewCtx ()
199+ defer cancel ()
200+ txSender .metrics .IncrementInvariantViolations (ctx , criticalErr .Error ())
203201 }
204202}
205203
0 commit comments