From 6551c6cb96efd1463b9c7393a08f8a6034ec813c Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Thu, 21 Sep 2023 17:27:23 +0200 Subject: [PATCH] feat: add metrics to prepare and process proposal (#2560) Closes: https://github.com/celestiaorg/celestia-app/issues/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 (cherry picked from commit 5682d2ce937647cb212a990a3c8ecc52b2142232) --- app/prepare_proposal.go | 4 ++++ app/process_proposal.go | 6 +++++- app/validate_txs.go | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/prepare_proposal.go b/app/prepare_proposal.go index 88091d5fbb..c8d06b664e 100644 --- a/app/prepare_proposal.go +++ b/app/prepare_proposal.go @@ -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" ) @@ -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{ diff --git a/app/process_proposal.go b/app/process_proposal.go index 942569fa58..b2e6a446b9 100644 --- a/app/process_proposal.go +++ b/app/process_proposal.go @@ -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" @@ -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() } }() diff --git a/app/validate_txs.go b/app/validate_txs.go index 2c13f12f28..9a74fb0bbb 100644 --- a/app/validate_txs.go +++ b/app/validate_txs.go @@ -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" @@ -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 @@ -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