2020-02-14 04:20:45 +00:00
|
|
|
package beacon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-01-05 20:40:11 +00:00
|
|
|
|
2021-02-23 00:14:50 +00:00
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
2021-07-21 21:34:07 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2021-02-23 00:14:50 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
2020-02-15 18:57:49 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/sliceutil"
|
2020-02-14 04:20:45 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SubmitProposerSlashing receives a proposer slashing object via
|
|
|
|
// RPC and injects it into the beacon node's operations pool.
|
|
|
|
// Submission into this pool does not guarantee inclusion into a beacon block.
|
|
|
|
func (bs *Server) SubmitProposerSlashing(
|
|
|
|
ctx context.Context,
|
|
|
|
req *ethpb.ProposerSlashing,
|
|
|
|
) (*ethpb.SubmitSlashingResponse, error) {
|
|
|
|
beaconState, err := bs.HeadFetcher.HeadState(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(codes.Internal, "Could not retrieve head state: %v", err)
|
|
|
|
}
|
2020-03-12 01:16:55 +00:00
|
|
|
if err := bs.SlashingsPool.InsertProposerSlashing(ctx, beaconState, req); err != nil {
|
2020-02-14 04:20:45 +00:00
|
|
|
return nil, status.Errorf(codes.Internal, "Could not insert proposer slashing into pool: %v", err)
|
|
|
|
}
|
2021-01-04 19:36:17 +00:00
|
|
|
if !featureconfig.Get().DisableBroadcastSlashings {
|
|
|
|
if err := bs.Broadcaster.Broadcast(ctx, req); err != nil {
|
2021-02-25 20:00:33 +00:00
|
|
|
return nil, status.Errorf(codes.Internal, "Could not broadcast slashing object: %v", err)
|
2021-01-04 19:36:17 +00:00
|
|
|
}
|
2020-03-12 20:29:23 +00:00
|
|
|
}
|
2020-10-14 23:28:49 +00:00
|
|
|
|
2020-02-14 04:20:45 +00:00
|
|
|
return ðpb.SubmitSlashingResponse{
|
2021-02-23 00:14:50 +00:00
|
|
|
SlashedIndices: []types.ValidatorIndex{req.Header_1.Header.ProposerIndex},
|
2020-02-14 04:20:45 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SubmitAttesterSlashing receives an attester slashing object via
|
|
|
|
// RPC and injects it into the beacon node's operations pool.
|
|
|
|
// Submission into this pool does not guarantee inclusion into a beacon block.
|
|
|
|
func (bs *Server) SubmitAttesterSlashing(
|
|
|
|
ctx context.Context,
|
|
|
|
req *ethpb.AttesterSlashing,
|
|
|
|
) (*ethpb.SubmitSlashingResponse, error) {
|
|
|
|
beaconState, err := bs.HeadFetcher.HeadState(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(codes.Internal, "Could not retrieve head state: %v", err)
|
|
|
|
}
|
2020-03-12 01:16:55 +00:00
|
|
|
if err := bs.SlashingsPool.InsertAttesterSlashing(ctx, beaconState, req); err != nil {
|
2020-02-14 04:20:45 +00:00
|
|
|
return nil, status.Errorf(codes.Internal, "Could not insert attester slashing into pool: %v", err)
|
|
|
|
}
|
2021-01-04 19:36:17 +00:00
|
|
|
if !featureconfig.Get().DisableBroadcastSlashings {
|
|
|
|
if err := bs.Broadcaster.Broadcast(ctx, req); err != nil {
|
2021-02-25 20:00:33 +00:00
|
|
|
return nil, status.Errorf(codes.Internal, "Could not broadcast slashing object: %v", err)
|
2021-01-04 19:36:17 +00:00
|
|
|
}
|
2020-03-12 20:29:23 +00:00
|
|
|
}
|
2021-02-23 00:14:50 +00:00
|
|
|
indices := sliceutil.IntersectionUint64(req.Attestation_1.AttestingIndices, req.Attestation_2.AttestingIndices)
|
|
|
|
slashedIndices := make([]types.ValidatorIndex, len(indices))
|
|
|
|
for i, index := range indices {
|
|
|
|
slashedIndices[i] = types.ValidatorIndex(index)
|
|
|
|
}
|
2020-02-14 04:20:45 +00:00
|
|
|
return ðpb.SubmitSlashingResponse{
|
|
|
|
SlashedIndices: slashedIndices,
|
|
|
|
}, nil
|
|
|
|
}
|