2019-10-17 03:12:26 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-11-20 05:14:50 +00:00
|
|
|
"github.com/pkg/errors"
|
2019-11-27 05:08:18 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
2019-12-21 03:47:00 +00:00
|
|
|
slashpb "github.com/prysmaticlabs/prysm/proto/slashing"
|
2020-03-27 00:09:14 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/slasher/db"
|
2020-03-24 18:30:21 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/slasher/detection"
|
2020-03-27 00:09:14 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2020-03-26 18:31:20 +00:00
|
|
|
"go.opencensus.io/trace"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
2019-10-17 03:12:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Server defines a server implementation of the gRPC Slasher service,
|
|
|
|
// providing RPC endpoints for retrieving slashing proofs for malicious validators.
|
|
|
|
type Server struct {
|
2020-03-26 18:31:20 +00:00
|
|
|
ctx context.Context
|
|
|
|
detector *detection.Service
|
|
|
|
slasherDB db.Database
|
2019-10-17 03:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsSlashableAttestation returns an attester slashing if the attestation submitted
|
|
|
|
// is a slashable vote.
|
2019-11-27 05:08:18 +00:00
|
|
|
func (ss *Server) IsSlashableAttestation(ctx context.Context, req *ethpb.IndexedAttestation) (*slashpb.AttesterSlashingResponse, error) {
|
2020-03-26 18:31:20 +00:00
|
|
|
ctx, span := trace.StartSpan(ctx, "detection.IsSlashableAttestation")
|
|
|
|
defer span.End()
|
|
|
|
//TODO(#5189) add signature validation to prevent DOS attack on the endpoint.
|
|
|
|
if err := ss.slasherDB.SaveIndexedAttestation(ctx, req); err != nil {
|
|
|
|
log.WithError(err).Error("Could not save indexed attestation")
|
|
|
|
return nil, status.Errorf(codes.Internal, "Could not save indexed attestation: %v: %v", req, err)
|
|
|
|
}
|
|
|
|
slashings, err := ss.detector.DetectAttesterSlashings(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(codes.Internal, "Could not detect attester slashings for attestation: %v: %v", req, err)
|
|
|
|
}
|
|
|
|
if len(slashings) < 1 {
|
|
|
|
if err := ss.detector.UpdateSpans(ctx, req); err != nil {
|
|
|
|
log.WithError(err).Error("Could not update spans")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &slashpb.AttesterSlashingResponse{
|
|
|
|
AttesterSlashing: slashings,
|
|
|
|
}, nil
|
2019-10-17 03:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-03-03 22:09:35 +00:00
|
|
|
// IsSlashableBlock returns an proposer slashing if the block submitted
|
|
|
|
// is a double proposal.
|
2020-03-24 18:30:21 +00:00
|
|
|
func (ss *Server) IsSlashableBlock(ctx context.Context, req *ethpb.SignedBeaconBlockHeader) (*slashpb.ProposerSlashingResponse, error) {
|
2020-03-03 22:09:35 +00:00
|
|
|
return nil, errors.New("unimplemented")
|
2019-11-21 07:11:23 +00:00
|
|
|
}
|