Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

feat(telemetry): add timing operations #1343

Merged
merged 10 commits into from
Dec 11, 2023
Merged
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
5 changes: 2 additions & 3 deletions cosmos/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
cosmossdk.io/core v0.11.0
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/log v1.2.1
cosmossdk.io/math v1.2.0
cosmossdk.io/math v1.2.1-0.20231207094843-14bb52ad925e
cosmossdk.io/store v1.0.0
cosmossdk.io/x/evidence v0.0.0-20231103111158-e83a20081ced
cosmossdk.io/x/tx v0.12.0
Expand Down Expand Up @@ -248,11 +248,10 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v1.1.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
9 changes: 5 additions & 4 deletions cosmos/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ cosmossdk.io/errors v1.0.0 h1:nxF07lmlBbB8NKQhtJ+sJm6ef5uV1XkvPXG2bUntb04=
cosmossdk.io/errors v1.0.0/go.mod h1:+hJZLuhdDE0pYN8HkOrVNwrIOYvUGnn6+4fjnJs/oV0=
cosmossdk.io/log v1.2.1 h1:Xc1GgTCicniwmMiKwDxUjO4eLhPxoVdI9vtMW8Ti/uk=
cosmossdk.io/log v1.2.1/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4=
cosmossdk.io/math v1.2.0 h1:8gudhTkkD3NxOP2YyyJIYYmt6dQ55ZfJkDOaxXpy7Ig=
cosmossdk.io/math v1.2.0/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0=
cosmossdk.io/math v1.2.1-0.20231207094843-14bb52ad925e h1:oou3TGlMyd1oTG7vHAPOdEBBrE9sanVd2+ktsTfZB8I=
cosmossdk.io/math v1.2.1-0.20231207094843-14bb52ad925e/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
cosmossdk.io/store v1.0.0 h1:6tnPgTpTSIskaTmw/4s5C9FARdgFflycIc9OX8i1tOI=
cosmossdk.io/store v1.0.0/go.mod h1:ABMprwjvx6IpMp8l06TwuMrj6694/QP5NIW+X6jaTYc=
cosmossdk.io/x/evidence v0.0.0-20231103111158-e83a20081ced h1:y2eG5dV8cVPPw88+ZtoFqaGaibTwRdN3uGGOO3QPWQk=
Expand Down Expand Up @@ -482,6 +482,7 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
Expand Down Expand Up @@ -1531,6 +1532,6 @@ rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU=
rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
17 changes: 15 additions & 2 deletions cosmos/runtime/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ package miner

