diff --git a/cosmos/runtime/txpool/handler.go b/cosmos/runtime/txpool/handler.go index e034944b4..b50b3edc9 100644 --- a/cosmos/runtime/txpool/handler.go +++ b/cosmos/runtime/txpool/handler.go @@ -52,6 +52,7 @@ type SdkTx interface { // TxSubProvider. type TxSubProvider interface { SubscribeTransactions(ch chan<- core.NewTxsEvent, reorgs bool) event.Subscription + Stats() (int, int) } // TxSerializer provides an interface to Serialize Geth Transactions to Bytes (via sdk.Tx). @@ -121,6 +122,7 @@ func (h *handler) Start() error { } go h.mainLoop() go h.failedLoop() // Start the retry policy + go h.statLoop() return nil } @@ -178,6 +180,21 @@ func (h *handler) failedLoop() { } } +func (h *handler) statLoop() { + ticker := time.NewTicker(5 * time.Second) + defer ticker.Stop() + for { + select { + case <-h.stopCh: + return + case <-ticker.C: + pending, queue := h.txPool.Stats() + telemetry.SetGauge(float32(pending), MetricKeyTxPoolPending) + telemetry.SetGauge(float32(queue), MetricKeyTxPoolQueue) + } + } +} + // Running returns true if the handler is running. func (h *handler) Running() bool { return h.running.Load() diff --git a/cosmos/runtime/txpool/mocks/tx_sub_provider.go b/cosmos/runtime/txpool/mocks/tx_sub_provider.go index 379478103..af7976b6d 100644 --- a/cosmos/runtime/txpool/mocks/tx_sub_provider.go +++ b/cosmos/runtime/txpool/mocks/tx_sub_provider.go @@ -54,6 +54,10 @@ func (_e *TxSubProvider_Expecter) SubscribeTransactions(ch interface{}, reorgs i return &TxSubProvider_SubscribeTransactions_Call{Call: _e.mock.On("SubscribeTransactions", ch, reorgs)} } +func (_m *TxSubProvider) Stats() (int, int) { + return 0, 0 +} + func (_c *TxSubProvider_SubscribeTransactions_Call) Run(run func(ch chan<- core.NewTxsEvent, reorgs bool)) *TxSubProvider_SubscribeTransactions_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(chan<- core.NewTxsEvent), args[1].(bool))