2020-05-29 02:51:00 +00:00
|
|
|
package evaluators
|
|
|
|
|
|
|
|
import (
|
2020-10-19 19:35:34 +00:00
|
|
|
"bytes"
|
2020-05-29 02:51:00 +00:00
|
|
|
"context"
|
|
|
|
"fmt"
|
2020-06-11 06:38:15 +00:00
|
|
|
"math"
|
2020-05-29 02:51:00 +00:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2021-02-22 23:20:57 +00:00
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
2020-10-19 19:35:34 +00:00
|
|
|
corehelpers "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
2021-09-27 16:19:20 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
|
2021-09-21 19:59:25 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
2021-09-23 15:23:37 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
2021-09-10 19:59:43 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
|
|
|
|
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
2021-09-15 14:42:05 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/endtoend/helpers"
|
|
|
|
e2e "github.com/prysmaticlabs/prysm/testing/endtoend/params"
|
|
|
|
"github.com/prysmaticlabs/prysm/testing/endtoend/policies"
|
|
|
|
e2etypes "github.com/prysmaticlabs/prysm/testing/endtoend/types"
|
2021-09-23 18:53:46 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/util"
|
2020-05-29 02:51:00 +00:00
|
|
|
"golang.org/x/exp/rand"
|
|
|
|
"google.golang.org/grpc"
|
2021-05-17 18:32:04 +00:00
|
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
2020-05-29 02:51:00 +00:00
|
|
|
)
|
|
|
|
|
2021-02-23 00:14:50 +00:00
|
|
|
// exitedIndex holds the exited index from ProposeVoluntaryExit in memory so other functions don't confuse it
|
2020-05-29 02:51:00 +00:00
|
|
|
// for a normal validator.
|
2021-02-23 00:14:50 +00:00
|
|
|
var exitedIndex types.ValidatorIndex
|
2020-05-29 02:51:00 +00:00
|
|
|
|
2021-02-23 00:14:50 +00:00
|
|
|
// valExited is used to know if exitedIndex is set, since default value is 0.
|
2020-05-29 02:51:00 +00:00
|
|
|
var valExited bool
|
|
|
|
|
2021-09-15 22:04:13 +00:00
|
|
|
// churnLimit is normally 4 unless the validator set is extremely large.
|
|
|
|
var churnLimit = uint64(4)
|
2020-08-01 17:22:53 +00:00
|
|
|
var depositValCount = e2e.DepositCount
|
|
|
|
|
|
|
|
// Deposits should be processed in twice the length of the epochs per eth1 voting period.
|
2021-02-09 10:05:22 +00:00
|
|
|
var depositsInBlockStart = types.Epoch(math.Floor(float64(params.E2ETestConfig().EpochsPerEth1VotingPeriod) * 2))
|
2020-08-02 21:30:59 +00:00
|
|
|
|
|
|
|
// deposits included + finalization + MaxSeedLookahead for activation.
|
|
|
|
var depositActivationStartEpoch = depositsInBlockStart + 2 + params.E2ETestConfig().MaxSeedLookahead
|
2021-02-09 10:05:22 +00:00
|
|
|
var depositEndEpoch = depositActivationStartEpoch + types.Epoch(math.Ceil(float64(depositValCount)/float64(churnLimit)))
|
2020-08-01 17:22:53 +00:00
|
|
|
|
|
|
|
// ProcessesDepositsInBlocks ensures the expected amount of deposits are accepted into blocks.
|
2021-02-09 10:05:22 +00:00
|
|
|
var ProcessesDepositsInBlocks = e2etypes.Evaluator{
|
2020-08-01 17:22:53 +00:00
|
|
|
Name: "processes_deposits_in_blocks_epoch_%d",
|
2020-10-19 19:35:34 +00:00
|
|
|
Policy: policies.OnEpoch(depositsInBlockStart), // We expect all deposits to enter in one epoch.
|
2020-08-01 17:22:53 +00:00
|
|
|
Evaluation: processesDepositsInBlocks,
|
|
|
|
}
|
2020-06-11 06:38:15 +00:00
|
|
|
|
2020-12-04 23:15:12 +00:00
|
|
|
// VerifyBlockGraffiti ensures the block graffiti is one of the random list.
|
2021-02-09 10:05:22 +00:00
|
|
|
var VerifyBlockGraffiti = e2etypes.Evaluator{
|
2020-12-04 23:15:12 +00:00
|
|
|
Name: "verify_graffiti_in_blocks_epoch_%d",
|
|
|
|
Policy: policies.AfterNthEpoch(0),
|
|
|
|
Evaluation: verifyGraffitiInBlocks,
|
|
|
|
}
|
|
|
|
|
2020-08-01 17:22:53 +00:00
|
|
|
// ActivatesDepositedValidators ensures the expected amount of validator deposits are activated into the state.
|
2021-02-09 10:05:22 +00:00
|
|
|
var ActivatesDepositedValidators = e2etypes.Evaluator{
|
2020-05-29 02:51:00 +00:00
|
|
|
Name: "processes_deposit_validators_epoch_%d",
|
2020-10-19 19:35:34 +00:00
|
|
|
Policy: policies.BetweenEpochs(depositActivationStartEpoch, depositEndEpoch),
|
2020-08-01 17:22:53 +00:00
|
|
|
Evaluation: activatesDepositedValidators,
|
2020-05-29 02:51:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DepositedValidatorsAreActive ensures the expected amount of validators are active after their deposits are processed.
|
2021-02-09 10:05:22 +00:00
|
|
|
var DepositedValidatorsAreActive = e2etypes.Evaluator{
|
2020-05-29 02:51:00 +00:00
|
|
|
Name: "deposited_validators_are_active_epoch_%d",
|
2020-10-19 19:35:34 +00:00
|
|
|
Policy: policies.AfterNthEpoch(depositEndEpoch),
|
2020-05-29 02:51:00 +00:00
|
|
|
Evaluation: depositedValidatorsAreActive,
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProposeVoluntaryExit sends a voluntary exit from randomly selected validator in the genesis set.
|
2021-02-09 10:05:22 +00:00
|
|
|
var ProposeVoluntaryExit = e2etypes.Evaluator{
|
2020-05-29 02:51:00 +00:00
|
|
|
Name: "propose_voluntary_exit_epoch_%d",
|
2020-10-19 19:35:34 +00:00
|
|
|
Policy: policies.OnEpoch(7),
|
2020-05-29 02:51:00 +00:00
|
|
|
Evaluation: proposeVoluntaryExit,
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidatorHasExited checks the beacon state for the exited validator and ensures its marked as exited.
|
2021-02-09 10:05:22 +00:00
|
|
|
var ValidatorHasExited = e2etypes.Evaluator{
|
2020-05-29 02:51:00 +00:00
|
|
|
Name: "voluntary_has_exited_%d",
|
2020-10-19 19:35:34 +00:00
|
|
|
Policy: policies.OnEpoch(8),
|
2020-05-29 02:51:00 +00:00
|
|
|
Evaluation: validatorIsExited,
|
|
|
|
}
|
|
|
|
|
2020-10-19 19:35:34 +00:00
|
|
|
// ValidatorsVoteWithTheMajority verifies whether validator vote for eth1data using the majority algorithm.
|
2021-02-09 10:05:22 +00:00
|
|
|
var ValidatorsVoteWithTheMajority = e2etypes.Evaluator{
|
2020-10-19 19:35:34 +00:00
|
|
|
Name: "validators_vote_with_the_majority_%d",
|
|
|
|
Policy: policies.AfterNthEpoch(0),
|
|
|
|
Evaluation: validatorsVoteWithTheMajority,
|
2020-05-29 02:51:00 +00:00
|
|
|
}
|
|
|
|
|
2020-08-01 17:22:53 +00:00
|
|
|
func processesDepositsInBlocks(conns ...*grpc.ClientConn) error {
|
|
|
|
conn := conns[0]
|
2021-09-10 19:59:43 +00:00
|
|
|
client := ethpb.NewBeaconChainClient(conn)
|
2021-05-17 18:32:04 +00:00
|
|
|
chainHead, err := client.GetChainHead(context.Background(), &emptypb.Empty{})
|
2020-08-01 17:22:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get chain head")
|
|
|
|
}
|
|
|
|
|
2021-09-10 19:59:43 +00:00
|
|
|
req := ðpb.ListBlocksRequest{QueryFilter: ðpb.ListBlocksRequest_Epoch{Epoch: chainHead.HeadEpoch - 1}}
|
2021-09-07 15:17:50 +00:00
|
|
|
blks, err := client.ListBeaconBlocks(context.Background(), req)
|
2020-08-01 17:22:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get blocks from beacon-chain")
|
|
|
|
}
|
2021-09-07 15:17:50 +00:00
|
|
|
var numDeposits uint64
|
2020-08-01 17:22:53 +00:00
|
|
|
for _, blk := range blks.BlockContainers {
|
2021-09-07 15:17:50 +00:00
|
|
|
var slot types.Slot
|
2021-09-10 19:59:43 +00:00
|
|
|
var eth1Data *ethpb.Eth1Data
|
|
|
|
var deposits []*ethpb.Deposit
|
2021-09-07 15:17:50 +00:00
|
|
|
switch blk.Block.(type) {
|
2021-09-10 19:59:43 +00:00
|
|
|
case *ethpb.BeaconBlockContainer_Phase0Block:
|
2021-09-07 15:17:50 +00:00
|
|
|
b := blk.GetPhase0Block().Block
|
|
|
|
slot = b.Slot
|
|
|
|
eth1Data = b.Body.Eth1Data
|
|
|
|
deposits = b.Body.Deposits
|
2021-09-10 19:59:43 +00:00
|
|
|
case *ethpb.BeaconBlockContainer_AltairBlock:
|
2021-09-07 15:17:50 +00:00
|
|
|
b := blk.GetAltairBlock().Block
|
|
|
|
slot = b.Slot
|
|
|
|
eth1Data = b.Body.Eth1Data
|
|
|
|
deposits = b.Body.Deposits
|
|
|
|
default:
|
|
|
|
return errors.New("block neither phase0 nor altair")
|
|
|
|
}
|
2020-08-01 17:22:53 +00:00
|
|
|
fmt.Printf(
|
|
|
|
"Slot: %d with %d deposits, Eth1 block %#x with %d deposits\n",
|
2021-09-07 15:17:50 +00:00
|
|
|
slot,
|
|
|
|
len(deposits),
|
|
|
|
eth1Data.BlockHash, eth1Data.DepositCount,
|
2020-08-01 17:22:53 +00:00
|
|
|
)
|
2021-09-07 15:17:50 +00:00
|
|
|
numDeposits += uint64(len(deposits))
|
2020-08-01 17:22:53 +00:00
|
|
|
}
|
2021-09-07 15:17:50 +00:00
|
|
|
if numDeposits != depositValCount {
|
|
|
|
return fmt.Errorf("expected %d deposits to be processed, received %d", depositValCount, numDeposits)
|
2020-08-01 17:22:53 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-04 23:15:12 +00:00
|
|
|
func verifyGraffitiInBlocks(conns ...*grpc.ClientConn) error {
|
|
|
|
conn := conns[0]
|
2021-09-10 19:59:43 +00:00
|
|
|
client := ethpb.NewBeaconChainClient(conn)
|
2021-05-17 18:32:04 +00:00
|
|
|
chainHead, err := client.GetChainHead(context.Background(), &emptypb.Empty{})
|
2020-12-04 23:15:12 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get chain head")
|
|
|
|
}
|
2022-01-31 16:44:17 +00:00
|
|
|
req := ðpb.ListBlocksRequest{QueryFilter: ðpb.ListBlocksRequest_Epoch{Epoch: chainHead.HeadEpoch.Sub(1)}}
|
2021-09-07 15:17:50 +00:00
|
|
|
blks, err := client.ListBeaconBlocks(context.Background(), req)
|
2020-12-04 23:15:12 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get blocks from beacon-chain")
|
|
|
|
}
|
2021-09-10 19:59:43 +00:00
|
|
|
for _, ctr := range blks.BlockContainers {
|
|
|
|
blk, err := convertToBlockInterface(ctr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-09-07 15:17:50 +00:00
|
|
|
}
|
2021-09-10 19:59:43 +00:00
|
|
|
var e bool
|
|
|
|
slot := blk.Block().Slot()
|
|
|
|
graffitiInBlock := blk.Block().Body().Graffiti()
|
2020-12-04 23:15:12 +00:00
|
|
|
for _, graffiti := range helpers.Graffiti {
|
2021-09-07 15:17:50 +00:00
|
|
|
if bytes.Equal(bytesutil.PadTo([]byte(graffiti), 32), graffitiInBlock) {
|
2020-12-04 23:15:12 +00:00
|
|
|
e = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2021-09-07 15:17:50 +00:00
|
|
|
if !e && slot != 0 {
|
2020-12-04 23:15:12 +00:00
|
|
|
return errors.New("could not get graffiti from the list")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-01 17:22:53 +00:00
|
|
|
func activatesDepositedValidators(conns ...*grpc.ClientConn) error {
|
2020-05-29 02:51:00 +00:00
|
|
|
conn := conns[0]
|
2021-09-10 19:59:43 +00:00
|
|
|
client := ethpb.NewBeaconChainClient(conn)
|
2020-06-11 06:38:15 +00:00
|
|
|
|
2021-05-17 18:32:04 +00:00
|
|
|
chainHead, err := client.GetChainHead(context.Background(), &emptypb.Empty{})
|
2020-06-11 06:38:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get chain head")
|
|
|
|
}
|
|
|
|
|
2021-09-10 19:59:43 +00:00
|
|
|
validatorRequest := ðpb.ListValidatorsRequest{
|
2020-05-29 02:51:00 +00:00
|
|
|
PageSize: int32(params.BeaconConfig().MinGenesisActiveValidatorCount),
|
|
|
|
PageToken: "1",
|
|
|
|
}
|
|
|
|
validators, err := client.ListValidators(context.Background(), validatorRequest)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get validators")
|
|
|
|
}
|
|
|
|
|
2020-08-01 17:22:53 +00:00
|
|
|
expectedCount := depositValCount
|
2020-05-29 02:51:00 +00:00
|
|
|
receivedCount := uint64(len(validators.ValidatorList))
|
|
|
|
if expectedCount != receivedCount {
|
|
|
|
return fmt.Errorf("expected validator count to be %d, recevied %d", expectedCount, receivedCount)
|
|
|
|
}
|
|
|
|
|
2020-06-11 06:38:15 +00:00
|
|
|
epoch := chainHead.HeadEpoch
|
|
|
|
depositsInEpoch := uint64(0)
|
2020-05-29 02:51:00 +00:00
|
|
|
var effBalanceLowCount, exitEpochWrongCount, withdrawEpochWrongCount uint64
|
|
|
|
for _, item := range validators.ValidatorList {
|
2020-06-11 06:38:15 +00:00
|
|
|
if item.Validator.ActivationEpoch == epoch {
|
|
|
|
depositsInEpoch++
|
|
|
|
if item.Validator.EffectiveBalance < params.BeaconConfig().MaxEffectiveBalance {
|
|
|
|
effBalanceLowCount++
|
|
|
|
}
|
|
|
|
if item.Validator.ExitEpoch != params.BeaconConfig().FarFutureEpoch {
|
|
|
|
exitEpochWrongCount++
|
|
|
|
}
|
|
|
|
if item.Validator.WithdrawableEpoch != params.BeaconConfig().FarFutureEpoch {
|
|
|
|
withdrawEpochWrongCount++
|
|
|
|
}
|
2020-05-29 02:51:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-11 06:38:15 +00:00
|
|
|
if depositsInEpoch != churnLimit {
|
|
|
|
return fmt.Errorf("expected %d deposits to be processed in epoch %d, received %d", churnLimit, epoch, depositsInEpoch)
|
|
|
|
}
|
2020-05-29 02:51:00 +00:00
|
|
|
|
|
|
|
if effBalanceLowCount > 0 {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"%d validators did not have genesis validator effective balance of %d",
|
|
|
|
effBalanceLowCount,
|
|
|
|
params.BeaconConfig().MaxEffectiveBalance,
|
|
|
|
)
|
|
|
|
} else if exitEpochWrongCount > 0 {
|
|
|
|
return fmt.Errorf("%d validators did not have an exit epoch of far future epoch", exitEpochWrongCount)
|
|
|
|
} else if withdrawEpochWrongCount > 0 {
|
|
|
|
return fmt.Errorf("%d validators did not have a withdrawable epoch of far future epoch", withdrawEpochWrongCount)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func depositedValidatorsAreActive(conns ...*grpc.ClientConn) error {
|
|
|
|
conn := conns[0]
|
2021-09-10 19:59:43 +00:00
|
|
|
client := ethpb.NewBeaconChainClient(conn)
|
|
|
|
validatorRequest := ðpb.ListValidatorsRequest{
|
2020-05-29 02:51:00 +00:00
|
|
|
PageSize: int32(params.BeaconConfig().MinGenesisActiveValidatorCount),
|
|
|
|
PageToken: "1",
|
|
|
|
}
|
|
|
|
validators, err := client.ListValidators(context.Background(), validatorRequest)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get validators")
|
|
|
|
}
|
|
|
|
|
2020-08-01 17:22:53 +00:00
|
|
|
expectedCount := depositValCount
|
2020-05-29 02:51:00 +00:00
|
|
|
receivedCount := uint64(len(validators.ValidatorList))
|
|
|
|
if expectedCount != receivedCount {
|
|
|
|
return fmt.Errorf("expected validator count to be %d, recevied %d", expectedCount, receivedCount)
|
|
|
|
}
|
|
|
|
|
2021-05-17 18:32:04 +00:00
|
|
|
chainHead, err := client.GetChainHead(context.Background(), &emptypb.Empty{})
|
2020-05-29 02:51:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get chain head")
|
|
|
|
}
|
|
|
|
|
2020-08-01 17:22:53 +00:00
|
|
|
inactiveCount, belowBalanceCount := 0, 0
|
2020-05-29 02:51:00 +00:00
|
|
|
for _, item := range validators.ValidatorList {
|
2020-10-19 19:35:34 +00:00
|
|
|
if !corehelpers.IsActiveValidator(item.Validator, chainHead.HeadEpoch) {
|
2020-05-29 02:51:00 +00:00
|
|
|
inactiveCount++
|
|
|
|
}
|
2020-08-01 17:22:53 +00:00
|
|
|
if item.Validator.EffectiveBalance < params.BeaconConfig().MaxEffectiveBalance {
|
|
|
|
belowBalanceCount++
|
|
|
|
}
|
2020-05-29 02:51:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if inactiveCount > 0 {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"%d validators were not active, expected %d active validators from deposits",
|
|
|
|
inactiveCount,
|
|
|
|
params.BeaconConfig().MinGenesisActiveValidatorCount,
|
|
|
|
)
|
|
|
|
}
|
2020-08-01 17:22:53 +00:00
|
|
|
if belowBalanceCount > 0 {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"%d validators did not have a proper balance, expected %d validators to have 32 ETH",
|
|
|
|
belowBalanceCount,
|
|
|
|
params.BeaconConfig().MinGenesisActiveValidatorCount,
|
|
|
|
)
|
|
|
|
}
|
2020-05-29 02:51:00 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func proposeVoluntaryExit(conns ...*grpc.ClientConn) error {
|
|
|
|
conn := conns[0]
|
2021-09-10 19:59:43 +00:00
|
|
|
valClient := ethpb.NewBeaconNodeValidatorClient(conn)
|
|
|
|
beaconClient := ethpb.NewBeaconChainClient(conn)
|
2020-05-29 02:51:00 +00:00
|
|
|
|
|
|
|
ctx := context.Background()
|
2021-05-17 18:32:04 +00:00
|
|
|
chainHead, err := beaconClient.GetChainHead(ctx, &emptypb.Empty{})
|
2020-05-29 02:51:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not get chain head")
|
|
|
|
}
|
|
|
|
|
2021-09-23 18:53:46 +00:00
|
|
|
_, privKeys, err := util.DeterministicDepositsAndKeys(params.BeaconConfig().MinGenesisActiveValidatorCount)
|
2020-05-29 02:51:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-23 00:14:50 +00:00
|
|
|
exitedIndex = types.ValidatorIndex(rand.Uint64() % params.BeaconConfig().MinGenesisActiveValidatorCount)
|
2020-05-29 02:51:00 +00:00
|
|
|
valExited = true
|
|
|
|
|
2021-09-10 19:59:43 +00:00
|
|
|
voluntaryExit := ðpb.VoluntaryExit{
|
2020-05-29 02:51:00 +00:00
|
|
|
Epoch: chainHead.HeadEpoch,
|
2021-02-23 00:14:50 +00:00
|
|
|
ValidatorIndex: exitedIndex,
|
2020-05-29 02:51:00 +00:00
|
|
|
}
|
2021-09-10 19:59:43 +00:00
|
|
|
req := ðpb.DomainRequest{
|
2020-05-29 02:51:00 +00:00
|
|
|
Epoch: chainHead.HeadEpoch,
|
|
|
|
Domain: params.BeaconConfig().DomainVoluntaryExit[:],
|
|
|
|
}
|
|
|
|
domain, err := valClient.DomainData(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-09-27 16:19:20 +00:00
|
|
|
signingData, err := signing.ComputeSigningRoot(voluntaryExit, domain.SignatureDomain)
|
2020-05-29 02:51:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-02-23 00:14:50 +00:00
|
|
|
signature := privKeys[exitedIndex].Sign(signingData[:])
|
2021-09-10 19:59:43 +00:00
|
|
|
signedExit := ðpb.SignedVoluntaryExit{
|
2020-05-29 02:51:00 +00:00
|
|
|
Exit: voluntaryExit,
|
|
|
|
Signature: signature.Marshal(),
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err = valClient.ProposeExit(ctx, signedExit); err != nil {
|
|
|
|
return errors.Wrap(err, "could not propose exit")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func validatorIsExited(conns ...*grpc.ClientConn) error {
|
|
|
|
conn := conns[0]
|
2021-09-10 19:59:43 +00:00
|
|
|
client := ethpb.NewBeaconChainClient(conn)
|
|
|
|
validatorRequest := ðpb.GetValidatorRequest{
|
|
|
|
QueryFilter: ðpb.GetValidatorRequest_Index{
|
2021-02-23 00:14:50 +00:00
|
|
|
Index: exitedIndex,
|
2020-05-29 02:51:00 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
validator, err := client.GetValidator(context.Background(), validatorRequest)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get validators")
|
|
|
|
}
|
|
|
|
if validator.ExitEpoch == params.BeaconConfig().FarFutureEpoch {
|
2021-02-23 00:14:50 +00:00
|
|
|
return fmt.Errorf("expected validator %d to be submitted for exit", exitedIndex)
|
2020-05-29 02:51:00 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2020-10-19 19:35:34 +00:00
|
|
|
|
|
|
|
func validatorsVoteWithTheMajority(conns ...*grpc.ClientConn) error {
|
|
|
|
conn := conns[0]
|
2021-09-10 19:59:43 +00:00
|
|
|
client := ethpb.NewBeaconChainClient(conn)
|
2021-05-17 18:32:04 +00:00
|
|
|
chainHead, err := client.GetChainHead(context.Background(), &emptypb.Empty{})
|
2020-10-19 19:35:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get chain head")
|
|
|
|
}
|
|
|
|
|
2022-01-31 16:44:17 +00:00
|
|
|
req := ðpb.ListBlocksRequest{QueryFilter: ðpb.ListBlocksRequest_Epoch{Epoch: chainHead.HeadEpoch.Sub(1)}}
|
2021-09-10 19:59:43 +00:00
|
|
|
blks, err := client.ListBeaconBlocks(context.Background(), req)
|
2020-10-19 19:35:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get blocks from beacon-chain")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, blk := range blks.BlockContainers {
|
2021-09-07 15:17:50 +00:00
|
|
|
var slot types.Slot
|
|
|
|
var vote []byte
|
|
|
|
switch blk.Block.(type) {
|
2021-09-10 19:59:43 +00:00
|
|
|
case *ethpb.BeaconBlockContainer_Phase0Block:
|
2021-09-07 15:17:50 +00:00
|
|
|
b := blk.GetPhase0Block().Block
|
|
|
|
slot = b.Slot
|
|
|
|
vote = b.Body.Eth1Data.BlockHash
|
2021-09-10 19:59:43 +00:00
|
|
|
case *ethpb.BeaconBlockContainer_AltairBlock:
|
2021-09-07 15:17:50 +00:00
|
|
|
b := blk.GetAltairBlock().Block
|
|
|
|
slot = b.Slot
|
|
|
|
vote = b.Body.Eth1Data.BlockHash
|
2022-04-05 14:02:46 +00:00
|
|
|
case *ethpb.BeaconBlockContainer_BellatrixBlock:
|
|
|
|
b := blk.GetBellatrixBlock().Block
|
|
|
|
slot = b.Slot
|
|
|
|
vote = b.Body.Eth1Data.BlockHash
|
2021-09-07 15:17:50 +00:00
|
|
|
default:
|
|
|
|
return errors.New("block neither phase0 nor altair")
|
|
|
|
}
|
2021-02-16 07:45:34 +00:00
|
|
|
slotsPerVotingPeriod := params.E2ETestConfig().SlotsPerEpoch.Mul(uint64(params.E2ETestConfig().EpochsPerEth1VotingPeriod))
|
2020-10-19 19:35:34 +00:00
|
|
|
|
|
|
|
// We treat epoch 1 differently from other epoch for two reasons:
|
|
|
|
// - this evaluator is not executed for epoch 0 so we have to calculate the first slot differently
|
|
|
|
// - for some reason the vote for the first slot in epoch 1 is 0x000... so we skip this slot
|
|
|
|
var isFirstSlotInVotingPeriod bool
|
2022-02-02 19:13:52 +00:00
|
|
|
if chainHead.HeadEpoch == 1 && slot%params.BeaconConfig().SlotsPerEpoch == 0 {
|
2020-10-19 19:35:34 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
// We skipped the first slot so we treat the second slot as the starting slot of epoch 1.
|
|
|
|
if chainHead.HeadEpoch == 1 {
|
2022-02-02 19:13:52 +00:00
|
|
|
isFirstSlotInVotingPeriod = slot%params.BeaconConfig().SlotsPerEpoch == 1
|
2020-10-19 19:35:34 +00:00
|
|
|
} else {
|
|
|
|
isFirstSlotInVotingPeriod = slot%slotsPerVotingPeriod == 0
|
|
|
|
}
|
|
|
|
if isFirstSlotInVotingPeriod {
|
|
|
|
expectedEth1DataVote = vote
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Equal(vote, expectedEth1DataVote) {
|
|
|
|
return fmt.Errorf("incorrect eth1data vote for slot %d; expected: %#x vs voted: %#x",
|
|
|
|
slot, expectedEth1DataVote, vote)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var expectedEth1DataVote []byte
|
2021-09-10 19:59:43 +00:00
|
|
|
|
|
|
|
func convertToBlockInterface(obj *ethpb.BeaconBlockContainer) (block.SignedBeaconBlock, error) {
|
|
|
|
if obj.GetPhase0Block() != nil {
|
2022-03-25 23:00:44 +00:00
|
|
|
return wrapper.WrappedSignedBeaconBlock(obj.GetPhase0Block())
|
2021-09-10 19:59:43 +00:00
|
|
|
}
|
|
|
|
if obj.GetAltairBlock() != nil {
|
2022-03-25 23:00:44 +00:00
|
|
|
return wrapper.WrappedSignedBeaconBlock(obj.GetAltairBlock())
|
|
|
|
}
|
|
|
|
if obj.GetBellatrixBlock() != nil {
|
|
|
|
return wrapper.WrappedSignedBeaconBlock(obj.GetBellatrixBlock())
|
2021-09-10 19:59:43 +00:00
|
|
|
}
|
2022-04-11 13:45:22 +00:00
|
|
|
if obj.GetBellatrixBlock() != nil {
|
|
|
|
return wrapper.WrappedSignedBeaconBlock(obj.GetBellatrixBlock())
|
|
|
|
}
|
2021-09-10 19:59:43 +00:00
|
|
|
return nil, errors.New("container has no block")
|
|
|
|
}
|