mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
Update state metrics on save state (#2083)
* Update state metrics on save state * fix tests
This commit is contained in:
parent
6012d0a5d1
commit
ac7d5a7780
@ -491,6 +491,7 @@ func TestLMDGhost_TrivialHeadUpdate(t *testing.T) {
|
||||
state := &pb.BeaconState{
|
||||
Slot: 10,
|
||||
ValidatorBalances: []uint64{params.BeaconConfig().MaxDepositAmount},
|
||||
ValidatorRegistry: []*pb.Validator{{}},
|
||||
}
|
||||
|
||||
chainService := setupBeaconChain(t, false, beaconDB, true, nil)
|
||||
@ -548,6 +549,7 @@ func TestLMDGhost_3WayChainSplitsSameHeight(t *testing.T) {
|
||||
params.BeaconConfig().MaxDepositAmount,
|
||||
params.BeaconConfig().MaxDepositAmount,
|
||||
params.BeaconConfig().MaxDepositAmount},
|
||||
ValidatorRegistry: []*pb.Validator{{}, {}, {}, {}},
|
||||
}
|
||||
|
||||
chainService := setupBeaconChain(t, false, beaconDB, true, nil)
|
||||
@ -631,6 +633,7 @@ func TestLMDGhost_2WayChainSplitsDiffHeight(t *testing.T) {
|
||||
params.BeaconConfig().MaxDepositAmount,
|
||||
params.BeaconConfig().MaxDepositAmount,
|
||||
params.BeaconConfig().MaxDepositAmount},
|
||||
ValidatorRegistry: []*pb.Validator{{}, {}, {}, {}},
|
||||
}
|
||||
|
||||
chainService := setupBeaconChain(t, false, beaconDB, true, nil)
|
||||
|
@ -3,7 +3,6 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"metrics.go",
|
||||
"state.go",
|
||||
"transition.go",
|
||||
],
|
||||
@ -20,8 +19,6 @@ go_library(
|
||||
"//shared/featureconfig:go_default_library",
|
||||
"//shared/hashutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@io_opencensus_go//trace:go_default_library",
|
||||
],
|
||||
@ -30,7 +27,6 @@ go_library(
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"metrics_test.go",
|
||||
"state_test.go",
|
||||
"transition_test.go",
|
||||
],
|
||||
@ -43,6 +39,5 @@ go_test(
|
||||
"//shared/forkutil:go_default_library",
|
||||
"//shared/hashutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus/testutil:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -1,33 +0,0 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/testutil"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
)
|
||||
|
||||
func TestReportEpochTransitionMetrics_validatorBalances(t *testing.T) {
|
||||
state := &pb.BeaconState{
|
||||
ValidatorBalances: []uint64{1, 15},
|
||||
ValidatorRegistry: []*pb.Validator{
|
||||
{Pubkey: []byte{1}},
|
||||
{Pubkey: []byte{2}},
|
||||
},
|
||||
}
|
||||
|
||||
reportEpochTransitionMetrics(state)
|
||||
expectedMetadata := `
|
||||
# HELP state_validator_balances Balances of validators, updated on epoch transition
|
||||
# TYPE state_validator_balances gauge
|
||||
`
|
||||
expectedValues := `
|
||||
state_validator_balances{validator="0x01"} 1
|
||||
state_validator_balances{validator="0x02"} 15
|
||||
`
|
||||
expected := expectedMetadata + expectedValues
|
||||
if err := testutil.CollectAndCompare(validatorBalancesGauge, strings.NewReader(expected)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
@ -466,7 +466,5 @@ func ProcessEpoch(ctx context.Context, state *pb.BeaconState, config *Transition
|
||||
log.Infof("Validator balances: %v", state.ValidatorBalances)
|
||||
}
|
||||
|
||||
// Report interesting metrics.
|
||||
reportEpochTransitionMetrics(state)
|
||||
return state, nil
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ go_library(
|
||||
"schema.go",
|
||||
"setup_db.go",
|
||||
"state.go",
|
||||
"state_metrics.go",
|
||||
"validator.go",
|
||||
"verify_contract.go",
|
||||
],
|
||||
|
@ -148,6 +148,7 @@ func (db *BeaconDB) SaveState(beaconState *pb.BeaconState) error {
|
||||
return err
|
||||
}
|
||||
stateBytes.Set(float64(len(beaconStateEnc)))
|
||||
reportStateMetrics(beaconState)
|
||||
return chainInfo.Put(stateLookupKey, beaconStateEnc)
|
||||
})
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package state
|
||||
package db
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
@ -34,7 +34,7 @@ var (
|
||||
})
|
||||
)
|
||||
|
||||
func reportEpochTransitionMetrics(state *pb.BeaconState) {
|
||||
func reportStateMetrics(state *pb.BeaconState) {
|
||||
// Validator balances
|
||||
for i, bal := range state.ValidatorBalances {
|
||||
validatorBalancesGauge.WithLabelValues(
|
Loading…
Reference in New Issue
Block a user