mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 05:38:55 +00:00
7588e491ab
* Add overflow checks * More fixes * Typos * Merge branch 'master' into fix-overflow * One more regression test * Merge branch 'fix-overflow' of github.com:prysmaticlabs/prysm into fix-overflow * Gazelle * Merge branch 'master' into fix-overflow * Nishant's feedback * Merge refs/heads/master into fix-overflow
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
package validator
|
|
|
|
import (
|
|
"context"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
|
|
opfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/operation"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// ProposeExit proposes an exit for a validator.
|
|
func (vs *Server) ProposeExit(ctx context.Context, req *ethpb.SignedVoluntaryExit) (*ethpb.ProposeExitResponse, error) {
|
|
if req == nil {
|
|
return nil, status.Error(codes.InvalidArgument, "nil request")
|
|
}
|
|
s, err := vs.HeadFetcher.HeadState(ctx)
|
|
if err != nil {
|
|
return nil, status.Errorf(codes.Internal, "Could not get head state: %v", err)
|
|
}
|
|
if req.Exit == nil {
|
|
return nil, status.Error(codes.InvalidArgument, "voluntary exit does not exist")
|
|
}
|
|
if req.Signature == nil || len(req.Signature) != params.BeaconConfig().BLSSignatureLength {
|
|
return nil, status.Error(codes.InvalidArgument, "invalid signature provided")
|
|
}
|
|
|
|
// Confirm the validator is eligible to exit with the parameters provided.
|
|
val, err := s.ValidatorAtIndexReadOnly(req.Exit.ValidatorIndex)
|
|
if err != nil {
|
|
return nil, status.Error(codes.InvalidArgument, "validator index exceeds validator set length")
|
|
}
|
|
|
|
if err := blocks.VerifyExitAndSignature(val, s.Slot(), s.Fork(), req, s.GenesisValidatorRoot()); err != nil {
|
|
return nil, status.Error(codes.InvalidArgument, err.Error())
|
|
}
|
|
|
|
// Send the voluntary exit to the operation feed.
|
|
vs.OperationNotifier.OperationFeed().Send(&feed.Event{
|
|
Type: opfeed.ExitReceived,
|
|
Data: &opfeed.ExitReceivedData{
|
|
Exit: req,
|
|
},
|
|
})
|
|
|
|
vs.ExitPool.InsertVoluntaryExit(ctx, s, req)
|
|
|
|
r, err := req.Exit.HashTreeRoot()
|
|
if err != nil {
|
|
return nil, status.Errorf(codes.Internal, "Could not get tree hash of exit: %v", err)
|
|
}
|
|
|
|
return ðpb.ProposeExitResponse{
|
|
ExitRoot: r[:],
|
|
}, vs.P2P.Broadcast(ctx, req)
|
|
}
|