Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
add goroutine for txpool stat
Browse files Browse the repository at this point in the history
  • Loading branch information
po-bera committed Jan 19, 2024
1 parent 44740fe commit 358236e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cosmos/runtime/txpool/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -121,6 +122,7 @@ func (h *handler) Start() error {
}
go h.mainLoop()
go h.failedLoop() // Start the retry policy
go h.statLoop()
return nil
}

Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions cosmos/runtime/txpool/mocks/tx_sub_provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 358236e

Please sign in to comment.