Add balances to voting summary log (#4857)

This commit is contained in:
terence tsao
2020-02-13 14:52:35 -08:00
committed by GitHub
parent 4072eb711f
commit bb60b2f523
7 changed files with 42 additions and 16 deletions

View File

@@ -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 = [

View File

@@ -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
}

View File

@@ -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

View File

@@ -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 &ethpb.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
}

View File

@@ -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

View File

@@ -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";

View File

@@ -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{