mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-11 12:10:05 +00:00
0326be86b5
* starting on patch * finish determining all required patches * properly redefine the patch rules * new patch * rem double semicolon * fix patch file * Merge branch 'master' of github.com:prysmaticlabs/prysm into deprecate-eth-protos * building the deps * test target passes using ethereumapis * compile gateway * attempting to build everything * e2e use ethereumapis * more fixes for slasher * other item * getting closer to compiling slasher * build slasher package * Merge branch 'master' into deprecate-eth-protos * Merge branch 'master' into deprecate-eth-protos * fix benches * lint gazelle * Merge branch 'deprecate-eth-protos' of github.com:prysmaticlabs/prysm into deprecate-eth-protos * proper gateway * lint * Merge branch 'master' into deprecate-eth-protos * fix build * Merge branch 'deprecate-eth-protos' of github.com:prysmaticlabs/prysm into deprecate-eth-protos * use swag * resolve * ignore change * include new patch changes * fix test * builds * fix e2e * gaz
95 lines
3.2 KiB
Go
95 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 expected %f, received: %f", expected, partRate)
|
|
}
|
|
return nil
|
|
}
|