Skip to content

Commit

Permalink
Add balances to voting summary log (prysmaticlabs#4857)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain authored and cryptomental committed Feb 28, 2020
1 parent 1c6c63d commit b1b7fec
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 16 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ go_repository(
go_repository(
name = "com_github_prysmaticlabs_ethereumapis",
commit = "9e66dfce9956682649fedac730eb5aa2d5973456",
commit = "79d7a99b999d1873431b2ae56f1e6ea6e730242f",
importpath = "github.com/prysmaticlabs/ethereumapis",
patch_args = ["-p1"],
patches = [
Expand Down
11 changes: 11 additions & 0 deletions beacon-chain/core/epoch/precompute/reward_penalty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions beacon-chain/core/epoch/precompute/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions beacon-chain/rpc/beacon/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion shared/testutil/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions third_party/com_github_prysmaticlabs_ethereumapis-tags.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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";
Expand Down
9 changes: 7 additions & 2 deletions validator/client/validator_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,21 @@ 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],
"correctlyVotedTarget": resp.CorrectlyVotedTarget[i],
"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)
Expand All @@ -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{
Expand Down

0 comments on commit b1b7fec

Please sign in to comment.