Skip to content

Commit

Permalink
feat: metric for counting rejected transactions (#1415)
Browse files Browse the repository at this point in the history
Add counter to the block executor metrics :
- RejectedTransactions

Resolves #1241

Unblocks #1007

- [ ] 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 <[email protected]>
Co-authored-by: Callum Waters <[email protected]>
  • Loading branch information
3 people committed Jul 31, 2024
1 parent 1214056 commit 4a69a7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ func (blockExec *BlockExecutor) CreateProposalBlock(
panic(err)
}
rawNewData := preparedProposal.GetBlockData()

// don't count the last tx in rpp.Txs which is data root back from app
rejectedTxs := len(rawNewData.Txs) - len(txs)
if rejectedTxs > 0 {
blockExec.metrics.RejectedTransactions.Add(float64(rejectedTxs))
}

var blockDataSize int
for _, tx := range rawNewData.GetTxs() {
blockDataSize += len(tx)
Expand Down
9 changes: 9 additions & 0 deletions state/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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...),
}
}

Expand All @@ -51,5 +59,6 @@ func NopMetrics() *Metrics {
return &Metrics{
BlockProcessingTime: discard.NewHistogram(),
ProcessProposalRejected: discard.NewCounter(),
RejectedTransactions: discard.NewCounter(),
}
}

0 comments on commit 4a69a7a

Please sign in to comment.