prysm-pulse/beacon-chain/rpc/validator/exit.go
Preston Van Loon 2f02a2baa3 Actually wire up exits (#4661)
* Actually wire up exits
* Merge branch 'master' into exit-fixes
2020-01-27 01:49:37 +00:00

46 lines
1.5 KiB
Go

package validator
import (
"context"
ptypes "github.com/gogo/protobuf/types"
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/beacon-chain/core/helpers"
"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) (*ptypes.Empty, 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)
}
// Confirm the validator is eligible to exit with the parameters provided.
if int(req.Exit.ValidatorIndex) >= len(s.Validators) {
return nil, status.Error(codes.InvalidArgument, "validator index exceeds validator set length")
}
if err := blocks.VerifyExit(s.Validators[req.Exit.ValidatorIndex], helpers.StartSlot(req.Exit.Epoch), s.Fork, req); 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.Validators, req)
return &ptypes.Empty{}, vs.P2P.Broadcast(ctx, req)
}