2021-09-29 18:17:37 +00:00
|
|
|
package slasher
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-09-30 02:33:28 +00:00
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
2021-09-29 18:17:37 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
|
|
|
// IsSlashableAttestation returns an attester slashing if an input
|
|
|
|
// attestation is found to be slashable.
|
|
|
|
func (s *Server) IsSlashableAttestation(
|
|
|
|
ctx context.Context, req *ethpb.IndexedAttestation,
|
|
|
|
) (*ethpb.AttesterSlashingResponse, error) {
|
|
|
|
attesterSlashings, err := s.SlashingChecker.IsSlashableAttestation(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(codes.Internal, "Could not determine if attestation is slashable: %v", err)
|
|
|
|
}
|
|
|
|
if len(attesterSlashings) > 0 {
|
|
|
|
return ðpb.AttesterSlashingResponse{
|
|
|
|
AttesterSlashings: attesterSlashings,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
return ðpb.AttesterSlashingResponse{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// HighestAttestations returns the highest source and target epochs attested for
|
|
|
|
// validator indices that have been observed by slasher.
|
2021-09-30 02:33:28 +00:00
|
|
|
func (s *Server) HighestAttestations(
|
2021-09-29 18:17:37 +00:00
|
|
|
ctx context.Context, req *ethpb.HighestAttestationRequest,
|
|
|
|
) (*ethpb.HighestAttestationResponse, error) {
|
2021-09-30 02:33:28 +00:00
|
|
|
valIndices := make([]types.ValidatorIndex, len(req.ValidatorIndices))
|
|
|
|
for i, valIdx := range req.ValidatorIndices {
|
|
|
|
valIndices[i] = types.ValidatorIndex(valIdx)
|
|
|
|
}
|
|
|
|
atts, err := s.SlashingChecker.HighestAttestations(ctx, valIndices)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(codes.Internal, "Could not get highest attestations: %v", err)
|
|
|
|
}
|
|
|
|
return ðpb.HighestAttestationResponse{Attestations: atts}, nil
|
2021-09-29 18:17:37 +00:00
|
|
|
}
|