mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-19 08:14:15 +00:00
68edad13bc
* Begin working on end to end tests using geth dev chain * Start on beacon node set up * More progress on bnode setup * Complete flow until chainstart, begin work on evaluators * More progress on evaluators * Start changing bazel run to direct binary * Move endtoend to inside beacon-chain * use bazel provided geth, use bazel test * tempdir * use fork rules_go * Change to use UUID dir and bazel binaries * Truncate UUID a bit * Get full run from chainstart to evaluating * Rewrite to react to logs rather than arbitrarily wait * Fix export * Move evaluators to evaluators.go * Add peer check test * Add more comments * Remove unneeded exports * Check all nodes have the correct amount of peers * Change name to onGenesisEpoch * Remove extra wait times where not needed * Cleanup * Add log for beacon start * Fix deposit amount * Make room for eth1follow distnce * Cleanup and fix minimal test * Goimports * Fix imports * gazelle and minimal * manual * Fix for comments * Make timing rely on reading logs, and cleanup * Fix for comments * Fix workspace * Cleanup * Fix visibility * Cleanup and some comments * Address comments * Fix for v0.9 * Modify for v0.9 * Move to own package outside of beacon-chain * Gazelle * Polishing, logging * Fix filenames * Add more logs * Add flag logging * Cover for page not having libp2p info * Improve multiAddr detection * Add more logs * Add missing flags * Add log printing to defer * Get multiAddr from logs * Fix logging and detection * Change evaluators to rely on EpochTimer * Add evaluator for ValidatorParticipation * Fix validator participation evaluator * Cleanup, comments and fix participation calculation * Cleanup * Let the file searcher search for longer * Change participation to check for full * Log out file contents if text isnt found * Split into different files * Disable IPC and use RPC instead, change tmp dir to bazel dir * Change visibility * Gazelle * Add e2e tag * new line
95 lines
3.2 KiB
Go
95 lines
3.2 KiB
Go
package evaluators
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/proto/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 := ð.GetValidatorsRequest{}
|
|
validators, err := client.GetValidators(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
|
|
}
|