Skip to content

Commit

Permalink
refactor(cannon): remove unused code and update function names
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Sep 4, 2023
1 parent c0f52d8 commit cbb2af1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"mode": "debug",
"program": "${workspaceRoot}",
"args": [
"sentry"
"cannon"
],
}
]
Expand Down
1 change: 1 addition & 0 deletions pkg/cannon/cannon.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func New(ctx context.Context, log logrus.FieldLogger, config *Config) (*Cannon,

beaconBlockDerivers := []v2.BeaconBlockEventDeriver{
v2.NewAttesterSlashingDeriver(log),
v2.NewProposerSlashingDeriver(log),
}

return &Cannon{
Expand Down
6 changes: 5 additions & 1 deletion pkg/cannon/event/beacon/eth/v2/attester_slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"google.golang.org/protobuf/types/known/wrapperspb"
)

const (
AttesterSlashingDeriverName = "BEACON_API_ETH_V2_BEACON_BLOCK_ATTESTER_SLASHING"
)

type AttesterSlashingDeriver struct {
log logrus.FieldLogger
}
Expand Down Expand Up @@ -41,7 +45,7 @@ func (a *AttesterSlashingDeriver) Process(ctx context.Context, metadata *BeaconB
}

func (a *AttesterSlashingDeriver) Name() string {
return "AttesterSlashing"
return AttesterSlashingDeriverName
}

func (a *AttesterSlashingDeriver) getAttesterSlashings(ctx context.Context, block *spec.VersionedSignedBeaconBlock) []*xatuethv1.AttesterSlashingV2 {
Expand Down
36 changes: 12 additions & 24 deletions pkg/cannon/event/beacon/eth/v2/proposer_slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v2

import (
"context"
"errors"

"github.com/attestantio/go-eth2-client/spec"
xatuethv1 "github.com/ethpandaops/xatu/pkg/proto/eth/v1"
Expand All @@ -14,39 +13,28 @@ import (
)

const (
BeaconBlockProposerSlashingType = "BEACON_API_ETH_V2_BEACON_BLOCK_PROPOSER_SLASHING"
ProposerSlashingDeriverName = "BEACON_API_ETH_V2_BEACON_BLOCK_PROPOSER_SLASHING"
)

type BeaconBlockProposerSlashing struct {
log logrus.FieldLogger
event *xatu.DecoratedEvent
type ProposerSlashingDeriver struct {
log logrus.FieldLogger
}

func NewBeaconBlockProposerSlashing(log logrus.FieldLogger, event *xatu.DecoratedEvent) *BeaconBlockProposerSlashing {
return &BeaconBlockProposerSlashing{
log: log.WithField("event", BeaconBlockProposerSlashingType),
event: event,
func NewProposerSlashingDeriver(log logrus.FieldLogger) *ProposerSlashingDeriver {
return &ProposerSlashingDeriver{
log: log.WithField("module", "cannon/event/beacon/eth/v2/proposer_slashing"),
}
}

func (b *BeaconBlockProposerSlashing) Type() string {
return BeaconBlockProposerSlashingType
func (b *ProposerSlashingDeriver) Name() string {
return ProposerSlashingDeriverName
}

func (b *BeaconBlockProposerSlashing) Validate(ctx context.Context) error {
_, ok := b.event.Data.(*xatu.DecoratedEvent_EthV2BeaconBlockProposerSlashing)
if !ok {
return errors.New("failed to cast event data")
}

return nil
}

func (b *BeaconBlockProposerSlashing) Filter(ctx context.Context) bool {
func (b *ProposerSlashingDeriver) Filter(ctx context.Context) bool {
return false
}

func (b *BeaconBlockProposerSlashing) Process(ctx context.Context, metadata *BeaconBlockMetadata, block *spec.VersionedSignedBeaconBlock) ([]*xatu.DecoratedEvent, error) {
func (b *ProposerSlashingDeriver) Process(ctx context.Context, metadata *BeaconBlockMetadata, block *spec.VersionedSignedBeaconBlock) ([]*xatu.DecoratedEvent, error) {
events := []*xatu.DecoratedEvent{}

slashings, err := b.getProposerSlashings(ctx, block)
Expand All @@ -68,7 +56,7 @@ func (b *BeaconBlockProposerSlashing) Process(ctx context.Context, metadata *Bea
return events, nil
}

func (b *BeaconBlockProposerSlashing) getProposerSlashings(ctx context.Context, block *spec.VersionedSignedBeaconBlock) ([]*xatuethv1.ProposerSlashingV2, error) {
func (b *ProposerSlashingDeriver) getProposerSlashings(ctx context.Context, block *spec.VersionedSignedBeaconBlock) ([]*xatuethv1.ProposerSlashingV2, error) {
slashings := []*xatuethv1.ProposerSlashingV2{}

blockSlashings, err := block.ProposerSlashings()
Expand Down Expand Up @@ -104,7 +92,7 @@ func (b *BeaconBlockProposerSlashing) getProposerSlashings(ctx context.Context,
return slashings, nil
}

func (b *BeaconBlockProposerSlashing) createEvent(ctx context.Context, metadata *BeaconBlockMetadata, slashing *xatuethv1.ProposerSlashingV2) (*xatu.DecoratedEvent, error) {
func (b *ProposerSlashingDeriver) createEvent(ctx context.Context, metadata *BeaconBlockMetadata, slashing *xatuethv1.ProposerSlashingV2) (*xatu.DecoratedEvent, error) {
decoratedEvent := &xatu.DecoratedEvent{
Event: &xatu.Event{
Name: xatu.Event_BEACON_API_ETH_V2_BEACON_BLOCK_PROPOSER_SLASHING,
Expand Down

0 comments on commit cbb2af1

Please sign in to comment.