mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 02:31:19 +00:00
84916672c6
* replace eth2 types * replace protos * regen proto * replace * gaz * deps * amend * regen proto * mod * gaz * gaz * ensure build * ssz * add dep * no more eth2 types * no more eth2 * remg * all builds * buidl * tidy * clean * fmt * val serv * gaz Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
67 lines
2.5 KiB
Go
67 lines
2.5 KiB
Go
package beacon
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/prysmaticlabs/prysm/config/features"
|
|
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
|
"github.com/prysmaticlabs/prysm/container/slice"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
"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)
|
|
}
|
|
if err := bs.SlashingsPool.InsertProposerSlashing(ctx, beaconState, req); err != nil {
|
|
return nil, status.Errorf(codes.Internal, "Could not insert proposer slashing into pool: %v", err)
|
|
}
|
|
if !features.Get().DisableBroadcastSlashings {
|
|
if err := bs.Broadcaster.Broadcast(ctx, req); err != nil {
|
|
return nil, status.Errorf(codes.Internal, "Could not broadcast slashing object: %v", err)
|
|
}
|
|
}
|
|
|
|
return ðpb.SubmitSlashingResponse{
|
|
SlashedIndices: []types.ValidatorIndex{req.Header_1.Header.ProposerIndex},
|
|
}, 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)
|
|
}
|
|
if err := bs.SlashingsPool.InsertAttesterSlashing(ctx, beaconState, req); err != nil {
|
|
return nil, status.Errorf(codes.Internal, "Could not insert attester slashing into pool: %v", err)
|
|
}
|
|
if !features.Get().DisableBroadcastSlashings {
|
|
if err := bs.Broadcaster.Broadcast(ctx, req); err != nil {
|
|
return nil, status.Errorf(codes.Internal, "Could not broadcast slashing object: %v", err)
|
|
}
|
|
}
|
|
indices := slice.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)
|
|
}
|
|
return ðpb.SubmitSlashingResponse{
|
|
SlashedIndices: slashedIndices,
|
|
}, nil
|
|
}
|