2019-11-15 18:56:26 +00:00
|
|
|
package evaluators
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
ptypes "github.com/gogo/protobuf/types"
|
|
|
|
"github.com/pkg/errors"
|
2019-11-17 16:16:20 +00:00
|
|
|
eth "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
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.
|
|
|
|
var FinalizationOccurs = Evaluator{
|
|
|
|
Name: "finalizes_at_epoch_%d",
|
|
|
|
Policy: afterNthEpoch(3),
|
|
|
|
Evaluation: finalizationOccurs,
|
|
|
|
}
|
|
|
|
|
|
|
|
func finalizationOccurs(client eth.BeaconChainClient) error {
|
|
|
|
chainHead, err := client.GetChainHead(context.Background(), &ptypes.Empty{})
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get chain head")
|
|
|
|
}
|
2019-11-19 19:33:13 +00:00
|
|
|
currentEpoch := chainHead.HeadBlockEpoch
|
|
|
|
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
|
|
|
|
}
|