Skip to content

Commit

Permalink
feat: add metrics to prepare and process proposal (#2560)
Browse files Browse the repository at this point in the history
Closes: #2517

This PR adds metrics to track:
- The amount of times process proposal recovers from a panic
- The amount of invalid transactions that get filtered in prepare
proposal
- The time it takes for prepare proposal and process proposal to execute
  • Loading branch information
cmwaters authored Sep 21, 2023
1 parent e3f2bc2 commit 5682d2c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/prepare_proposal.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package app

import (
"time"

"github.com/celestiaorg/celestia-app/app/ante"
"github.com/celestiaorg/celestia-app/pkg/da"
"github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/celestia-app/pkg/square"
"github.com/cosmos/cosmos-sdk/telemetry"
abci "github.com/tendermint/tendermint/abci/types"
core "github.com/tendermint/tendermint/proto/tendermint/types"
)
Expand All @@ -16,6 +19,7 @@ import (
// tendermint via the BlockData. Panics indicate a developer error and should
// immediately halt the node for visibility and so they can be quickly resolved.
func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePrepareProposal {
defer telemetry.MeasureSince(time.Now(), "prepare_proposal")
// create a context using a branch of the state and loaded using the
// proposal height and chain-id
sdkCtx := app.NewProposalContext(core.Header{
Expand Down
6 changes: 5 additions & 1 deletion app/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package app
import (
"bytes"
"fmt"
"time"

"github.com/celestiaorg/celestia-app/app/ante"
"github.com/celestiaorg/celestia-app/pkg/da"
"github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/celestia-app/pkg/square"
blobtypes "github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
Expand All @@ -19,11 +21,13 @@ import (
const rejectedPropBlockLog = "Rejected proposal block:"

func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.ResponseProcessProposal) {
defer telemetry.MeasureSince(time.Now(), "process_proposal")
// In the case of a panic from an unexpected condition, it is better for the liveness of the
// network that we catch it, log an error and vote nil than to crash the node.
defer func() {
if err := recover(); err != nil {
logInvalidPropBlock(app.Logger(), req.Header, fmt.Sprintf("%v", err))
logInvalidPropBlock(app.Logger(), req.Header, fmt.Sprintf("caught panic: %v", err))
telemetry.IncrCounter(1, "process_proposal", "panics")
resp = reject()
}
}()
Expand Down
3 changes: 3 additions & 0 deletions app/validate_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/log"
Expand Down Expand Up @@ -54,6 +55,7 @@ func filterStdTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler
"error", err,
"msgs", msgTypes(sdkTx),
)
telemetry.IncrCounter(1, "prepare_proposal", "invalid_std_txs")
continue
}
txs[n] = tx
Expand Down Expand Up @@ -83,6 +85,7 @@ func filterBlobTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handle
logger.Error(
"filtering already checked blob transaction", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash()), "error", err,
)
telemetry.IncrCounter(1, "prepare_proposal", "invalid_blob_txs")
continue
}
txs[n] = tx
Expand Down

0 comments on commit 5682d2c

Please sign in to comment.