Skip to content

Commit

Permalink
feat: metric for counting rejected transactions (#1415)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
Co-authored-by: Callum Waters <[email protected]>
  • Loading branch information
3 people authored Jul 31, 2024
1 parent ac057f3 commit 025a8bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 025a8bc

Please sign in to comment.