Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 44 additions & 13 deletions app/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"crypto/sha256"
"time"

"go.opentelemetry.io/otel/attribute"
otelmetric "go.opentelemetry.io/otel/metric"

"github.com/sei-protocol/sei-chain/app/legacyabci"
"github.com/sei-protocol/sei-chain/sei-cosmos/tasks"
"github.com/sei-protocol/sei-chain/sei-cosmos/telemetry"
Expand All @@ -13,7 +16,7 @@ import (
"github.com/sei-protocol/sei-chain/sei-cosmos/types/legacytm"
abci "github.com/sei-protocol/sei-chain/sei-tendermint/abci/types"
"github.com/sei-protocol/sei-chain/sei-tendermint/libs/utils"
"github.com/sei-protocol/sei-chain/utils/metrics"
utilmetrics "github.com/sei-protocol/sei-chain/utils/metrics"
)

func (app *App) BeginBlock(
Expand All @@ -27,14 +30,18 @@ func (app *App) BeginBlock(
defer beginBlockSpan.End()
ctx = ctx.WithTraceSpanContext(spanCtx)
ctx = ctx.WithEventManager(sdk.NewEventManager())
defer telemetry.MeasureSince(time.Now(), "abci", "begin_block")
beginBlockStart := time.Now()
defer func() {
telemetry.MeasureSince(beginBlockStart, "abci", "begin_block") // TODO(PLT-327): remove once app_abci_begin_block_duration_seconds verified
appMetrics.beginBlockDuration.Record(ctx.Context(), time.Since(beginBlockStart).Seconds())
}()
// inline begin block
if checkHeight {
if err := app.ValidateHeight(height); err != nil {
panic(err)
}
}
metrics.GaugeSeidVersionAndCommit(app.versionInfo.Version, app.versionInfo.GitCommit)
utilmetrics.GaugeSeidVersionAndCommit(app.versionInfo.Version, app.versionInfo.GitCommit) // TODO(PLT-327): remove once app_build_info observable gauge verified
// check if we've reached a target height, if so, execute any applicable handlers
if app.forkInitializer != nil {
app.forkInitializer(ctx)
Expand All @@ -59,9 +66,17 @@ func (app *App) EndBlock(ctx sdk.Context, height int64, blockGasUsed int64) (res
spanCtx, span := app.GetBaseApp().TracingInfo.StartWithContext("EndBlock", ctx.TraceSpanContext())
defer span.End()
ctx = ctx.WithTraceSpanContext(spanCtx)
defer telemetry.MeasureSince(time.Now(), "abci", "end_block")
endBlockStart := time.Now()
defer func() {
telemetry.MeasureSince(endBlockStart, "abci", "end_block") // TODO(PLT-327): remove once app_abci_end_block_duration_seconds verified
appMetrics.endBlockDuration.Record(ctx.Context(), time.Since(endBlockStart).Seconds())
}()
ctx = ctx.WithEventManager(sdk.NewEventManager())
defer telemetry.MeasureSince(time.Now(), "module", "total_end_block")
moduleEndBlockStart := time.Now()
defer func() {
telemetry.MeasureSince(moduleEndBlockStart, "module", "total_end_block") // TODO(PLT-327): remove once app_abci_module_end_block_duration_seconds verified
appMetrics.moduleEndBlockDuration.Record(ctx.Context(), time.Since(moduleEndBlockStart).Seconds())
}()
res.ValidatorUpdates = legacyabci.EndBlock(ctx, height, blockGasUsed, app.EndBlockKeepers)
res.Events = sdk.MarkEventsToIndex(ctx.EventManager().ABCIEvents(), app.IndexEvents)
if cp := app.GetConsensusParams(ctx); cp != nil {
Expand All @@ -83,7 +98,11 @@ func (app *App) CheckTx(ctx context.Context, req *abci.RequestCheckTxV2) *abci.R
}
_, span := app.GetBaseApp().TracingInfo.StartWithContext("CheckTx", ctx)
defer span.End()
defer telemetry.MeasureSince(time.Now(), "abci", "check_tx")
checkTxStart := time.Now()
defer func() {
telemetry.MeasureSince(checkTxStart, "abci", "check_tx") // TODO(PLT-327): remove once app_abci_check_tx_duration_seconds verified
appMetrics.checkTxDuration.Record(ctx, time.Since(checkTxStart).Seconds())
}()
sdkCtx := app.GetCheckTxContext(req.Tx, req.Type == abci.CheckTxTypeV2Recheck)
tx, err := app.txDecoder(req.Tx)
if err != nil {
Expand Down Expand Up @@ -121,22 +140,30 @@ func (app *App) CheckTx(ctx context.Context, req *abci.RequestCheckTxV2) *abci.R
}

func (app *App) DeliverTx(ctx sdk.Context, req abci.RequestDeliverTxV2, tx sdk.Tx, checksum [32]byte) abci.ResponseDeliverTx {
defer metrics.MeasureDeliverTxDuration(time.Now())
deliverTxStart := time.Now()
// ensure we carry the initial context from tracer here
spanCtx, span := app.GetBaseApp().TracingInfo.StartWithContext("DeliverTx", ctx.TraceSpanContext())
defer span.End()
// update context with trace span new context
ctx = ctx.WithTraceSpanContext(spanCtx)
defer telemetry.MeasureSince(time.Now(), "abci", "deliver_tx")
defer func() {
utilmetrics.MeasureDeliverTxDuration(deliverTxStart) // TODO(PLT-327): remove once app_abci_deliver_tx_duration_seconds verified
telemetry.MeasureSince(deliverTxStart, "abci", "deliver_tx") // TODO(PLT-327): remove once app_abci_deliver_tx_duration_seconds verified
appMetrics.deliverTxDuration.Record(ctx.Context(), time.Since(deliverTxStart).Seconds())
}()

gInfo := sdk.GasInfo{}
resultStr := "successful"

defer func() {
telemetry.IncrCounter(1, "tx", "count")
telemetry.IncrCounter(1, "tx", resultStr)
telemetry.SetGauge(float32(gInfo.GasUsed), "tx", "gas", "used")
telemetry.SetGauge(float32(gInfo.GasWanted), "tx", "gas", "wanted")
telemetry.IncrCounter(1, "tx", "count") // TODO(PLT-327): remove once app_tx_count_total verified
telemetry.IncrCounter(1, "tx", resultStr) // TODO(PLT-327): remove once app_tx_count_total verified
telemetry.SetGauge(float32(gInfo.GasUsed), "tx", "gas", "used") // TODO(PLT-327): remove once app_tx_gas_used verified
telemetry.SetGauge(float32(gInfo.GasWanted), "tx", "gas", "wanted") // TODO(PLT-327): remove once app_tx_gas_wanted verified
appMetrics.txCount.Add(ctx.Context(), 1)
appMetrics.txCount.Add(ctx.Context(), 1, otelmetric.WithAttributes(attribute.String("result", resultStr)))
appMetrics.txGasUsed.Record(ctx.Context(), int64(gInfo.GasUsed)) //nolint:gosec
appMetrics.txGasWanted.Record(ctx.Context(), int64(gInfo.GasWanted)) //nolint:gosec
}()
gInfo, result, anteEvents, resCtx, err := legacyabci.DeliverTx(ctx.WithTxBytes(req.Tx).WithTxSum(checksum), tx, app.GetTxConfig(), &app.DeliverTxKeepers, checksum, func(ctx sdk.Context) (sdk.Context, sdk.CacheMultiStore) {
return app.CacheTxContext(ctx, checksum)
Expand Down Expand Up @@ -177,7 +204,11 @@ func (app *App) DeliverTx(ctx sdk.Context, req abci.RequestDeliverTxV2, tx sdk.T

// DeliverTxBatch is not part of the ABCI specification, but this is here for code convention
func (app *App) DeliverTxBatch(ctx sdk.Context, req sdk.DeliverTxBatchRequest) (res sdk.DeliverTxBatchResponse) {
defer metrics.MeasureDeliverBatchTxDuration(time.Now())
deliverBatchStart := time.Now()
defer func() {
utilmetrics.MeasureDeliverBatchTxDuration(deliverBatchStart) // TODO(PLT-327): remove once app_abci_deliver_batch_tx_duration_seconds verified
appMetrics.deliverBatchTxDuration.Record(ctx.Context(), time.Since(deliverBatchStart).Seconds())
}()
spanCtx, span := app.GetBaseApp().TracingInfo.StartWithContext("DeliverTxBatch", ctx.TraceSpanContext())
defer span.End()
// update context with trace span new context
Expand Down
15 changes: 11 additions & 4 deletions app/ante/evm_checktx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
upgradekeeper "github.com/sei-protocol/sei-chain/sei-cosmos/x/upgrade/keeper"
abci "github.com/sei-protocol/sei-chain/sei-tendermint/abci/types"
tmtypes "github.com/sei-protocol/sei-chain/sei-tendermint/types"
"go.opentelemetry.io/otel/attribute"
otelmetric "go.opentelemetry.io/otel/metric"

"github.com/sei-protocol/sei-chain/utils"
"github.com/sei-protocol/sei-chain/utils/helpers"
"github.com/sei-protocol/sei-chain/utils/metrics"
Expand Down Expand Up @@ -297,14 +300,16 @@ func CheckNonce(ctx sdk.Context, latestCtxGetter func() sdk.Context, ek *evmkeep
ctx = ctx.WithCheckTxCallback(func(priority int64) {
txHash := tmtypes.Tx(ctx.TxBytes()).Hash()
ek.AddPendingNonce(txHash, evmAddr, etx.Nonce(), priority)
metrics.IncrementPendingNonce("added")
metrics.IncrementPendingNonce("added") // TODO(PLT-327): remove once app_pending_nonce_total verified
getAnteMetrics().pendingNonce.Add(ctx.Context(), 1, otelmetric.WithAttributes(attribute.String("event", "added")))
})

// if the mempool expires a transaction, this handler is invoked
ctx = ctx.WithExpireTxHandler(func() {
txHash := tmtypes.Tx(ctx.TxBytes()).Hash()
ek.RemovePendingNonce(txHash)
metrics.IncrementPendingNonce("expired")
metrics.IncrementPendingNonce("expired") // TODO(PLT-327): remove once app_pending_nonce_total verified
getAnteMetrics().pendingNonce.Add(ctx.Context(), 1, otelmetric.WithAttributes(attribute.String("event", "expired")))
})

if txNonce > nextNonce {
Expand All @@ -323,7 +328,8 @@ func CheckNonce(ctx sdk.Context, latestCtxGetter func() sdk.Context, ek *evmkeep

if txNonce < nextNonceToBeMined {
// this nonce has already been mined, we cannot accept it again
metrics.IncrementPendingNonce("rejected")
metrics.IncrementPendingNonce("rejected") // TODO(PLT-327): remove once app_pending_nonce_total verified
getAnteMetrics().pendingNonce.Add(ctx.Context(), 1, otelmetric.WithAttributes(attribute.String("event", "rejected")))
return abci.Rejected
} else if txNonce < nextPendingNonce {
// check if the sender still has enough funds to pay for gas
Expand All @@ -335,7 +341,8 @@ func CheckNonce(ctx sdk.Context, latestCtxGetter func() sdk.Context, ek *evmkeep
// this nonce is allowed to process as it is part of the
// consecutive nonces from nextNonceToBeMined to nextPendingNonce
// This logic allows multiple nonces from an account to be processed in a block.
metrics.IncrementPendingNonce("accepted")
metrics.IncrementPendingNonce("accepted") // TODO(PLT-327): remove once app_pending_nonce_total verified
getAnteMetrics().pendingNonce.Add(ctx.Context(), 1, otelmetric.WithAttributes(attribute.String("event", "accepted")))
return abci.Accepted
}
return abci.Pending
Expand Down
27 changes: 27 additions & 0 deletions app/ante/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ante

import (
"sync"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
)

type anteMetrics struct {
pendingNonce metric.Int64Counter
}

// getAnteMetrics returns the package-level OTel instruments, initializing them
// lazily on first call (after the global MeterProvider is set in NewApp).
var getAnteMetrics = sync.OnceValue(func() *anteMetrics {
m := &anteMetrics{}
meter := otel.Meter("app_ante")
var err error
if m.pendingNonce, err = meter.Int64Counter(
"app_pending_nonce_total",
metric.WithDescription("Pending nonce events by type (added, expired, rejected, accepted)"),
); err != nil {
panic("ante anteMetrics: " + err.Error())
}
return m
})
60 changes: 47 additions & 13 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@
tmproto "github.com/sei-protocol/sei-chain/sei-tendermint/proto/tendermint/types"
tmtypes "github.com/sei-protocol/sei-chain/sei-tendermint/types"
wasmkeeper "github.com/sei-protocol/sei-chain/sei-wasmd/x/wasm/keeper"

"github.com/sei-protocol/sei-chain/utils"
"github.com/sei-protocol/sei-chain/utils/metrics"

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / Compile with Mock Balances

other declaration of metrics

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / Coverage

other declaration of metrics

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / Linux AMD64

other declaration of metrics

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / macOS ARM64

other declaration of metrics

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / Run ETH Blocktests 0

other declaration of metrics

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / Run ETH Blocktests 3

other declaration of metrics

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / Run ETH Blocktests 4

other declaration of metrics

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / Run ETH Blocktests 1

other declaration of metrics

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / Run ETH Blocktests 2

other declaration of metrics

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

other declaration of metrics

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / Race Detection

other declaration of metrics

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / Race Detection

other declaration of metrics

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / Race Detection

other declaration of metrics

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / Go / Lint

other declaration of metrics

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / Go / Lint

other declaration of metrics

Check failure on line 143 in app/app.go

View workflow job for this annotation

GitHub Actions / Go / Lint

other declaration of metrics
"github.com/sei-protocol/sei-chain/wasmbinding"
epochmodule "github.com/sei-protocol/sei-chain/x/epoch"
epochmodulekeeper "github.com/sei-protocol/sei-chain/x/epoch/keeper"
Expand All @@ -165,6 +166,7 @@
"github.com/spf13/cast"
dbm "github.com/tendermint/tm-db"
"go.opentelemetry.io/otel/attribute"
otelmetric "go.opentelemetry.io/otel/metric"

// this line is used by starport scaffolding # stargate/app/moduleImport

Expand Down Expand Up @@ -491,6 +493,7 @@
if err := metrics.SetupOtelMetricsProvider(); err != nil {
logger.Error(err.Error())
}
initAppMetrics()

keys := sdk.NewKVStoreKeys(
authtypes.StoreKey, authzkeeper.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
Expand Down Expand Up @@ -1217,7 +1220,9 @@
// Invariant: at this point nil entries in typedTxs are proto decode failures only.
// EVM preprocessing runs later inside ProcessBlock; do not reorder that before this check.
if !app.checkTotalBlockGas(checkCtx, typedTxs) {
metrics.IncrFailedTotalGasWantedCheck(string(req.Header.ProposerAddress))
metrics.IncrFailedTotalGasWantedCheck(string(req.Header.ProposerAddress)) // TODO(PLT-327): remove once app_failed_total_gas_wanted_check_total verified
appMetrics.failedGasWantedCheck.Add(ctx.Context(), 1,
otelmetric.WithAttributes(attribute.String("proposer", string(req.Header.ProposerAddress))))
return &abci.ResponseProcessProposal{
Status: abci.ResponseProcessProposal_REJECT,
}, nil
Expand Down Expand Up @@ -1318,7 +1323,9 @@
app.optimisticProcessingInfoMutex.RUnlock()

if !aborted && bytes.Equal(finalHash, req.Hash) {
metrics.IncrementOptimisticProcessingCounter(true)
metrics.IncrementOptimisticProcessingCounter(true) // TODO(PLT-327): remove once app_optimistic_processing_total verified
appMetrics.optimisticProcessing.Add(ctx.Context(), 1,
otelmetric.WithAttributes(attribute.String("enabled", "true")))
app.SetProcessProposalStateToCommit()
if app.EvmKeeper.EthReplayConfig.Enabled || app.EvmKeeper.EthBlockTestConfig.Enabled {
return &abci.ResponseFinalizeBlock{}, nil
Expand All @@ -1330,7 +1337,9 @@
return &resp, nil
}
}
metrics.IncrementOptimisticProcessingCounter(false)
metrics.IncrementOptimisticProcessingCounter(false) // TODO(PLT-327): remove once app_optimistic_processing_total verified
appMetrics.optimisticProcessing.Add(ctx.Context(), 1,
otelmetric.WithAttributes(attribute.String("enabled", "false")))
logger.Info("optimistic processing ineligible")
bpreq := &BlockProcessRequest{
Hash: req.Hash,
Expand Down Expand Up @@ -1384,8 +1393,12 @@

if !skipMetrics {
// Record metrics for non-gasless transactions
metrics.IncrGasCounter("gas_used", deliverTxResp.GasUsed)
metrics.IncrGasCounter("gas_wanted", deliverTxResp.GasWanted)
metrics.IncrGasCounter("gas_used", deliverTxResp.GasUsed) // TODO(PLT-327): remove once app_tx_gas_total verified
metrics.IncrGasCounter("gas_wanted", deliverTxResp.GasWanted) // TODO(PLT-327): remove once app_tx_gas_total verified
appMetrics.txGas.Add(ctx.Context(), deliverTxResp.GasUsed,
otelmetric.WithAttributes(attribute.String("type", "gas_used")))
appMetrics.txGas.Add(ctx.Context(), deliverTxResp.GasWanted,
otelmetric.WithAttributes(attribute.String("type", "gas_wanted")))
}

return &abci.ExecTxResult{
Expand All @@ -1402,20 +1415,32 @@
}

func (app *App) ProcessTxsSynchronousV2(ctx sdk.Context, txs [][]byte, typedTxs []sdk.Tx) []*abci.ExecTxResult {
defer metrics.BlockProcessLatency(time.Now(), metrics.SYNCHRONOUS)
blockProcessStart := time.Now()
defer func() {
metrics.BlockProcessLatency(blockProcessStart, metrics.SYNCHRONOUS) // TODO(PLT-327): remove once app_block_process_duration_seconds verified
appMetrics.blockProcessDuration.Record(ctx.Context(), time.Since(blockProcessStart).Seconds(),
otelmetric.WithAttributes(attribute.String("type", metrics.SYNCHRONOUS)))
}()

txResults := make([]*abci.ExecTxResult, 0, len(txs))
for i, tx := range txs {
ctx = ctx.WithTxIndex(i)
res := app.DeliverTxWithResult(ctx, tx, typedTxs[i])
txResults = append(txResults, res)
metrics.IncrTxProcessTypeCounter(metrics.SYNCHRONOUS)
metrics.IncrTxProcessTypeCounter(metrics.SYNCHRONOUS) // TODO(PLT-327): remove once app_tx_process_type_total verified
appMetrics.txProcessType.Add(ctx.Context(), 1,
otelmetric.WithAttributes(attribute.String("type", metrics.SYNCHRONOUS)))
}
return txResults
}

func (app *App) ProcessTxsSynchronousGiga(ctx sdk.Context, txs [][]byte, typedTxs []sdk.Tx) []*abci.ExecTxResult {
defer metrics.BlockProcessLatency(time.Now(), metrics.SYNCHRONOUS)
blockProcessGigaStart := time.Now()
defer func() {
metrics.BlockProcessLatency(blockProcessGigaStart, metrics.SYNCHRONOUS) // TODO(PLT-327): remove once app_block_process_duration_seconds verified
appMetrics.blockProcessDuration.Record(ctx.Context(), time.Since(blockProcessGigaStart).Seconds(),
otelmetric.WithAttributes(attribute.String("type", metrics.SYNCHRONOUS)))
}()

ms := ctx.MultiStore().CacheMultiStore()
defer ms.Write()
Expand Down Expand Up @@ -1500,7 +1525,9 @@

txResults[i] = result
ctx.GigaMultiStore().WriteGiga()
metrics.IncrTxProcessTypeCounter(metrics.SYNCHRONOUS)
metrics.IncrTxProcessTypeCounter(metrics.SYNCHRONOUS) // TODO(PLT-327): remove once app_tx_process_type_total verified
appMetrics.txProcessType.Add(ctx.Context(), 1,
otelmetric.WithAttributes(attribute.String("type", metrics.SYNCHRONOUS)))
}

return txResults
Expand Down Expand Up @@ -1549,7 +1576,9 @@

execResults := make([]*abci.ExecTxResult, 0, len(batchResult.Results))
for i, r := range batchResult.Results {
metrics.IncrTxProcessTypeCounter(metrics.OCC_CONCURRENT)
metrics.IncrTxProcessTypeCounter(metrics.OCC_CONCURRENT) // TODO(PLT-327): remove once app_tx_process_type_total verified
appMetrics.txProcessType.Add(ctx.Context(), 1,
otelmetric.WithAttributes(attribute.String("type", metrics.OCC_CONCURRENT)))

// Check if transaction is gasless before recording gas metrics
var recordGasMetrics = true
Expand All @@ -1575,8 +1604,12 @@
}

if recordGasMetrics {
metrics.IncrGasCounter("gas_used", r.Response.GasUsed)
metrics.IncrGasCounter("gas_wanted", r.Response.GasWanted)
metrics.IncrGasCounter("gas_used", r.Response.GasUsed) // TODO(PLT-327): remove once app_tx_gas_total verified
metrics.IncrGasCounter("gas_wanted", r.Response.GasWanted) // TODO(PLT-327): remove once app_tx_gas_total verified
appMetrics.txGas.Add(ctx.Context(), r.Response.GasUsed,
otelmetric.WithAttributes(attribute.String("type", "gas_used")))
appMetrics.txGas.Add(ctx.Context(), r.Response.GasWanted,
otelmetric.WithAttributes(attribute.String("type", "gas_wanted")))
}

execResults = append(execResults, &abci.ExecTxResult{
Expand Down Expand Up @@ -1655,7 +1688,8 @@
}

if fallbackToV2 {
metrics.IncrGigaFallbackToV2Counter()
metrics.IncrGigaFallbackToV2Counter() // TODO(PLT-327): remove once app_giga_fallback_to_v2_total verified
appMetrics.gigaFallback.Add(ctx.Context(), 1)
// Discard all EVM changes by skipping cache writes, then re-run all txs via DeliverTx.
evmBatchResult = nil
v2Entries = make([]*sdk.DeliverTxEntry, len(txs))
Expand Down
Loading
Loading