2019-11-15 18:56:26 +00:00
|
|
|
package evaluators
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2021-07-21 21:34:07 +00:00
|
|
|
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2021-09-15 14:42:05 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/endtoend/policies"
|
|
|
|
"github.com/prysmaticlabs/prysm/testing/endtoend/types"
|
2020-03-15 05:09:23 +00:00
|
|
|
"google.golang.org/grpc"
|
2021-05-17 18:32:04 +00:00
|
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
2019-11-15 18:56:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// FinalizationOccurs is an evaluator to make sure finalization is performing as it should.
|
|
|
|
// Requires to be run after at least 4 epochs have passed.
|
2020-03-22 23:04:23 +00:00
|
|
|
var FinalizationOccurs = types.Evaluator{
|
2019-11-15 18:56:26 +00:00
|
|
|
Name: "finalizes_at_epoch_%d",
|
2020-10-19 19:35:34 +00:00
|
|
|
Policy: policies.AfterNthEpoch(3),
|
2019-11-15 18:56:26 +00:00
|
|
|
Evaluation: finalizationOccurs,
|
|
|
|
}
|
|
|
|
|
2020-03-15 05:09:23 +00:00
|
|
|
func finalizationOccurs(conns ...*grpc.ClientConn) error {
|
|
|
|
conn := conns[0]
|
|
|
|
client := eth.NewBeaconChainClient(conn)
|
2021-05-17 18:32:04 +00:00
|
|
|
chainHead, err := client.GetChainHead(context.Background(), &emptypb.Empty{})
|
2019-11-15 18:56:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get chain head")
|
|
|
|
}
|
2019-12-03 19:48:11 +00:00
|
|
|
currentEpoch := chainHead.HeadEpoch
|
2019-11-19 19:33:13 +00:00
|
|
|
finalizedEpoch := chainHead.FinalizedEpoch
|
2019-11-15 18:56:26 +00:00
|
|
|
|
|
|
|
expectedFinalizedEpoch := currentEpoch - 2
|
|
|
|
if expectedFinalizedEpoch != finalizedEpoch {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"expected finalized epoch to be %d, received: %d",
|
|
|
|
expectedFinalizedEpoch,
|
|
|
|
finalizedEpoch,
|
|
|
|
)
|
|
|
|
}
|
2019-11-19 19:33:13 +00:00
|
|
|
previousJustifiedEpoch := chainHead.PreviousJustifiedEpoch
|
|
|
|
currentJustifiedEpoch := chainHead.JustifiedEpoch
|
2019-11-15 18:56:26 +00:00
|
|
|
if previousJustifiedEpoch+1 != currentJustifiedEpoch {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"there should be no gaps between current and previous justified epochs, received current %d and previous %d",
|
|
|
|
currentJustifiedEpoch,
|
|
|
|
previousJustifiedEpoch,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
if currentJustifiedEpoch+1 != currentEpoch {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"there should be no gaps between current epoch and current justified epoch, received current %d and justified %d",
|
|
|
|
currentEpoch,
|
|
|
|
currentJustifiedEpoch,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|