prysm-pulse/validator/client/metrics_test.go

172 lines
6.6 KiB
Go
Raw Normal View History

Show overall validator results in addition to epoch specific results (#6492) * Add aggregate stats struct to validator struct. Log aggregate voting summary from beginning of node startup. * Refactoring out to function UpdateLogAggregateStats which updates and logs aggregate statistics * Changes to spelling. More refactoring so that the rest of aggregate stats are moved to UpdateLogAggregateStats * Bugfix - moved startBalance initialization out of if. * Remove a print debug. Spelling adjustment. * Minor refactoring/grammar changes * Renaming variables for consistency. * Address linter feedback: omit 2nd value from range over map as values were not being used. * Address feedback from PR re comments. Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Addressing feedback from terencechain in PR. (name changes) * Addressing feedback from terencechain in PR. * Create test for UpdateLogAggregateStats() * Changed comment regarding "numberOfEpochs" log * go fmt metrics_test.go * bazel run //:gazelle -- fix * fix typos * Improved the code to detect the last iteration of the range responses loop * Merge branch 'master' into tempIssue4987 * For both previous Epoch and total runtime statistics, do not count non-included attestations for "correctly" statistics. * Update wording in since-launch logging Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Store first logged epoch in startEpoch and appropriately adjust calculations. Initialize startEpoch to ^uint64(0). * Merge branch 'master' into tempIssue4987 * Update validator/client/metrics.go * Update validator/client/metrics.go * Update validator/client/validator.go * Update validator/client/metrics_test.go * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987
2020-07-07 19:23:56 +00:00
package client
import (
"testing"
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params"
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/time/slots"
Show overall validator results in addition to epoch specific results (#6492) * Add aggregate stats struct to validator struct. Log aggregate voting summary from beginning of node startup. * Refactoring out to function UpdateLogAggregateStats which updates and logs aggregate statistics * Changes to spelling. More refactoring so that the rest of aggregate stats are moved to UpdateLogAggregateStats * Bugfix - moved startBalance initialization out of if. * Remove a print debug. Spelling adjustment. * Minor refactoring/grammar changes * Renaming variables for consistency. * Address linter feedback: omit 2nd value from range over map as values were not being used. * Address feedback from PR re comments. Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Addressing feedback from terencechain in PR. (name changes) * Addressing feedback from terencechain in PR. * Create test for UpdateLogAggregateStats() * Changed comment regarding "numberOfEpochs" log * go fmt metrics_test.go * bazel run //:gazelle -- fix * fix typos * Improved the code to detect the last iteration of the range responses loop * Merge branch 'master' into tempIssue4987 * For both previous Epoch and total runtime statistics, do not count non-included attestations for "correctly" statistics. * Update wording in since-launch logging Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Store first logged epoch in startEpoch and appropriately adjust calculations. Initialize startEpoch to ^uint64(0). * Merge branch 'master' into tempIssue4987 * Update validator/client/metrics.go * Update validator/client/metrics.go * Update validator/client/validator.go * Update validator/client/metrics_test.go * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987
2020-07-07 19:23:56 +00:00
logTest "github.com/sirupsen/logrus/hooks/test"
)
func TestUpdateLogAggregateStats(t *testing.T) {
v := &validator{
logValidatorBalances: true,
startBalances: make(map[[fieldparams.BLSPubkeyLength]byte]uint64),
prevBalance: make(map[[fieldparams.BLSPubkeyLength]byte]uint64),
Show overall validator results in addition to epoch specific results (#6492) * Add aggregate stats struct to validator struct. Log aggregate voting summary from beginning of node startup. * Refactoring out to function UpdateLogAggregateStats which updates and logs aggregate statistics * Changes to spelling. More refactoring so that the rest of aggregate stats are moved to UpdateLogAggregateStats * Bugfix - moved startBalance initialization out of if. * Remove a print debug. Spelling adjustment. * Minor refactoring/grammar changes * Renaming variables for consistency. * Address linter feedback: omit 2nd value from range over map as values were not being used. * Address feedback from PR re comments. Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Addressing feedback from terencechain in PR. (name changes) * Addressing feedback from terencechain in PR. * Create test for UpdateLogAggregateStats() * Changed comment regarding "numberOfEpochs" log * go fmt metrics_test.go * bazel run //:gazelle -- fix * fix typos * Improved the code to detect the last iteration of the range responses loop * Merge branch 'master' into tempIssue4987 * For both previous Epoch and total runtime statistics, do not count non-included attestations for "correctly" statistics. * Update wording in since-launch logging Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Store first logged epoch in startEpoch and appropriately adjust calculations. Initialize startEpoch to ^uint64(0). * Merge branch 'master' into tempIssue4987 * Update validator/client/metrics.go * Update validator/client/metrics.go * Update validator/client/validator.go * Update validator/client/metrics_test.go * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987
2020-07-07 19:23:56 +00:00
voteStats: voteStats{
startEpoch: 0, // this would otherwise have been previously set in LogValidatorGainsAndLosses()
Show overall validator results in addition to epoch specific results (#6492) * Add aggregate stats struct to validator struct. Log aggregate voting summary from beginning of node startup. * Refactoring out to function UpdateLogAggregateStats which updates and logs aggregate statistics * Changes to spelling. More refactoring so that the rest of aggregate stats are moved to UpdateLogAggregateStats * Bugfix - moved startBalance initialization out of if. * Remove a print debug. Spelling adjustment. * Minor refactoring/grammar changes * Renaming variables for consistency. * Address linter feedback: omit 2nd value from range over map as values were not being used. * Address feedback from PR re comments. Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Addressing feedback from terencechain in PR. (name changes) * Addressing feedback from terencechain in PR. * Create test for UpdateLogAggregateStats() * Changed comment regarding "numberOfEpochs" log * go fmt metrics_test.go * bazel run //:gazelle -- fix * fix typos * Improved the code to detect the last iteration of the range responses loop * Merge branch 'master' into tempIssue4987 * For both previous Epoch and total runtime statistics, do not count non-included attestations for "correctly" statistics. * Update wording in since-launch logging Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Store first logged epoch in startEpoch and appropriately adjust calculations. Initialize startEpoch to ^uint64(0). * Merge branch 'master' into tempIssue4987 * Update validator/client/metrics.go * Update validator/client/metrics.go * Update validator/client/validator.go * Update validator/client/metrics_test.go * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987
2020-07-07 19:23:56 +00:00
},
}
pubKeyBytes := [][fieldparams.BLSPubkeyLength]byte{
Show overall validator results in addition to epoch specific results (#6492) * Add aggregate stats struct to validator struct. Log aggregate voting summary from beginning of node startup. * Refactoring out to function UpdateLogAggregateStats which updates and logs aggregate statistics * Changes to spelling. More refactoring so that the rest of aggregate stats are moved to UpdateLogAggregateStats * Bugfix - moved startBalance initialization out of if. * Remove a print debug. Spelling adjustment. * Minor refactoring/grammar changes * Renaming variables for consistency. * Address linter feedback: omit 2nd value from range over map as values were not being used. * Address feedback from PR re comments. Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Addressing feedback from terencechain in PR. (name changes) * Addressing feedback from terencechain in PR. * Create test for UpdateLogAggregateStats() * Changed comment regarding "numberOfEpochs" log * go fmt metrics_test.go * bazel run //:gazelle -- fix * fix typos * Improved the code to detect the last iteration of the range responses loop * Merge branch 'master' into tempIssue4987 * For both previous Epoch and total runtime statistics, do not count non-included attestations for "correctly" statistics. * Update wording in since-launch logging Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Store first logged epoch in startEpoch and appropriately adjust calculations. Initialize startEpoch to ^uint64(0). * Merge branch 'master' into tempIssue4987 * Update validator/client/metrics.go * Update validator/client/metrics.go * Update validator/client/validator.go * Update validator/client/metrics_test.go * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987
2020-07-07 19:23:56 +00:00
bytesutil.ToBytes48([]byte("000000000000000000000000000000000000000012345678")),
bytesutil.ToBytes48([]byte("000000000000000000000000000000000000000099999999")),
bytesutil.ToBytes48([]byte("000000000000000000000000000000000000000055555555")),
}
v.startBalances[pubKeyBytes[0]] = uint64(32100000000)
v.startBalances[pubKeyBytes[1]] = uint64(32200000000)
v.startBalances[pubKeyBytes[2]] = uint64(33000000000)
responses := []*ethpb.ValidatorPerformanceResponse{
{
PublicKeys: [][]byte{
bytesutil.FromBytes48(pubKeyBytes[0]),
bytesutil.FromBytes48(pubKeyBytes[1]),
bytesutil.FromBytes48(pubKeyBytes[2]),
},
InclusionSlots: []types.Slot{types.Slot(^uint64(0)), 10, 11}, // exact slot doesn't matter, only if it is == or != ^uint64(0)
InclusionDistances: []types.Slot{0, 5, 2},
Show overall validator results in addition to epoch specific results (#6492) * Add aggregate stats struct to validator struct. Log aggregate voting summary from beginning of node startup. * Refactoring out to function UpdateLogAggregateStats which updates and logs aggregate statistics * Changes to spelling. More refactoring so that the rest of aggregate stats are moved to UpdateLogAggregateStats * Bugfix - moved startBalance initialization out of if. * Remove a print debug. Spelling adjustment. * Minor refactoring/grammar changes * Renaming variables for consistency. * Address linter feedback: omit 2nd value from range over map as values were not being used. * Address feedback from PR re comments. Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Addressing feedback from terencechain in PR. (name changes) * Addressing feedback from terencechain in PR. * Create test for UpdateLogAggregateStats() * Changed comment regarding "numberOfEpochs" log * go fmt metrics_test.go * bazel run //:gazelle -- fix * fix typos * Improved the code to detect the last iteration of the range responses loop * Merge branch 'master' into tempIssue4987 * For both previous Epoch and total runtime statistics, do not count non-included attestations for "correctly" statistics. * Update wording in since-launch logging Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Store first logged epoch in startEpoch and appropriately adjust calculations. Initialize startEpoch to ^uint64(0). * Merge branch 'master' into tempIssue4987 * Update validator/client/metrics.go * Update validator/client/metrics.go * Update validator/client/validator.go * Update validator/client/metrics_test.go * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987
2020-07-07 19:23:56 +00:00
CorrectlyVotedHead: []bool{false, true, false},
CorrectlyVotedSource: []bool{false, true, true},
CorrectlyVotedTarget: []bool{false, true, true},
},
{
PublicKeys: [][]byte{
bytesutil.FromBytes48(pubKeyBytes[0]),
bytesutil.FromBytes48(pubKeyBytes[1]),
bytesutil.FromBytes48(pubKeyBytes[2]),
},
InclusionSlots: []types.Slot{33, 34, 35},
InclusionDistances: []types.Slot{1, 2, 3},
Show overall validator results in addition to epoch specific results (#6492) * Add aggregate stats struct to validator struct. Log aggregate voting summary from beginning of node startup. * Refactoring out to function UpdateLogAggregateStats which updates and logs aggregate statistics * Changes to spelling. More refactoring so that the rest of aggregate stats are moved to UpdateLogAggregateStats * Bugfix - moved startBalance initialization out of if. * Remove a print debug. Spelling adjustment. * Minor refactoring/grammar changes * Renaming variables for consistency. * Address linter feedback: omit 2nd value from range over map as values were not being used. * Address feedback from PR re comments. Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Addressing feedback from terencechain in PR. (name changes) * Addressing feedback from terencechain in PR. * Create test for UpdateLogAggregateStats() * Changed comment regarding "numberOfEpochs" log * go fmt metrics_test.go * bazel run //:gazelle -- fix * fix typos * Improved the code to detect the last iteration of the range responses loop * Merge branch 'master' into tempIssue4987 * For both previous Epoch and total runtime statistics, do not count non-included attestations for "correctly" statistics. * Update wording in since-launch logging Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Store first logged epoch in startEpoch and appropriately adjust calculations. Initialize startEpoch to ^uint64(0). * Merge branch 'master' into tempIssue4987 * Update validator/client/metrics.go * Update validator/client/metrics.go * Update validator/client/validator.go * Update validator/client/metrics_test.go * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987
2020-07-07 19:23:56 +00:00
CorrectlyVotedHead: []bool{true, true, true},
CorrectlyVotedSource: []bool{true, true, true},
CorrectlyVotedTarget: []bool{true, true, true},
},
{
PublicKeys: [][]byte{
bytesutil.FromBytes48(pubKeyBytes[0]),
bytesutil.FromBytes48(pubKeyBytes[1]),
bytesutil.FromBytes48(pubKeyBytes[2]),
},
InclusionSlots: []types.Slot{65, types.Slot(^uint64(0)), 67},
InclusionDistances: []types.Slot{1, 0, 2},
Show overall validator results in addition to epoch specific results (#6492) * Add aggregate stats struct to validator struct. Log aggregate voting summary from beginning of node startup. * Refactoring out to function UpdateLogAggregateStats which updates and logs aggregate statistics * Changes to spelling. More refactoring so that the rest of aggregate stats are moved to UpdateLogAggregateStats * Bugfix - moved startBalance initialization out of if. * Remove a print debug. Spelling adjustment. * Minor refactoring/grammar changes * Renaming variables for consistency. * Address linter feedback: omit 2nd value from range over map as values were not being used. * Address feedback from PR re comments. Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Addressing feedback from terencechain in PR. (name changes) * Addressing feedback from terencechain in PR. * Create test for UpdateLogAggregateStats() * Changed comment regarding "numberOfEpochs" log * go fmt metrics_test.go * bazel run //:gazelle -- fix * fix typos * Improved the code to detect the last iteration of the range responses loop * Merge branch 'master' into tempIssue4987 * For both previous Epoch and total runtime statistics, do not count non-included attestations for "correctly" statistics. * Update wording in since-launch logging Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Store first logged epoch in startEpoch and appropriately adjust calculations. Initialize startEpoch to ^uint64(0). * Merge branch 'master' into tempIssue4987 * Update validator/client/metrics.go * Update validator/client/metrics.go * Update validator/client/validator.go * Update validator/client/metrics_test.go * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987
2020-07-07 19:23:56 +00:00
CorrectlyVotedHead: []bool{true, false, true},
CorrectlyVotedSource: []bool{true, false, true},
CorrectlyVotedTarget: []bool{false, false, true},
},
}
v.prevBalance[pubKeyBytes[0]] = uint64(33200000000)
v.prevBalance[pubKeyBytes[1]] = uint64(33300000000)
v.prevBalance[pubKeyBytes[2]] = uint64(31000000000)
var hook *logTest.Hook
for i, val := range responses {
if i == len(responses)-1 { // Handle last log.
hook = logTest.NewGlobal()
}
v.UpdateLogAggregateStats(val, types.Slot(params.BeaconConfig().SlotsPerEpoch*types.Slot(i+1)))
Show overall validator results in addition to epoch specific results (#6492) * Add aggregate stats struct to validator struct. Log aggregate voting summary from beginning of node startup. * Refactoring out to function UpdateLogAggregateStats which updates and logs aggregate statistics * Changes to spelling. More refactoring so that the rest of aggregate stats are moved to UpdateLogAggregateStats * Bugfix - moved startBalance initialization out of if. * Remove a print debug. Spelling adjustment. * Minor refactoring/grammar changes * Renaming variables for consistency. * Address linter feedback: omit 2nd value from range over map as values were not being used. * Address feedback from PR re comments. Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Addressing feedback from terencechain in PR. (name changes) * Addressing feedback from terencechain in PR. * Create test for UpdateLogAggregateStats() * Changed comment regarding "numberOfEpochs" log * go fmt metrics_test.go * bazel run //:gazelle -- fix * fix typos * Improved the code to detect the last iteration of the range responses loop * Merge branch 'master' into tempIssue4987 * For both previous Epoch and total runtime statistics, do not count non-included attestations for "correctly" statistics. * Update wording in since-launch logging Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Store first logged epoch in startEpoch and appropriately adjust calculations. Initialize startEpoch to ^uint64(0). * Merge branch 'master' into tempIssue4987 * Update validator/client/metrics.go * Update validator/client/metrics.go * Update validator/client/validator.go * Update validator/client/metrics_test.go * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987
2020-07-07 19:23:56 +00:00
}
require.LogsContain(t, hook, "msg=\"Previous epoch aggregated voting summary\" attestationInclusionPct=\"67%\" "+
Show overall validator results in addition to epoch specific results (#6492) * Add aggregate stats struct to validator struct. Log aggregate voting summary from beginning of node startup. * Refactoring out to function UpdateLogAggregateStats which updates and logs aggregate statistics * Changes to spelling. More refactoring so that the rest of aggregate stats are moved to UpdateLogAggregateStats * Bugfix - moved startBalance initialization out of if. * Remove a print debug. Spelling adjustment. * Minor refactoring/grammar changes * Renaming variables for consistency. * Address linter feedback: omit 2nd value from range over map as values were not being used. * Address feedback from PR re comments. Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Addressing feedback from terencechain in PR. (name changes) * Addressing feedback from terencechain in PR. * Create test for UpdateLogAggregateStats() * Changed comment regarding "numberOfEpochs" log * go fmt metrics_test.go * bazel run //:gazelle -- fix * fix typos * Improved the code to detect the last iteration of the range responses loop * Merge branch 'master' into tempIssue4987 * For both previous Epoch and total runtime statistics, do not count non-included attestations for "correctly" statistics. * Update wording in since-launch logging Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Store first logged epoch in startEpoch and appropriately adjust calculations. Initialize startEpoch to ^uint64(0). * Merge branch 'master' into tempIssue4987 * Update validator/client/metrics.go * Update validator/client/metrics.go * Update validator/client/validator.go * Update validator/client/metrics_test.go * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987
2020-07-07 19:23:56 +00:00
"correctlyVotedHeadPct=\"100%\" correctlyVotedSourcePct=\"100%\" correctlyVotedTargetPct=\"50%\" epoch=2")
require.LogsContain(t, hook, "msg=\"Vote summary since launch\" attestationsInclusionPct=\"78%\" "+
Show overall validator results in addition to epoch specific results (#6492) * Add aggregate stats struct to validator struct. Log aggregate voting summary from beginning of node startup. * Refactoring out to function UpdateLogAggregateStats which updates and logs aggregate statistics * Changes to spelling. More refactoring so that the rest of aggregate stats are moved to UpdateLogAggregateStats * Bugfix - moved startBalance initialization out of if. * Remove a print debug. Spelling adjustment. * Minor refactoring/grammar changes * Renaming variables for consistency. * Address linter feedback: omit 2nd value from range over map as values were not being used. * Address feedback from PR re comments. Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Addressing feedback from terencechain in PR. (name changes) * Addressing feedback from terencechain in PR. * Create test for UpdateLogAggregateStats() * Changed comment regarding "numberOfEpochs" log * go fmt metrics_test.go * bazel run //:gazelle -- fix * fix typos * Improved the code to detect the last iteration of the range responses loop * Merge branch 'master' into tempIssue4987 * For both previous Epoch and total runtime statistics, do not count non-included attestations for "correctly" statistics. * Update wording in since-launch logging Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Store first logged epoch in startEpoch and appropriately adjust calculations. Initialize startEpoch to ^uint64(0). * Merge branch 'master' into tempIssue4987 * Update validator/client/metrics.go * Update validator/client/metrics.go * Update validator/client/validator.go * Update validator/client/metrics_test.go * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987 * Merge branch 'master' into tempIssue4987
2020-07-07 19:23:56 +00:00
"averageInclusionDistance=\"2.29 slots\" correctlyVotedHeadPct=\"86%\" correctlyVotedSourcePct=\"100%\" "+
"correctlyVotedTargetPct=\"86%\" numberOfEpochs=3 pctChangeCombinedBalance=\"0.20555%\"")
}
func TestUpdateLogAltairAggregateStats(t *testing.T) {
v := &validator{
logValidatorBalances: true,
startBalances: make(map[[fieldparams.BLSPubkeyLength]byte]uint64),
prevBalance: make(map[[fieldparams.BLSPubkeyLength]byte]uint64),
voteStats: voteStats{
startEpoch: params.BeaconConfig().AltairForkEpoch, // this would otherwise have been previously set in LogValidatorGainsAndLosses()
},
}
pubKeyBytes := [][fieldparams.BLSPubkeyLength]byte{
bytesutil.ToBytes48([]byte("000000000000000000000000000000000000000012345678")),
bytesutil.ToBytes48([]byte("000000000000000000000000000000000000000099999999")),
bytesutil.ToBytes48([]byte("000000000000000000000000000000000000000055555555")),
}
v.startBalances[pubKeyBytes[0]] = uint64(32100000000)
v.startBalances[pubKeyBytes[1]] = uint64(32200000000)
v.startBalances[pubKeyBytes[2]] = uint64(33000000000)
// 7 attestations included
responses := []*ethpb.ValidatorPerformanceResponse{
{
PublicKeys: [][]byte{
bytesutil.FromBytes48(pubKeyBytes[0]),
bytesutil.FromBytes48(pubKeyBytes[1]),
bytesutil.FromBytes48(pubKeyBytes[2]),
},
CorrectlyVotedHead: []bool{false, true, false},
CorrectlyVotedSource: []bool{false, true, true},
CorrectlyVotedTarget: []bool{false, false, true}, // test one fast target that is included
},
{
PublicKeys: [][]byte{
bytesutil.FromBytes48(pubKeyBytes[0]),
bytesutil.FromBytes48(pubKeyBytes[1]),
bytesutil.FromBytes48(pubKeyBytes[2]),
},
CorrectlyVotedHead: []bool{true, true, true},
CorrectlyVotedSource: []bool{true, true, true},
CorrectlyVotedTarget: []bool{true, true, true},
},
{
PublicKeys: [][]byte{
bytesutil.FromBytes48(pubKeyBytes[0]),
bytesutil.FromBytes48(pubKeyBytes[1]),
bytesutil.FromBytes48(pubKeyBytes[2]),
},
CorrectlyVotedHead: []bool{true, false, true},
CorrectlyVotedSource: []bool{true, false, true},
CorrectlyVotedTarget: []bool{false, false, true},
},
}
v.prevBalance[pubKeyBytes[0]] = uint64(33200000000)
v.prevBalance[pubKeyBytes[1]] = uint64(33300000000)
v.prevBalance[pubKeyBytes[2]] = uint64(31000000000)
var hook *logTest.Hook
for i, val := range responses {
if i == len(responses)-1 { // Handle last log.
hook = logTest.NewGlobal()
}
altairStart, err := slots.EpochStart(params.BeaconConfig().AltairForkEpoch)
require.NoError(t, err)
v.UpdateLogAggregateStats(val, altairStart+params.BeaconConfig().SlotsPerEpoch*types.Slot(i+1))
}
require.LogsContain(t, hook, "msg=\"Previous epoch aggregated voting summary\" attestationInclusionPct=\"67%\" "+
"averageInactivityScore=0 correctlyVotedHeadPct=\"100%\" correctlyVotedSourcePct=\"100%\" correctlyVotedTargetPct=\"50%\" epoch=74242")
require.LogsContain(t, hook, "msg=\"Vote summary since launch\" attestationsInclusionPct=\"78%\" "+
"correctlyVotedHeadPct=\"86%\" correctlyVotedSourcePct=\"100%\" "+
"correctlyVotedTargetPct=\"71%\" numberOfEpochs=3 pctChangeCombinedBalance=\"0.20555%\"")
}