Skip to content
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
84 changes: 48 additions & 36 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,45 +58,57 @@ import (
"github.com/ava-labs/libevm/metrics"
"github.com/ava-labs/libevm/trie"
"github.com/ava-labs/libevm/triedb"

// Force libevm metrics of the same name to be registered first.
_ "github.com/ava-labs/libevm/core"
)

// ====== If resolving merge conflicts ======
//
// All calls to metrics.NewRegistered*() have been replaced with
// metrics.GetOrRegister*() and this package's corresponding libevm package
// imported above. Together these ensure that the metric here is the same as the
// one with the same name in libevm.
//
// Note, however, those that have had their types overridden as
// [metrics.Counter].
var (
accountReadTimer = metrics.NewRegisteredCounter("chain/account/reads", nil)
accountHashTimer = metrics.NewRegisteredCounter("chain/account/hashes", nil)
accountUpdateTimer = metrics.NewRegisteredCounter("chain/account/updates", nil)
accountCommitTimer = metrics.NewRegisteredCounter("chain/account/commits", nil)
storageReadTimer = metrics.NewRegisteredCounter("chain/storage/reads", nil)
storageHashTimer = metrics.NewRegisteredCounter("chain/storage/hashes", nil)
storageUpdateTimer = metrics.NewRegisteredCounter("chain/storage/updates", nil)
storageCommitTimer = metrics.NewRegisteredCounter("chain/storage/commits", nil)
snapshotAccountReadTimer = metrics.NewRegisteredCounter("chain/snapshot/account/reads", nil)
snapshotStorageReadTimer = metrics.NewRegisteredCounter("chain/snapshot/storage/reads", nil)
snapshotCommitTimer = metrics.NewRegisteredCounter("chain/snapshot/commits", nil)

triedbCommitTimer = metrics.NewRegisteredCounter("chain/triedb/commits", nil)

blockInsertTimer = metrics.NewRegisteredCounter("chain/block/inserts", nil)
blockInsertCount = metrics.NewRegisteredCounter("chain/block/inserts/count", nil)
blockContentValidationTimer = metrics.NewRegisteredCounter("chain/block/validations/content", nil)
blockStateInitTimer = metrics.NewRegisteredCounter("chain/block/inits/state", nil)
blockExecutionTimer = metrics.NewRegisteredCounter("chain/block/executions", nil)
blockTrieOpsTimer = metrics.NewRegisteredCounter("chain/block/trie", nil)
blockValidationTimer = metrics.NewRegisteredCounter("chain/block/validations/state", nil)
blockWriteTimer = metrics.NewRegisteredCounter("chain/block/writes", nil)

acceptorQueueGauge = metrics.NewRegisteredGauge("chain/acceptor/queue/size", nil)
acceptorWorkTimer = metrics.NewRegisteredCounter("chain/acceptor/work", nil)
acceptorWorkCount = metrics.NewRegisteredCounter("chain/acceptor/work/count", nil)
processedBlockGasUsedCounter = metrics.NewRegisteredCounter("chain/block/gas/used/processed", nil)
acceptedBlockGasUsedCounter = metrics.NewRegisteredCounter("chain/block/gas/used/accepted", nil)
badBlockCounter = metrics.NewRegisteredCounter("chain/block/bad/count", nil)

txUnindexTimer = metrics.NewRegisteredCounter("chain/txs/unindex", nil)
acceptedTxsCounter = metrics.NewRegisteredCounter("chain/txs/accepted", nil)
processedTxsCounter = metrics.NewRegisteredCounter("chain/txs/processed", nil)

acceptedLogsCounter = metrics.NewRegisteredCounter("chain/logs/accepted", nil)
processedLogsCounter = metrics.NewRegisteredCounter("chain/logs/processed", nil)
accountReadTimer = getOrOverrideAsRegisteredCounter("chain/account/reads", nil)
accountHashTimer = getOrOverrideAsRegisteredCounter("chain/account/hashes", nil)
accountUpdateTimer = getOrOverrideAsRegisteredCounter("chain/account/updates", nil)
accountCommitTimer = getOrOverrideAsRegisteredCounter("chain/account/commits", nil)
storageReadTimer = getOrOverrideAsRegisteredCounter("chain/storage/reads", nil)
storageHashTimer = getOrOverrideAsRegisteredCounter("chain/storage/hashes", nil)
storageUpdateTimer = getOrOverrideAsRegisteredCounter("chain/storage/updates", nil)
storageCommitTimer = getOrOverrideAsRegisteredCounter("chain/storage/commits", nil)
snapshotAccountReadTimer = getOrOverrideAsRegisteredCounter("chain/snapshot/account/reads", nil)
snapshotStorageReadTimer = getOrOverrideAsRegisteredCounter("chain/snapshot/storage/reads", nil)
snapshotCommitTimer = getOrOverrideAsRegisteredCounter("chain/snapshot/commits", nil)

triedbCommitTimer = getOrOverrideAsRegisteredCounter("chain/triedb/commits", nil)

blockInsertTimer = metrics.GetOrRegisterCounter("chain/block/inserts", nil)
blockInsertCount = metrics.GetOrRegisterCounter("chain/block/inserts/count", nil)
blockContentValidationTimer = metrics.GetOrRegisterCounter("chain/block/validations/content", nil)
blockStateInitTimer = metrics.GetOrRegisterCounter("chain/block/inits/state", nil)
blockExecutionTimer = metrics.GetOrRegisterCounter("chain/block/executions", nil)
blockTrieOpsTimer = metrics.GetOrRegisterCounter("chain/block/trie", nil)
blockValidationTimer = metrics.GetOrRegisterCounter("chain/block/validations/state", nil)
blockWriteTimer = metrics.GetOrRegisterCounter("chain/block/writes", nil)

acceptorQueueGauge = metrics.GetOrRegisterGauge("chain/acceptor/queue/size", nil)
acceptorWorkTimer = metrics.GetOrRegisterCounter("chain/acceptor/work", nil)
acceptorWorkCount = metrics.GetOrRegisterCounter("chain/acceptor/work/count", nil)
processedBlockGasUsedCounter = metrics.GetOrRegisterCounter("chain/block/gas/used/processed", nil)
acceptedBlockGasUsedCounter = metrics.GetOrRegisterCounter("chain/block/gas/used/accepted", nil)
badBlockCounter = metrics.GetOrRegisterCounter("chain/block/bad/count", nil)

txUnindexTimer = metrics.GetOrRegisterCounter("chain/txs/unindex", nil)
acceptedTxsCounter = metrics.GetOrRegisterCounter("chain/txs/accepted", nil)
processedTxsCounter = metrics.GetOrRegisterCounter("chain/txs/processed", nil)

acceptedLogsCounter = metrics.GetOrRegisterCounter("chain/logs/accepted", nil)
processedLogsCounter = metrics.GetOrRegisterCounter("chain/logs/processed", nil)

ErrRefuseToCorruptArchiver = errors.New("node has operated with pruning disabled, shutting down to prevent missing tries")

Expand Down
27 changes: 27 additions & 0 deletions core/blockchain_ext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// (c) 2024 Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package core

import "github.com/ava-labs/libevm/metrics"

// getOrOverrideAsRegisteredCounter searches for a metric already registered
// with`name`. If a metric is found and it is a Counter, it is returned. If a
// metric is found and it is not a Counter, it is unregistered and replaced with
// a new registered Counter. If no metric is found, a new Counter is constructed
// and registered.
//
// This is necessary for a metric defined in libevm with the same name but a
// different type to what we expect.
func getOrOverrideAsRegisteredCounter(name string, r metrics.Registry) metrics.Counter {
if r == nil {
r = metrics.DefaultRegistry
}

switch c := r.GetOrRegister(name, metrics.NewCounter).(type) {
case metrics.Counter:
return c
default: // `name` must have already been registered to be any other type
r.Unregister(name)
return metrics.NewRegisteredCounter(name, r)
}
}
1 change: 1 addition & 0 deletions core/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func TestMain(m *testing.M) {
opts := []goleak.Option{
// No good way to shut down these goroutines:
goleak.IgnoreTopFunction("github.com/ava-labs/coreth/core/state/snapshot.(*diskLayer).generate"),
goleak.IgnoreTopFunction("github.com/ava-labs/libevm/core.(*txSenderCacher).cache"),
goleak.IgnoreTopFunction("github.com/ava-labs/libevm/metrics.(*meterArbiter).tick"),
goleak.IgnoreTopFunction("github.com/syndtr/goleveldb/leveldb.(*DB).mpoolDrain"),
}
Expand Down
90 changes: 48 additions & 42 deletions core/state/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,49 +55,55 @@ const (
skipGenThreshold = 500 * time.Millisecond
)

// ====== If resolving merge conflicts ======
//
// All calls to metrics.NewRegistered*() have been replaced with
// metrics.GetOrRegister*() and this package's corresponding libevm package
// imported above. Together these ensure that the metric here is the same as the
// one with the same name in libevm.
var (
snapshotCleanAccountHitMeter = metrics.NewRegisteredMeter("state/snapshot/clean/account/hit", nil)
snapshotCleanAccountMissMeter = metrics.NewRegisteredMeter("state/snapshot/clean/account/miss", nil)
snapshotCleanAccountInexMeter = metrics.NewRegisteredMeter("state/snapshot/clean/account/inex", nil)
snapshotCleanAccountReadMeter = metrics.NewRegisteredMeter("state/snapshot/clean/account/read", nil)
snapshotCleanAccountWriteMeter = metrics.NewRegisteredMeter("state/snapshot/clean/account/write", nil)

snapshotCleanStorageHitMeter = metrics.NewRegisteredMeter("state/snapshot/clean/storage/hit", nil)
snapshotCleanStorageMissMeter = metrics.NewRegisteredMeter("state/snapshot/clean/storage/miss", nil)
snapshotCleanStorageInexMeter = metrics.NewRegisteredMeter("state/snapshot/clean/storage/inex", nil)
snapshotCleanStorageReadMeter = metrics.NewRegisteredMeter("state/snapshot/clean/storage/read", nil)
snapshotCleanStorageWriteMeter = metrics.NewRegisteredMeter("state/snapshot/clean/storage/write", nil)

snapshotDirtyAccountHitMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/account/hit", nil)
snapshotDirtyAccountMissMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/account/miss", nil)
snapshotDirtyAccountInexMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/account/inex", nil)
snapshotDirtyAccountReadMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/account/read", nil)
snapshotDirtyAccountWriteMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/account/write", nil)

snapshotDirtyStorageHitMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/storage/hit", nil)
snapshotDirtyStorageMissMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/storage/miss", nil)
snapshotDirtyStorageInexMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/storage/inex", nil)
snapshotDirtyStorageReadMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/storage/read", nil)
snapshotDirtyStorageWriteMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/storage/write", nil)

snapshotDirtyAccountHitDepthHist = metrics.NewRegisteredHistogram("state/snapshot/dirty/account/hit/depth", nil, metrics.NewExpDecaySample(1028, 0.015))
snapshotDirtyStorageHitDepthHist = metrics.NewRegisteredHistogram("state/snapshot/dirty/storage/hit/depth", nil, metrics.NewExpDecaySample(1028, 0.015))

snapshotFlushAccountItemMeter = metrics.NewRegisteredMeter("state/snapshot/flush/account/item", nil)
snapshotFlushAccountSizeMeter = metrics.NewRegisteredMeter("state/snapshot/flush/account/size", nil)
snapshotFlushStorageItemMeter = metrics.NewRegisteredMeter("state/snapshot/flush/storage/item", nil)
snapshotFlushStorageSizeMeter = metrics.NewRegisteredMeter("state/snapshot/flush/storage/size", nil)

snapshotBloomIndexTimer = metrics.NewRegisteredResettingTimer("state/snapshot/bloom/index", nil)
snapshotBloomErrorGauge = metrics.NewRegisteredGaugeFloat64("state/snapshot/bloom/error", nil)

snapshotBloomAccountTrueHitMeter = metrics.NewRegisteredMeter("state/snapshot/bloom/account/truehit", nil)
snapshotBloomAccountFalseHitMeter = metrics.NewRegisteredMeter("state/snapshot/bloom/account/falsehit", nil)
snapshotBloomAccountMissMeter = metrics.NewRegisteredMeter("state/snapshot/bloom/account/miss", nil)

snapshotBloomStorageTrueHitMeter = metrics.NewRegisteredMeter("state/snapshot/bloom/storage/truehit", nil)
snapshotBloomStorageFalseHitMeter = metrics.NewRegisteredMeter("state/snapshot/bloom/storage/falsehit", nil)
snapshotBloomStorageMissMeter = metrics.NewRegisteredMeter("state/snapshot/bloom/storage/miss", nil)
snapshotCleanAccountHitMeter = metrics.GetOrRegisterMeter("state/snapshot/clean/account/hit", nil)
snapshotCleanAccountMissMeter = metrics.GetOrRegisterMeter("state/snapshot/clean/account/miss", nil)
snapshotCleanAccountInexMeter = metrics.GetOrRegisterMeter("state/snapshot/clean/account/inex", nil)
snapshotCleanAccountReadMeter = metrics.GetOrRegisterMeter("state/snapshot/clean/account/read", nil)
snapshotCleanAccountWriteMeter = metrics.GetOrRegisterMeter("state/snapshot/clean/account/write", nil)

snapshotCleanStorageHitMeter = metrics.GetOrRegisterMeter("state/snapshot/clean/storage/hit", nil)
snapshotCleanStorageMissMeter = metrics.GetOrRegisterMeter("state/snapshot/clean/storage/miss", nil)
snapshotCleanStorageInexMeter = metrics.GetOrRegisterMeter("state/snapshot/clean/storage/inex", nil)
snapshotCleanStorageReadMeter = metrics.GetOrRegisterMeter("state/snapshot/clean/storage/read", nil)
snapshotCleanStorageWriteMeter = metrics.GetOrRegisterMeter("state/snapshot/clean/storage/write", nil)

snapshotDirtyAccountHitMeter = metrics.GetOrRegisterMeter("state/snapshot/dirty/account/hit", nil)
snapshotDirtyAccountMissMeter = metrics.GetOrRegisterMeter("state/snapshot/dirty/account/miss", nil)
snapshotDirtyAccountInexMeter = metrics.GetOrRegisterMeter("state/snapshot/dirty/account/inex", nil)
snapshotDirtyAccountReadMeter = metrics.GetOrRegisterMeter("state/snapshot/dirty/account/read", nil)
snapshotDirtyAccountWriteMeter = metrics.GetOrRegisterMeter("state/snapshot/dirty/account/write", nil)

snapshotDirtyStorageHitMeter = metrics.GetOrRegisterMeter("state/snapshot/dirty/storage/hit", nil)
snapshotDirtyStorageMissMeter = metrics.GetOrRegisterMeter("state/snapshot/dirty/storage/miss", nil)
snapshotDirtyStorageInexMeter = metrics.GetOrRegisterMeter("state/snapshot/dirty/storage/inex", nil)
snapshotDirtyStorageReadMeter = metrics.GetOrRegisterMeter("state/snapshot/dirty/storage/read", nil)
snapshotDirtyStorageWriteMeter = metrics.GetOrRegisterMeter("state/snapshot/dirty/storage/write", nil)

snapshotDirtyAccountHitDepthHist = metrics.GetOrRegisterHistogram("state/snapshot/dirty/account/hit/depth", nil, metrics.NewExpDecaySample(1028, 0.015))
snapshotDirtyStorageHitDepthHist = metrics.GetOrRegisterHistogram("state/snapshot/dirty/storage/hit/depth", nil, metrics.NewExpDecaySample(1028, 0.015))

snapshotFlushAccountItemMeter = metrics.GetOrRegisterMeter("state/snapshot/flush/account/item", nil)
snapshotFlushAccountSizeMeter = metrics.GetOrRegisterMeter("state/snapshot/flush/account/size", nil)
snapshotFlushStorageItemMeter = metrics.GetOrRegisterMeter("state/snapshot/flush/storage/item", nil)
snapshotFlushStorageSizeMeter = metrics.GetOrRegisterMeter("state/snapshot/flush/storage/size", nil)

snapshotBloomIndexTimer = metrics.GetOrRegisterResettingTimer("state/snapshot/bloom/index", nil)
snapshotBloomErrorGauge = metrics.GetOrRegisterGaugeFloat64("state/snapshot/bloom/error", nil)

snapshotBloomAccountTrueHitMeter = metrics.GetOrRegisterMeter("state/snapshot/bloom/account/truehit", nil)
snapshotBloomAccountFalseHitMeter = metrics.GetOrRegisterMeter("state/snapshot/bloom/account/falsehit", nil)
snapshotBloomAccountMissMeter = metrics.GetOrRegisterMeter("state/snapshot/bloom/account/miss", nil)

snapshotBloomStorageTrueHitMeter = metrics.GetOrRegisterMeter("state/snapshot/bloom/storage/truehit", nil)
snapshotBloomStorageFalseHitMeter = metrics.GetOrRegisterMeter("state/snapshot/bloom/storage/falsehit", nil)
snapshotBloomStorageMissMeter = metrics.GetOrRegisterMeter("state/snapshot/bloom/storage/miss", nil)

// ErrSnapshotStale is returned from data accessors if the underlying snapshot
// layer had been invalidated due to the chain progressing forward far enough
Expand Down
Loading
Loading