Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics for root calculation and signature wait #133

Merged
merged 4 commits into from
Apr 5, 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
4 changes: 4 additions & 0 deletions chain/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,12 @@ func (b *StatelessBlock) innerVerify(ctx context.Context) (merkledb.TrieView, er
}

// Compute state root
start := time.Now()
computedRoot, err := state.GetMerkleRoot(ctx)
if err != nil {
return nil, err
}
b.vm.RecordRootCalculated(time.Since(start))
if b.StateRoot != computedRoot {
return nil, fmt.Errorf(
"%w: expected=%s found=%s",
Expand All @@ -605,9 +607,11 @@ func (b *StatelessBlock) innerVerify(ctx context.Context) (merkledb.TrieView, er
// Ensure signatures are verified
_, sspan := b.vm.Tracer().Start(ctx, "StatelessBlock.Verify.WaitSignatures")
defer sspan.End()
start = time.Now()
if err := b.sigJob.Wait(); err != nil {
return nil, err
}
b.vm.RecordWaitSignatures(time.Since(start))
return state, nil
}

Expand Down
8 changes: 8 additions & 0 deletions chain/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package chain

import (
"context"
"time"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
Expand Down Expand Up @@ -62,6 +63,13 @@ type VM interface {
// and false if the sync completed with the previous root.
UpdateSyncTarget(*StatelessBlock) (bool, error)
StateReady() bool

// Record the duration of various operations to populate chain metrics
//
// If there was a long-lived [Chain] struct, we would store metrics for chain
// there.
RecordRootCalculated(t time.Duration) // only called in Verify
RecordWaitSignatures(t time.Duration) // only called in Verify
}

type Mempool interface {
Expand Down
27 changes: 26 additions & 1 deletion vm/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package vm

import (
"github.com/ava-labs/avalanchego/utils/metric"
"github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/prometheus/client_golang/prometheus"
)
Expand All @@ -16,9 +17,32 @@ type Metrics struct {
txsAccepted prometheus.Counter
decisionsRPCConnections prometheus.Gauge
blocksRPCConnections prometheus.Gauge
rootCalculated metric.Averager
waitSignatures metric.Averager
}

func newMetrics() (*prometheus.Registry, *Metrics, error) {
r := prometheus.NewRegistry()

rootCalculated, err := metric.NewAverager(
"chain",
"root_calculated",
"time spent calculating the state root in verify",
r,
)
if err != nil {
return nil, nil, err
}
waitSignatures, err := metric.NewAverager(
"chain",
"wait_signatures",
"time spent waiting for signature verification in verify",
r,
)
if err != nil {
return nil, nil, err
}

m := &Metrics{
unitsVerified: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "chain",
Expand Down Expand Up @@ -55,8 +79,9 @@ func newMetrics() (*prometheus.Registry, *Metrics, error) {
Name: "blocks_rpc_connections",
Help: "number of open blocks connections",
}),
rootCalculated: rootCalculated,
waitSignatures: waitSignatures,
}
r := prometheus.NewRegistry()
errs := wrappers.Errs{}
errs.Add(
r.Register(m.unitsVerified),
Expand Down
8 changes: 8 additions & 0 deletions vm/resolutions.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,11 @@ func (vm *VM) StateSyncEnabled(ctx context.Context) (bool, error) {
func (vm *VM) StateManager() chain.StateManager {
return vm.c.StateManager()
}

func (vm *VM) RecordRootCalculated(t time.Duration) {
vm.metrics.rootCalculated.Observe(float64(t))
}

func (vm *VM) RecordWaitSignatures(t time.Duration) {
vm.metrics.waitSignatures.Observe(float64(t))
}