github.com/prysmaticlabs/prysm@v1.4.4/endtoend/evaluators/finality.go (about) 1 package evaluators 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/pkg/errors" 8 "github.com/prysmaticlabs/prysm/endtoend/policies" 9 "github.com/prysmaticlabs/prysm/endtoend/types" 10 eth "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 11 "google.golang.org/grpc" 12 "google.golang.org/protobuf/types/known/emptypb" 13 ) 14 15 // FinalizationOccurs is an evaluator to make sure finalization is performing as it should. 16 // Requires to be run after at least 4 epochs have passed. 17 var FinalizationOccurs = types.Evaluator{ 18 Name: "finalizes_at_epoch_%d", 19 Policy: policies.AfterNthEpoch(3), 20 Evaluation: finalizationOccurs, 21 } 22 23 func finalizationOccurs(conns ...*grpc.ClientConn) error { 24 conn := conns[0] 25 client := eth.NewBeaconChainClient(conn) 26 chainHead, err := client.GetChainHead(context.Background(), &emptypb.Empty{}) 27 if err != nil { 28 return errors.Wrap(err, "failed to get chain head") 29 } 30 currentEpoch := chainHead.HeadEpoch 31 finalizedEpoch := chainHead.FinalizedEpoch 32 33 expectedFinalizedEpoch := currentEpoch - 2 34 if expectedFinalizedEpoch != finalizedEpoch { 35 return fmt.Errorf( 36 "expected finalized epoch to be %d, received: %d", 37 expectedFinalizedEpoch, 38 finalizedEpoch, 39 ) 40 } 41 previousJustifiedEpoch := chainHead.PreviousJustifiedEpoch 42 currentJustifiedEpoch := chainHead.JustifiedEpoch 43 if previousJustifiedEpoch+1 != currentJustifiedEpoch { 44 return fmt.Errorf( 45 "there should be no gaps between current and previous justified epochs, received current %d and previous %d", 46 currentJustifiedEpoch, 47 previousJustifiedEpoch, 48 ) 49 } 50 if currentJustifiedEpoch+1 != currentEpoch { 51 return fmt.Errorf( 52 "there should be no gaps between current epoch and current justified epoch, received current %d and justified %d", 53 currentEpoch, 54 currentJustifiedEpoch, 55 ) 56 } 57 return nil 58 }