From bb60b2f5235e798f027f79b8fa5fbfeb69a9ee58 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Thu, 13 Feb 2020 14:52:35 -0800 Subject: [PATCH] Add balances to voting summary log (#4857) --- WORKSPACE | 2 +- .../core/epoch/precompute/reward_penalty.go | 11 ++++++++++ beacon-chain/core/epoch/precompute/type.go | 4 ++++ beacon-chain/rpc/beacon/validators.go | 20 ++++++++++++------- shared/testutil/block.go | 2 +- ...thub_prysmaticlabs_ethereumapis-tags.patch | 10 +++++----- validator/client/validator_metrics.go | 9 +++++++-- 7 files changed, 42 insertions(+), 16 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index baf11c3dc7..4bd73d4e61 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1272,7 +1272,7 @@ go_repository( go_repository( name = "com_github_prysmaticlabs_ethereumapis", - commit = "9e66dfce9956682649fedac730eb5aa2d5973456", + commit = "79d7a99b999d1873431b2ae56f1e6ea6e730242f", importpath = "github.com/prysmaticlabs/ethereumapis", patch_args = ["-p1"], patches = [ diff --git a/beacon-chain/core/epoch/precompute/reward_penalty.go b/beacon-chain/core/epoch/precompute/reward_penalty.go index aadd2e3c4e..4efcc822d4 100644 --- a/beacon-chain/core/epoch/precompute/reward_penalty.go +++ b/beacon-chain/core/epoch/precompute/reward_penalty.go @@ -36,13 +36,24 @@ func ProcessRewardsAndPenaltiesPrecompute( return nil, errors.Wrap(err, "could not get attestation delta") } for i := 0; i < numOfVals; i++ { + vp[i].BeforeEpochTransitionBalance, err = state.BalanceAtIndex(uint64(i)) + if err != nil { + return nil, errors.Wrap(err, "could not get validator balance before epoch") + } + if err := helpers.IncreaseBalance(state, uint64(i), attsRewards[i]+proposerRewards[i]); err != nil { return nil, err } if err := helpers.DecreaseBalance(state, uint64(i), attsPenalties[i]); err != nil { return nil, err } + + vp[i].AfterEpochTransitionBalance, err = state.BalanceAtIndex(uint64(i)) + if err != nil { + return nil, errors.Wrap(err, "could not get validator balance after epoch") + } } + return state, nil } diff --git a/beacon-chain/core/epoch/precompute/type.go b/beacon-chain/core/epoch/precompute/type.go index 467c227018..503ed99a14 100644 --- a/beacon-chain/core/epoch/precompute/type.go +++ b/beacon-chain/core/epoch/precompute/type.go @@ -31,6 +31,10 @@ type Validator struct { InclusionDistance uint64 // ProposerIndex is the index of proposer at slot where this validator's attestation was included. ProposerIndex uint64 + // BeforeEpochTransitionBalance is the validator balance prior to epoch transition. + BeforeEpochTransitionBalance uint64 + // AfterEpochTransitionBalance is the validator balance after epoch transition. + AfterEpochTransitionBalance uint64 } // Balance stores the pre computation of the total participated balances for a given epoch diff --git a/beacon-chain/rpc/beacon/validators.go b/beacon-chain/rpc/beacon/validators.go index 4c9f717412..ea90212daa 100644 --- a/beacon-chain/rpc/beacon/validators.go +++ b/beacon-chain/rpc/beacon/validators.go @@ -584,6 +584,8 @@ func (bs *Server) GetValidatorPerformance( validatorSummary := state.ValidatorSummary + beforeTransitionBalances := make([]uint64, 0) + afterTransitionBalances := make([]uint64, 0) effectiveBalances := make([]uint64, 0) inclusionSlots := make([]uint64, 0) inclusionDistances := make([]uint64, 0) @@ -605,6 +607,8 @@ func (bs *Server) GetValidatorPerformance( } effectiveBalances = append(effectiveBalances, validatorSummary[idx].CurrentEpochEffectiveBalance) + beforeTransitionBalances = append(beforeTransitionBalances, validatorSummary[idx].BeforeEpochTransitionBalance) + afterTransitionBalances = append(afterTransitionBalances, validatorSummary[idx].AfterEpochTransitionBalance) inclusionSlots = append(inclusionSlots, validatorSummary[idx].InclusionSlot) inclusionDistances = append(inclusionDistances, validatorSummary[idx].InclusionDistance) correctlyVotedSource = append(correctlyVotedSource, validatorSummary[idx].IsPrevEpochAttester) @@ -613,13 +617,15 @@ func (bs *Server) GetValidatorPerformance( } return ðpb.ValidatorPerformanceResponse{ - InclusionSlots: inclusionSlots, - InclusionDistances: inclusionDistances, - CorrectlyVotedSource: correctlyVotedSource, - CorrectlyVotedTarget: correctlyVotedTarget, - CorrectlyVotedHead: correctlyVotedHead, - Balances: effectiveBalances, - MissingValidators: missingValidators, + InclusionSlots: inclusionSlots, + InclusionDistances: inclusionDistances, + CorrectlyVotedSource: correctlyVotedSource, + CorrectlyVotedTarget: correctlyVotedTarget, + CorrectlyVotedHead: correctlyVotedHead, + CurrentEffectiveBalances: effectiveBalances, + BalancesBeforeEpochTransition: beforeTransitionBalances, + BalancesAfterEpochTransition: afterTransitionBalances, + MissingValidators: missingValidators, }, nil } diff --git a/shared/testutil/block.go b/shared/testutil/block.go index 9ad3bd24e8..b13e214c04 100644 --- a/shared/testutil/block.go +++ b/shared/testutil/block.go @@ -291,7 +291,7 @@ func generateAttesterSlashings( // for the same data with their aggregation bits split uniformly. // // If you request 4 attestations, but there are 8 committees, you will get 4 fully aggregated attestations. -func GenerateAttestations(bState *stateTrie.BeaconState, privs []*bls.SecretKey, numToGen uint64, slot uint64, randomRoot bool, ) ([]*ethpb.Attestation, error) { +func GenerateAttestations(bState *stateTrie.BeaconState, privs []*bls.SecretKey, numToGen uint64, slot uint64, randomRoot bool) ([]*ethpb.Attestation, error) { currentEpoch := helpers.SlotToEpoch(slot) attestations := []*ethpb.Attestation{} generateHeadState := false diff --git a/third_party/com_github_prysmaticlabs_ethereumapis-tags.patch b/third_party/com_github_prysmaticlabs_ethereumapis-tags.patch index 0826b344af..a8d38cec6a 100644 --- a/third_party/com_github_prysmaticlabs_ethereumapis-tags.patch +++ b/third_party/com_github_prysmaticlabs_ethereumapis-tags.patch @@ -262,7 +262,7 @@ index 2ce5c34..4cbb276 100644 + bytes signature = 3 [(gogoproto.moretags) = "ssz-size:\"96\""]; } diff --git a/eth/v1alpha1/beacon_chain.proto b/eth/v1alpha1/beacon_chain.proto -index 731fa45..3a9092c 100644 +index 5ee000f..0f5f69c 100644 --- a/eth/v1alpha1/beacon_chain.proto +++ b/eth/v1alpha1/beacon_chain.proto @@ -15,6 +15,7 @@ syntax = "proto3"; @@ -369,7 +369,7 @@ index 731fa45..3a9092c 100644 // Indices of validators ejected in the given epoch. repeated uint64 ejected_indices = 9; -@@ -591,11 +591,11 @@ message ValidatorQueue { +@@ -597,11 +597,11 @@ message ValidatorQueue { // Ordered list of 48 byte public keys awaiting activation. 0th index is the // next key to be processed. @@ -383,7 +383,7 @@ index 731fa45..3a9092c 100644 } message ListValidatorAssignmentsRequest { -@@ -607,7 +607,7 @@ message ListValidatorAssignmentsRequest { +@@ -613,7 +613,7 @@ message ListValidatorAssignmentsRequest { bool genesis = 2; } // 48 byte validator public keys to filter assignments for the given epoch. @@ -392,7 +392,7 @@ index 731fa45..3a9092c 100644 // Validator indicies to filter assignments for the given epoch. repeated uint64 indices = 4; -@@ -642,7 +642,7 @@ message ValidatorAssignments { +@@ -648,7 +648,7 @@ message ValidatorAssignments { uint64 proposer_slot = 4; // 48 byte BLS public key. @@ -402,7 +402,7 @@ index 731fa45..3a9092c 100644 // The epoch for which this set of validator assignments is valid. diff --git a/eth/v1alpha1/validator.proto b/eth/v1alpha1/validator.proto -index 9e19670..440e193 100644 +index c0ab286..428875b 100644 --- a/eth/v1alpha1/validator.proto +++ b/eth/v1alpha1/validator.proto @@ -15,6 +15,7 @@ syntax = "proto3"; diff --git a/validator/client/validator_metrics.go b/validator/client/validator_metrics.go index 15864a5106..5670487b9c 100644 --- a/validator/client/validator_metrics.go +++ b/validator/client/validator_metrics.go @@ -75,9 +75,11 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot uint64) if slot < params.BeaconConfig().SlotsPerEpoch { v.prevBalance[bytesutil.ToBytes48(pkey)] = params.BeaconConfig().MaxEffectiveBalance } - newBalance := float64(resp.Balances[i]) / float64(params.BeaconConfig().GweiPerEth) + newBalance := float64(resp.BalancesAfterEpochTransition[i]) / float64(params.BeaconConfig().GweiPerEth) if v.prevBalance[bytesutil.ToBytes48(pkey)] > 0 { + prevBalance := float64(resp.BalancesBeforeEpochTransition[i]) / float64(params.BeaconConfig().GweiPerEth) + percentNet := (newBalance - prevBalance) / prevBalance log.WithFields(logrus.Fields{ "epoch": (slot / params.BeaconConfig().SlotsPerEpoch) - 1, "correctlyVotedSource": resp.CorrectlyVotedSource[i], @@ -85,6 +87,9 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot uint64) "correctlyVotedHead": resp.CorrectlyVotedHead[i], "inclusionSlot": resp.InclusionSlots[i], "inclusionDistance": resp.InclusionDistances[i], + "oldBalance": prevBalance, + "newBalance": newBalance, + "percentChange": fmt.Sprintf("%.5f%%", percentNet*100), }).Info("Previous epoch voting summary") if v.emitAccountMetrics { validatorBalancesGaugeVec.WithLabelValues(pubKey).Set(newBalance) @@ -103,7 +108,7 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot uint64) if resp.CorrectlyVotedHead[i] { votedHead++ } - v.prevBalance[bytesutil.ToBytes48(pkey)] = resp.Balances[i] + v.prevBalance[bytesutil.ToBytes48(pkey)] = resp.BalancesBeforeEpochTransition[i] } log.WithFields(logrus.Fields{