From 025a8bca79393bb5fa869e75b330552e097bf117 Mon Sep 17 00:00:00 2001 From: Eoous <38656355+Eoous@users.noreply.github.com> Date: Wed, 31 Jul 2024 21:22:46 +0800 Subject: [PATCH] feat: metric for counting rejected transactions (#1415) ## Description Add counter to the block executor metrics : - RejectedTransactions Resolves #1241 Unblocks #1007 #### PR checklist - [ ] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments --------- Co-authored-by: 0xEclair <38656355+0xEclair@users.noreply.github.com> Co-authored-by: Callum Waters --- state/execution.go | 6 ++++++ state/metrics.go | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/state/execution.go b/state/execution.go index 99d35b13d7..961a9c36f7 100644 --- a/state/execution.go +++ b/state/execution.go @@ -153,6 +153,12 @@ func (blockExec *BlockExecutor) CreateProposalBlock( panic(fmt.Sprintf("state machine returned an invalid prepare proposal response: expected last transaction to be a hash, got %d bytes", len(rpp.Txs[len(rpp.Txs)-2]))) } + // don't count the last tx in rpp.Txs which is data root back from app + rejectedTxs := len(block.Txs) - (len(rpp.Txs) - 1) + if rejectedTxs > 0 { + blockExec.metrics.RejectedTransactions.Add(float64(rejectedTxs)) + } + // update the block with the response from PrepareProposal block.Data.Txs = types.ToTxs(rpp.Txs[:len(rpp.Txs)-1]) // update the data hash with the one passed back by celestia-app diff --git a/state/metrics.go b/state/metrics.go index 6c687f8549..31c674e60d 100644 --- a/state/metrics.go +++ b/state/metrics.go @@ -19,6 +19,8 @@ type Metrics struct { BlockProcessingTime metrics.Histogram // Count of times a block was rejected via ProcessProposal ProcessProposalRejected metrics.Counter + // Count of transactions rejected by application. + RejectedTransactions metrics.Counter } // PrometheusMetrics returns Metrics build using Prometheus client library. @@ -43,6 +45,12 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { Name: "process_proposal_rejected", Help: "Count of times a block was rejected via ProcessProposal", }, labels).With(labelsAndValues...), + RejectedTransactions: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ + Namespace: namespace, + Subsystem: MetricsSubsystem, + Name: "rejected_transactions", + Help: "Count of transactions rejected by application", + }, labels).With(labelsAndValues...), } } @@ -51,5 +59,6 @@ func NopMetrics() *Metrics { return &Metrics{ BlockProcessingTime: discard.NewHistogram(), ProcessProposalRejected: discard.NewCounter(), + RejectedTransactions: discard.NewCounter(), } }