forked from prysmaticlabs/prysm
/
subscriber_handlers.go
63 lines (58 loc) · 1.85 KB
/
subscriber_handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package sync
import (
"context"
"fmt"
"github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
)
func (r *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)
}
s, err := r.chain.HeadState(ctx)
if err != nil {
return err
}
r.exitPool.InsertVoluntaryExit(ctx, s, ve)
return nil
}
func (r *Service) attesterSlashingSubscriber(ctx context.Context, msg proto.Message) error {
as, 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.
if as != nil && as.Attestation_1 != nil && as.Attestation_1.Data != nil {
s, err := r.db.State(ctx, bytesutil.ToBytes32(as.Attestation_1.Data.BeaconBlockRoot))
if err != nil {
return err
}
if s == nil {
return fmt.Errorf("no state found for block root %#x", as.Attestation_1.Data.BeaconBlockRoot)
}
return r.slashingPool.InsertAttesterSlashing(ctx, s, as)
}
return nil
}
func (r *Service) proposerSlashingSubscriber(ctx context.Context, msg proto.Message) error {
ps, 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.
if ps.Header_1 != nil && ps.Header_1.Header != nil {
root, err := ssz.HashTreeRoot(ps.Header_1.Header)
s, err := r.db.State(ctx, root)
if err != nil {
return err
}
if s == nil {
return fmt.Errorf("no state found for block root %#x", root)
}
return r.slashingPool.InsertProposerSlashing(ctx, s, ps)
}
return nil
}