2021-09-10 19:59:43 +00:00
|
|
|
package evaluators
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-08-25 13:55:01 +00:00
|
|
|
"time"
|
2021-09-10 19:59:43 +00:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/runtime/version"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/endtoend/helpers"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/endtoend/policies"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/endtoend/types"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/time/slots"
|
2021-09-10 19:59:43 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
2022-08-25 13:55:01 +00:00
|
|
|
var streamDeadline = 1 * time.Minute
|
2023-03-14 13:59:26 +00:00
|
|
|
var startingFork = version.Phase0
|
2022-08-25 13:55:01 +00:00
|
|
|
|
2022-04-11 13:45:22 +00:00
|
|
|
// AltairForkTransition ensures that the Altair hard fork has occurred successfully.
|
|
|
|
var AltairForkTransition = types.Evaluator{
|
2022-12-13 23:13:49 +00:00
|
|
|
Name: "altair_fork_transition_%d",
|
2023-01-26 14:40:12 +00:00
|
|
|
Policy: func(e primitives.Epoch) bool {
|
2022-12-13 23:13:49 +00:00
|
|
|
altair := policies.OnEpoch(helpers.AltairE2EForkEpoch)
|
|
|
|
// TODO (11750): modify policies to take an end to end config
|
|
|
|
if startingFork == version.Phase0 {
|
|
|
|
return altair(e)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
},
|
2022-04-11 13:45:22 +00:00
|
|
|
Evaluation: altairForkOccurs,
|
2021-09-10 19:59:43 +00:00
|
|
|
}
|
|
|
|
|
2022-04-11 13:45:22 +00:00
|
|
|
// BellatrixForkTransition ensures that the Bellatrix hard fork has occurred successfully.
|
|
|
|
var BellatrixForkTransition = types.Evaluator{
|
|
|
|
Name: "bellatrix_fork_transition_%d",
|
|
|
|
Policy: policies.OnEpoch(helpers.BellatrixE2EForkEpoch),
|
|
|
|
Evaluation: bellatrixForkOccurs,
|
|
|
|
}
|
|
|
|
|
2023-02-10 06:19:15 +00:00
|
|
|
// CapellaForkTransition ensures that the Capella hard fork has occurred successfully.
|
|
|
|
var CapellaForkTransition = types.Evaluator{
|
|
|
|
Name: "capella_fork_transition_%d",
|
|
|
|
Policy: policies.OnEpoch(helpers.CapellaE2EForkEpoch),
|
|
|
|
Evaluation: capellaForkOccurs,
|
|
|
|
}
|
|
|
|
|
2023-01-06 07:49:42 +00:00
|
|
|
func altairForkOccurs(_ *types.EvaluationContext, conns ...*grpc.ClientConn) error {
|
2021-09-10 19:59:43 +00:00
|
|
|
conn := conns[0]
|
2022-11-11 17:33:48 +00:00
|
|
|
client := ethpb.NewBeaconNodeValidatorClient(conn)
|
2022-08-25 13:55:01 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), streamDeadline)
|
2021-09-10 19:59:43 +00:00
|
|
|
defer cancel()
|
|
|
|
stream, err := client.StreamBlocksAltair(ctx, ðpb.StreamBlocksRequest{VerifiedOnly: true})
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get stream")
|
|
|
|
}
|
2021-10-01 20:17:57 +00:00
|
|
|
fSlot, err := slots.EpochStart(helpers.AltairE2EForkEpoch)
|
2021-09-10 19:59:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if ctx.Err() == context.Canceled {
|
|
|
|
return errors.New("context canceled prematurely")
|
|
|
|
}
|
|
|
|
res, err := stream.Recv()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if res == nil || res.Block == nil {
|
|
|
|
return errors.New("nil block returned by beacon node")
|
|
|
|
}
|
|
|
|
if res.GetPhase0Block() == nil && res.GetAltairBlock() == nil {
|
|
|
|
return errors.New("nil block returned by beacon node")
|
|
|
|
}
|
|
|
|
if res.GetPhase0Block() != nil {
|
|
|
|
return errors.New("phase 0 block returned after altair fork has occurred")
|
|
|
|
}
|
2022-08-02 15:30:46 +00:00
|
|
|
blk, err := blocks.NewSignedBeaconBlock(res.GetAltairBlock())
|
2021-09-10 19:59:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-08-02 15:30:46 +00:00
|
|
|
if err := blocks.BeaconBlockIsNil(blk); err != nil {
|
2021-11-01 14:13:05 +00:00
|
|
|
return err
|
2021-09-10 19:59:43 +00:00
|
|
|
}
|
|
|
|
if blk.Block().Slot() < fSlot {
|
|
|
|
return errors.Errorf("wanted a block >= %d but received %d", fSlot, blk.Block().Slot())
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2022-04-11 13:45:22 +00:00
|
|
|
|
2023-01-06 07:49:42 +00:00
|
|
|
func bellatrixForkOccurs(_ *types.EvaluationContext, conns ...*grpc.ClientConn) error {
|
2022-04-11 13:45:22 +00:00
|
|
|
conn := conns[0]
|
2022-11-11 17:33:48 +00:00
|
|
|
client := ethpb.NewBeaconNodeValidatorClient(conn)
|
2022-08-25 13:55:01 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), streamDeadline)
|
2022-04-11 13:45:22 +00:00
|
|
|
defer cancel()
|
|
|
|
stream, err := client.StreamBlocksAltair(ctx, ðpb.StreamBlocksRequest{VerifiedOnly: true})
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get stream")
|
|
|
|
}
|
|
|
|
fSlot, err := slots.EpochStart(helpers.BellatrixE2EForkEpoch)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if ctx.Err() == context.Canceled {
|
|
|
|
return errors.New("context canceled prematurely")
|
|
|
|
}
|
|
|
|
res, err := stream.Recv()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if res == nil || res.Block == nil {
|
|
|
|
return errors.New("nil block returned by beacon node")
|
|
|
|
}
|
|
|
|
if res.GetPhase0Block() == nil && res.GetAltairBlock() == nil && res.GetBellatrixBlock() == nil {
|
|
|
|
return errors.New("nil block returned by beacon node")
|
|
|
|
}
|
|
|
|
if res.GetPhase0Block() != nil {
|
|
|
|
return errors.New("phase 0 block returned after bellatrix fork has occurred")
|
|
|
|
}
|
|
|
|
if res.GetAltairBlock() != nil {
|
|
|
|
return errors.New("altair block returned after bellatrix fork has occurred")
|
|
|
|
}
|
2022-08-02 15:30:46 +00:00
|
|
|
blk, err := blocks.NewSignedBeaconBlock(res.GetBellatrixBlock())
|
2022-04-11 13:45:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-08-02 15:30:46 +00:00
|
|
|
if err := blocks.BeaconBlockIsNil(blk); err != nil {
|
2022-04-11 13:45:22 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if blk.Block().Slot() < fSlot {
|
|
|
|
return errors.Errorf("wanted a block >= %d but received %d", fSlot, blk.Block().Slot())
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2023-02-10 06:19:15 +00:00
|
|
|
|
|
|
|
func capellaForkOccurs(_ *types.EvaluationContext, conns ...*grpc.ClientConn) error {
|
|
|
|
conn := conns[0]
|
|
|
|
client := ethpb.NewBeaconNodeValidatorClient(conn)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), streamDeadline)
|
|
|
|
defer cancel()
|
|
|
|
stream, err := client.StreamBlocksAltair(ctx, ðpb.StreamBlocksRequest{VerifiedOnly: true})
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get stream")
|
|
|
|
}
|
|
|
|
fSlot, err := slots.EpochStart(helpers.CapellaE2EForkEpoch)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if ctx.Err() == context.Canceled {
|
|
|
|
return errors.New("context canceled prematurely")
|
|
|
|
}
|
|
|
|
res, err := stream.Recv()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if res == nil || res.Block == nil {
|
|
|
|
return errors.New("nil block returned by beacon node")
|
|
|
|
}
|
|
|
|
|
|
|
|
if res.GetBlock() == nil {
|
|
|
|
return errors.New("nil block returned by beacon node")
|
|
|
|
}
|
|
|
|
if res.GetCapellaBlock() == nil {
|
|
|
|
return errors.Errorf("non-capella block returned after the fork with type %T", res.Block)
|
|
|
|
}
|
|
|
|
blk, err := blocks.NewSignedBeaconBlock(res.GetCapellaBlock())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := blocks.BeaconBlockIsNil(blk); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if blk.Block().Slot() < fSlot {
|
|
|
|
return errors.Errorf("wanted a block at slot >= %d but received %d", fSlot, blk.Block().Slot())
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|