github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/sync/subscriber_handlers.go (about) 1 package sync 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/pkg/errors" 8 ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 9 "google.golang.org/protobuf/proto" 10 ) 11 12 func (s *Service) voluntaryExitSubscriber(ctx context.Context, msg proto.Message) error { 13 ve, ok := msg.(*ethpb.SignedVoluntaryExit) 14 if !ok { 15 return fmt.Errorf("wrong type, expected: *ethpb.SignedVoluntaryExit got: %T", msg) 16 } 17 18 if ve.Exit == nil { 19 return errors.New("exit can't be nil") 20 } 21 s.setExitIndexSeen(ve.Exit.ValidatorIndex) 22 23 headState, err := s.cfg.Chain.HeadState(ctx) 24 if err != nil { 25 return err 26 } 27 s.cfg.ExitPool.InsertVoluntaryExit(ctx, headState, ve) 28 return nil 29 } 30 31 func (s *Service) attesterSlashingSubscriber(ctx context.Context, msg proto.Message) error { 32 aSlashing, ok := msg.(*ethpb.AttesterSlashing) 33 if !ok { 34 return fmt.Errorf("wrong type, expected: *ethpb.AttesterSlashing got: %T", msg) 35 } 36 // Do some nil checks to prevent easy DoS'ing of this handler. 37 aSlashing1IsNil := aSlashing == nil || aSlashing.Attestation_1 == nil || aSlashing.Attestation_1.AttestingIndices == nil 38 aSlashing2IsNil := aSlashing == nil || aSlashing.Attestation_2 == nil || aSlashing.Attestation_2.AttestingIndices == nil 39 if !aSlashing1IsNil && !aSlashing2IsNil { 40 headState, err := s.cfg.Chain.HeadState(ctx) 41 if err != nil { 42 return err 43 } 44 if err := s.cfg.SlashingPool.InsertAttesterSlashing(ctx, headState, aSlashing); err != nil { 45 return errors.Wrap(err, "could not insert attester slashing into pool") 46 } 47 s.setAttesterSlashingIndicesSeen(aSlashing.Attestation_1.AttestingIndices, aSlashing.Attestation_2.AttestingIndices) 48 } 49 return nil 50 } 51 52 func (s *Service) proposerSlashingSubscriber(ctx context.Context, msg proto.Message) error { 53 pSlashing, ok := msg.(*ethpb.ProposerSlashing) 54 if !ok { 55 return fmt.Errorf("wrong type, expected: *ethpb.ProposerSlashing got: %T", msg) 56 } 57 // Do some nil checks to prevent easy DoS'ing of this handler. 58 header1IsNil := pSlashing == nil || pSlashing.Header_1 == nil || pSlashing.Header_1.Header == nil 59 header2IsNil := pSlashing == nil || pSlashing.Header_2 == nil || pSlashing.Header_2.Header == nil 60 if !header1IsNil && !header2IsNil { 61 headState, err := s.cfg.Chain.HeadState(ctx) 62 if err != nil { 63 return err 64 } 65 if err := s.cfg.SlashingPool.InsertProposerSlashing(ctx, headState, pSlashing); err != nil { 66 return errors.Wrap(err, "could not insert proposer slashing into pool") 67 } 68 s.setProposerSlashingIndexSeen(pSlashing.Header_1.Header.ProposerIndex) 69 } 70 return nil 71 }