prysm-pulse/beacon-chain/sync/subscriber_handlers.go
Raul Jordan 5aac06f04e
Move EthereumAPIs Into Prysm (#8968)
* begin move

* use same import path

* imports

* regen protos

* regen

* no rename

* generate ssz

* gaz

* fmt

* edit build file

* imports

* modify

* remove generated files

* remove protos

* edit imports in prysm

* beacon chain all builds

* edit script

* add generated pbs

* add replace rules

* license for ethereumapis protos

* change visibility

* fmt

* update build files to gaz ignore

* use proper form

* edit imports

* wrap block

* revert scripts

* revert go mod
2021-06-02 18:49:52 -05:00

72 lines
2.5 KiB
Go

package sync
import (
"context"
"fmt"
"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"google.golang.org/protobuf/proto"
)
func (s *Service) voluntaryExitSubscriber(ctx context.Context, msg proto.Message) error {
ve, ok := msg.(*ethpb.SignedVoluntaryExit)
if !ok {
return fmt.Errorf("wrong type, expected: *ethpb.SignedVoluntaryExit got: %T", msg)
}
if ve.Exit == nil {
return errors.New("exit can't be nil")
}
s.setExitIndexSeen(ve.Exit.ValidatorIndex)
headState, err := s.cfg.Chain.HeadState(ctx)
if err != nil {
return err
}
s.cfg.ExitPool.InsertVoluntaryExit(ctx, headState, ve)
return nil
}
func (s *Service) attesterSlashingSubscriber(ctx context.Context, msg proto.Message) error {
aSlashing, ok := msg.(*ethpb.AttesterSlashing)
if !ok {
return fmt.Errorf("wrong type, expected: *ethpb.AttesterSlashing got: %T", msg)
}
// Do some nil checks to prevent easy DoS'ing of this handler.
aSlashing1IsNil := aSlashing == nil || aSlashing.Attestation_1 == nil || aSlashing.Attestation_1.AttestingIndices == nil
aSlashing2IsNil := aSlashing == nil || aSlashing.Attestation_2 == nil || aSlashing.Attestation_2.AttestingIndices == nil
if !aSlashing1IsNil && !aSlashing2IsNil {
headState, err := s.cfg.Chain.HeadState(ctx)
if err != nil {
return err
}
if err := s.cfg.SlashingPool.InsertAttesterSlashing(ctx, headState, aSlashing); err != nil {
return errors.Wrap(err, "could not insert attester slashing into pool")
}
s.setAttesterSlashingIndicesSeen(aSlashing.Attestation_1.AttestingIndices, aSlashing.Attestation_2.AttestingIndices)
}
return nil
}
func (s *Service) proposerSlashingSubscriber(ctx context.Context, msg proto.Message) error {
pSlashing, ok := msg.(*ethpb.ProposerSlashing)
if !ok {
return fmt.Errorf("wrong type, expected: *ethpb.ProposerSlashing got: %T", msg)
}
// Do some nil checks to prevent easy DoS'ing of this handler.
header1IsNil := pSlashing == nil || pSlashing.Header_1 == nil || pSlashing.Header_1.Header == nil
header2IsNil := pSlashing == nil || pSlashing.Header_2 == nil || pSlashing.Header_2.Header == nil
if !header1IsNil && !header2IsNil {
headState, err := s.cfg.Chain.HeadState(ctx)
if err != nil {
return err
}
if err := s.cfg.SlashingPool.InsertProposerSlashing(ctx, headState, pSlashing); err != nil {
return errors.Wrap(err, "could not insert proposer slashing into pool")
}
s.setProposerSlashingIndexSeen(pSlashing.Header_1.Header.ProposerIndex)
}
return nil
}