import (
"context"
"time"

"github.com/cosmos/gogoproto/proto"

"github.com/berachain/polaris/eth"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -67,10 +69,15 @@ func (m *Miner) Init(serializer EnvelopeSerializer) {
// to resolve from the underying worker.
func (m *Miner) buildBlock(ctx sdk.Context) ([]byte, uint64, error) {
defer m.clearPayload()

// Record the time it takes to build a payload.
defer telemetry.MeasureSince(time.Now(), MetricKeyBuildBlock)

if err := m.submitPayloadForBuilding(ctx); err != nil {
return nil, 0, err
}
env, gasUsed := m.resolveEnvelope()

return env, gasUsed, nil
}

Expand Down Expand Up @@ -109,11 +116,17 @@ func (m *Miner) resolveEnvelope() ([]byte, uint64) {
return nil, 0
}
envelope := m.currentPayload.ResolveFull()
bz, err := m.serializer.ToSdkTxBytes(envelope, envelope.ExecutionPayload.GasLimit)
payload := envelope.ExecutionPayload

// Record metadata about the payload
defer telemetry.SetGauge(float32(payload.GasUsed), MetricKeyBlockGasUsed)
defer telemetry.SetGauge(float32(len(payload.Transactions)), MetricKeyTransactions)

bz, err := m.serializer.ToSdkTxBytes(envelope, payload.GasLimit)
if err != nil {
panic(err)
}
return bz, envelope.ExecutionPayload.GasUsed
return bz, payload.GasUsed
}

// clearPayload clears the payload.
Expand Down
27 changes: 27 additions & 0 deletions cosmos/runtime/miner/telemetry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2023, Berachain Foundation. All rights reserved.
// Use of this software is govered by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package miner

const (
MetricKeyBuildBlock = "polaris_miner_build_block"
MetricKeyBlockGasUsed = "polaris_miner_block_gas_used"
MetricKeyTransactions = "polaris_miner_transactions"
)
3 changes: 3 additions & 0 deletions cosmos/runtime/txpool/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"cosmossdk.io/log"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

Expand Down Expand Up @@ -229,12 +230,14 @@ func (h *handler) broadcastTransaction(tx *ethtypes.Transaction, retries int) {
switch rsp.Code {
case sdkerrors.ErrMempoolIsFull.ABCICode():
h.logger.Error("failed to broadcast: comet-bft mempool is full", "tx_hash", tx.Hash())
telemetry.IncrCounter(float32(1), MetricKeyMempoolFull)
case
sdkerrors.ErrTxInMempoolCache.ABCICode():
return
default:
h.logger.Error("failed to broadcast transaction",
"codespace", rsp.Codespace, "code", rsp.Code, "info", rsp.Info, "tx_hash", tx.Hash())
telemetry.IncrCounter(float32(1), MetricKeyBroadcastFailure)
}

h.failedTxs <- &failedTx{tx: tx, retries: retries}
Expand Down
26 changes: 26 additions & 0 deletions cosmos/runtime/txpool/telemetry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2023, Berachain Foundation. All rights reserved.
// Use of this software is govered by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package txpool

const (
MetricKeyMempoolFull = "polaris_cometbft_mempool_full"
MetricKeyBroadcastFailure = "polaris_cometbft_broadcast_failure"
)
12 changes: 12 additions & 0 deletions cosmos/store/snapmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
package snapmulti

import (
"time"

"cosmossdk.io/store/cachekv"
storetypes "cosmossdk.io/store/types"

polariscachekv "github.com/berachain/polaris/cosmos/store/cachekv"
"github.com/berachain/polaris/lib/ds"
"github.com/berachain/polaris/lib/ds/stack"
"github.com/berachain/polaris/lib/utils"

"github.com/cosmos/cosmos-sdk/telemetry"
)

const (
Expand Down Expand Up @@ -109,6 +113,9 @@ func (s *store) GetKVStore(key storetypes.StoreKey) storetypes.KVStore {

// Snapshot implements `libtypes.Snapshottable`.
func (s *store) Snapshot() int {
defer telemetry.MeasureSince(time.Now(), MetricKeySnapshot)
defer telemetry.SetGauge(float32(s.journal.Size()), MetricKeySnapshotSize)

var cms mapMultiStore
if cms = s.journal.Peek(); cms == nil {
// use root if the journal is empty
Expand All @@ -128,6 +135,8 @@ func (s *store) Snapshot() int {
// Revert implements `libtypes.Snapshottable`.
func (s *store) RevertToSnapshot(id int) {
// id is the new size of the journal we want to maintain.
defer telemetry.MeasureSince(time.Now(), MetricKeyRevertToSnapshot)
defer telemetry.SetGauge(float32(s.journal.Size()-id), MetricKeyRevertToSnapshotSize)
s.journal.PopToSize(id)
}

Expand All @@ -137,6 +146,9 @@ func (s *store) RevertToSnapshot(id int) {
//
// Finalize implements `libtypes.Controllable`.
func (s *store) Finalize() {
defer telemetry.MeasureSince(time.Now(), MetricKeyFinalize)
defer telemetry.SetGauge(float32(s.journal.Size()), MetricKeyFinalizeSize)

// Recursively pop the journal and write each cachekv store to its parent cachekv store.
for revision := s.journal.Pop(); revision != nil; revision = s.journal.Pop() {
for key, cacheKVStore := range revision {
Expand Down
31 changes: 31 additions & 0 deletions cosmos/store/snapmulti/telemetry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2023, Berachain Foundation. All rights reserved.
// Use of this software is govered by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package snapmulti

const (
MetricKeyBase = "polaris_snapmulti_"
MetricKeyFinalize = MetricKeyBase + "finalize"
MetricKeyFinalizeSize = MetricKeyFinalize + "_size"
MetricKeySnapshot = MetricKeyBase + "snapshot"
MetricKeySnapshotSize = MetricKeySnapshot + "_size"
MetricKeyRevertToSnapshot = MetricKeyBase + "revert_to_snapshot"
MetricKeyRevertToSnapshotSize = MetricKeyRevertToSnapshot + "_size"
)
7 changes: 7 additions & 0 deletions cosmos/x/evm/keeper/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@ package keeper
import (
"context"
"fmt"
"time"

storetypes "cosmossdk.io/store/types"

evmtypes "github.com/berachain/polaris/cosmos/x/evm/types"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/ethereum/go-ethereum/beacon/engine"
ethtypes "github.com/ethereum/go-ethereum/core/types"
)

const ()

func (k *Keeper) ProcessPayloadEnvelope(
ctx context.Context, msg *evmtypes.WrappedPayloadEnvelope,
) (*evmtypes.WrappedPayloadEnvelopeResponse, error) {
Expand Down Expand Up @@ -66,6 +70,9 @@ func (k *Keeper) ProcessPayloadEnvelope(
ctx = sCtx.WithKVGasConfig(storetypes.GasConfig{}).
itsdevbear marked this conversation as resolved.
Show resolved Hide resolved
WithTransientKVGasConfig(storetypes.GasConfig{})

// Record how long it takes to insert the new block into the chain.
defer telemetry.ModuleMeasureSince(evmtypes.ModuleName,
time.Now(), evmtypes.MetricKeyInsertBlockAndSetHead)
if err = k.wrappedChain.InsertBlockAndSetHead(ctx, block); err != nil {
return nil, err
}
Expand Down
25 changes: 15 additions & 10 deletions cosmos/x/evm/plugins/precompile/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package precompile
import (
"fmt"
"math/big"
"time"

storetypes "cosmossdk.io/store/types"

Expand All @@ -35,6 +36,7 @@ import (
libtypes "github.com/berachain/polaris/lib/types"
"github.com/berachain/polaris/lib/utils"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -166,16 +168,19 @@ func (p *plugin) Run(
gm.ConsumeGas(requiredGas, "precompile required gas")

// run the precompile container
ret, err = pc.Run(
ctx.WithGasMeter(gm).
WithKVGasConfig(p.kvGasConfig).
WithTransientKVGasConfig(p.transientKVGasConfig),
evm,
input,
caller,
value,
)
gasRemaining = gm.GasRemaining()
{
defer telemetry.MeasureSince(time.Now(), MetricKeyTime)
ret, err = pc.Run(
ctx.WithGasMeter(gm).
WithKVGasConfig(p.kvGasConfig).
WithTransientKVGasConfig(p.transientKVGasConfig),
evm,
input,
caller,
value,
)
gasRemaining = gm.GasRemaining()
}

return //nolint:nakedret // named returns.
}
Expand Down
26 changes: 26 additions & 0 deletions cosmos/x/evm/plugins/precompile/telemetry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2023, Berachain Foundation. All rights reserved.
// Use of this software is govered by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package precompile

const (
MetricKeyBase = "polaris_precompile"
MetricKeyTime = "polaris_precompile_time"
)
5 changes: 3 additions & 2 deletions cosmos/x/evm/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
package types

const (
StoreKey = "evm"
ModuleName = "evm"
StoreKey = "evm"
ModuleName = "evm"
MetricKeyInsertBlockAndSetHead = "polaris_evm_insert_block_and_set_head"
)

const (
Expand Down
Loading
Loading