From 9f5caf8feaa97da09b672260b134bd5bfab2dd08 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Sun, 5 Jan 2020 11:12:48 -0800 Subject: [PATCH] total and target balances metrics (#4414) --- beacon-chain/blockchain/forkchoice/BUILD.bazel | 1 + beacon-chain/blockchain/forkchoice/metrics.go | 14 ++++++++++++++ beacon-chain/core/epoch/precompute/attestation.go | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/beacon-chain/blockchain/forkchoice/BUILD.bazel b/beacon-chain/blockchain/forkchoice/BUILD.bazel index 2965c1b66..3695a0446 100644 --- a/beacon-chain/blockchain/forkchoice/BUILD.bazel +++ b/beacon-chain/blockchain/forkchoice/BUILD.bazel @@ -15,6 +15,7 @@ go_library( deps = [ "//beacon-chain/cache:go_default_library", "//beacon-chain/core/blocks:go_default_library", + "//beacon-chain/core/epoch/precompute:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/state:go_default_library", "//beacon-chain/db:go_default_library", diff --git a/beacon-chain/blockchain/forkchoice/metrics.go b/beacon-chain/blockchain/forkchoice/metrics.go index 01e1695d4..8d915f367 100644 --- a/beacon-chain/blockchain/forkchoice/metrics.go +++ b/beacon-chain/blockchain/forkchoice/metrics.go @@ -3,6 +3,7 @@ package forkchoice import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" + "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" @@ -61,6 +62,14 @@ var ( Name: "current_eth1_data_deposit_count", Help: "The current eth1 deposit count in the last processed state eth1data field.", }) + totalEligibleBalances = promauto.NewGauge(prometheus.GaugeOpts{ + Name: "total_eligible_balances", + Help: "The total amount of ether, in gwei, that has been used in voting attestation target of previous epoch", + }) + totalVotedTargetBalances = promauto.NewGauge(prometheus.GaugeOpts{ + Name: "total_voted_target_balances", + Help: "The total amount of ether, in gwei, that is eligible for voting of previous epoch", + }) ) func reportEpochMetrics(state *pb.BeaconState) { @@ -144,4 +153,9 @@ func reportEpochMetrics(state *pb.BeaconState) { if state.Eth1Data != nil { currentEth1DataDepositCount.Set(float64(state.Eth1Data.DepositCount)) } + + if precompute.Balances != nil { + totalEligibleBalances.Set(float64(precompute.Balances.PrevEpoch)) + totalVotedTargetBalances.Set(float64(precompute.Balances.PrevEpochTargetAttesters)) + } } diff --git a/beacon-chain/core/epoch/precompute/attestation.go b/beacon-chain/core/epoch/precompute/attestation.go index bd5d2fbc5..fdaf5e740 100644 --- a/beacon-chain/core/epoch/precompute/attestation.go +++ b/beacon-chain/core/epoch/precompute/attestation.go @@ -11,6 +11,10 @@ import ( "go.opencensus.io/trace" ) +// Balances stores balances such as prev/current total validator balances, attested balances and more. +// It's used for metrics reporting. +var Balances *Balance + // ProcessAttestations process the attestations in state and update individual validator's pre computes, // it also tracks and updates epoch attesting balances. func ProcessAttestations( @@ -48,6 +52,7 @@ func ProcessAttestations( } bp = UpdateBalance(vp, bp) + Balances = bp return vp, bp, nil }