mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
6816337589
* Make logs more helpful for E2E * gofmt * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into helpful-logs * Add extra info * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into helpful-logs * gofmt and fix error output * Use errors * Gazelle * Revert "gofmt and fix error output" This reverts commit 9fc85f2dd2e87a64ab43d526cd711df6cba4ab86. * Formatting and fix * add f * Add more details to logs * Merge branch 'master' into helpful-logs * Change text a bit * Merge branch 'helpful-logs' of https://github.com/0xKiwi/Prysm into helpful-logs * Merge branch 'master' into helpful-logs
100 lines
3.2 KiB
Go
100 lines
3.2 KiB
Go
package evaluators
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/pkg/errors"
|
|
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
)
|
|
|
|
// Evaluator defines the structure of the evaluators used to
|
|
// conduct the current beacon state during the E2E.
|
|
type Evaluator struct {
|
|
Name string
|
|
Policy func(currentEpoch uint64) bool
|
|
Evaluation func(client eth.BeaconChainClient) error
|
|
}
|
|
|
|
// ValidatorsAreActive ensures the expected amount of validators are active.
|
|
var ValidatorsAreActive = Evaluator{
|
|
Name: "validators_active_epoch_%d",
|
|
Policy: onGenesisEpoch,
|
|
Evaluation: validatorsAreActive,
|
|
}
|
|
|
|
// ValidatorsParticipating ensures the expected amount of validators are active.
|
|
var ValidatorsParticipating = Evaluator{
|
|
Name: "validators_participating_epoch_%d",
|
|
Policy: afterNthEpoch(1),
|
|
Evaluation: validatorsParticipating,
|
|
}
|
|
|
|
func onGenesisEpoch(currentEpoch uint64) bool {
|
|
return currentEpoch < 2
|
|
}
|
|
|
|
// Not including first epoch because of issues with genesis.
|
|
func afterNthEpoch(afterEpoch uint64) func(uint64) bool {
|
|
return func(currentEpoch uint64) bool {
|
|
return currentEpoch > afterEpoch
|
|
}
|
|
}
|
|
|
|
func validatorsAreActive(client eth.BeaconChainClient) error {
|
|
// Balances actually fluctuate but we just want to check initial balance.
|
|
validatorRequest := ð.ListValidatorsRequest{}
|
|
validators, err := client.ListValidators(context.Background(), validatorRequest)
|
|
if err != nil {
|
|
return errors.Wrap(err, "failed to get validators")
|
|
}
|
|
|
|
expectedCount := params.BeaconConfig().MinGenesisActiveValidatorCount
|
|
receivedCount := uint64(len(validators.Validators))
|
|
if expectedCount != receivedCount {
|
|
return fmt.Errorf("expected validator count to be %d, recevied %d", expectedCount, receivedCount)
|
|
}
|
|
|
|
for _, val := range validators.Validators {
|
|
if val.ActivationEpoch != 0 {
|
|
return fmt.Errorf("expected genesis validator epoch to be 0, received %d", val.ActivationEpoch)
|
|
}
|
|
if val.ExitEpoch != params.BeaconConfig().FarFutureEpoch {
|
|
return fmt.Errorf("expected genesis validator exit epoch to be far future, received %d", val.ExitEpoch)
|
|
}
|
|
if val.WithdrawableEpoch != params.BeaconConfig().FarFutureEpoch {
|
|
return fmt.Errorf("expected genesis validator withdrawable epoch to be far future, received %d", val.WithdrawableEpoch)
|
|
}
|
|
if val.EffectiveBalance != params.BeaconConfig().MaxEffectiveBalance {
|
|
return fmt.Errorf(
|
|
"expected genesis validator effective balance to be %d, received %d",
|
|
params.BeaconConfig().MaxEffectiveBalance,
|
|
val.EffectiveBalance,
|
|
)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// validatorsParticipating ensures the validators have an acceptable participation rate.
|
|
func validatorsParticipating(client eth.BeaconChainClient) error {
|
|
validatorRequest := ð.GetValidatorParticipationRequest{}
|
|
participation, err := client.GetValidatorParticipation(context.Background(), validatorRequest)
|
|
if err != nil {
|
|
return errors.Wrap(err, "failed to get validator participation")
|
|
}
|
|
|
|
partRate := participation.Participation.GlobalParticipationRate
|
|
expected := float32(1)
|
|
if partRate < expected {
|
|
return fmt.Errorf(
|
|
"validator participation was below for epoch %d, expected %f, received: %f",
|
|
participation.Epoch,
|
|
expected,
|
|
partRate,
|
|
)
|
|
}
|
|
return nil
|
|
}
|