2020-07-01 17:35:05 +00:00
|
|
|
package evaluators
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
|
2021-02-22 23:20:57 +00:00
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
2020-07-01 17:35:05 +00:00
|
|
|
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
2021-02-09 10:05:22 +00:00
|
|
|
e2etypes "github.com/prysmaticlabs/prysm/endtoend/types"
|
2020-07-01 17:35:05 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
const epochToCheck = 50 // must be more than 46 (32 hot states + 16 chkpt interval)
|
|
|
|
|
|
|
|
// ColdStateCheckpoint checks data from the database using cold state storage.
|
2021-02-09 10:05:22 +00:00
|
|
|
var ColdStateCheckpoint = e2etypes.Evaluator{
|
2020-07-01 17:35:05 +00:00
|
|
|
Name: "cold_state_assignments_from_epoch_%d",
|
2021-02-09 10:05:22 +00:00
|
|
|
Policy: func(currentEpoch types.Epoch) bool {
|
2020-07-01 17:35:05 +00:00
|
|
|
return currentEpoch == epochToCheck
|
|
|
|
},
|
|
|
|
Evaluation: checkColdStateCheckpoint,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks the first node for an old checkpoint using cold state storage.
|
|
|
|
func checkColdStateCheckpoint(conns ...*grpc.ClientConn) error {
|
|
|
|
ctx := context.Background()
|
|
|
|
client := eth.NewBeaconChainClient(conns[0])
|
|
|
|
|
2021-02-09 10:05:22 +00:00
|
|
|
for i := types.Epoch(0); i < epochToCheck; i++ {
|
2020-07-01 17:35:05 +00:00
|
|
|
res, err := client.ListValidatorAssignments(ctx, ð.ListValidatorAssignmentsRequest{
|
|
|
|
QueryFilter: ð.ListValidatorAssignmentsRequest_Epoch{Epoch: i},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// A simple check to ensure we received some data.
|
|
|
|
if res == nil || res.Epoch != i {
|
|
|
|
return errors.New("failed to return a validator assignments response for an old epoch " +
|
|
|
|
"using cold state storage from the database")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|