prysm-pulse/beacon-chain/rpc/prysm/v1alpha1/validator/exit.go
Raul Jordan d077483577
Add V3 Suffix to All Prysm Packages (#11083)
* v3 import renamings

* tidy

* fmt

* rev

* Update beacon-chain/core/epoch/precompute/reward_penalty_test.go

* Update beacon-chain/core/helpers/validators_test.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/iface/BUILD.bazel

* Update beacon-chain/db/kv/kv.go

* Update beacon-chain/db/kv/state.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/sync/initial-sync/service.go

* fix deps

* fix bad replacements

* fix bad replacements

* change back

* gohashtree version

* fix deps

Co-authored-by: Nishant Das <nishdas93@gmail.com>
Co-authored-by: Potuz <potuz@prysmaticlabs.com>
2022-08-16 12:20:13 +00:00

59 lines
1.9 KiB
Go

package validator
import (
"context"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/feed"
opfeed "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/feed/operation"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"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) != fieldparams.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.GenesisValidatorsRoot()); err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
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 &ethpb.ProposeExitResponse{
ExitRoot: r[:],
}, vs.P2P.Broadcast(ctx, req)
}