Skip to content

Commit

Permalink
feat(server): Support cannon events (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm authored Sep 6, 2023
1 parent e68a9b2 commit fd241f0
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package v2

import (
"context"
"errors"

"github.com/ethpandaops/xatu/pkg/proto/xatu"
"github.com/sirupsen/logrus"
)

const (
BeaconBlockBLSToExecutionChangeType = "BEACON_API_ETH_V2_BEACON_BLOCK_BLS_TO_EXECUTION_CHANGE"
)

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

func NewBeaconBlockBLSToExecutionChange(log logrus.FieldLogger, event *xatu.DecoratedEvent) *BeaconBlockBLSToExecutionChange {
return &BeaconBlockBLSToExecutionChange{
log: log.WithField("event", BeaconBlockBLSToExecutionChangeType),
event: event,
}
}

func (b *BeaconBlockBLSToExecutionChange) Type() string {
return BeaconBlockBLSToExecutionChangeType
}

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

return nil
}

func (b *BeaconBlockBLSToExecutionChange) Filter(ctx context.Context) bool {
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package v2

import (
"context"
"errors"

"github.com/ethpandaops/xatu/pkg/proto/xatu"
"github.com/sirupsen/logrus"
)

const (
BeaconBlockDepositType = "BEACON_API_ETH_V2_BEACON_BLOCK_DEPOSIT"
)

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

func NewBeaconBlockDeposit(log logrus.FieldLogger, event *xatu.DecoratedEvent) *BeaconBlockDeposit {
return &BeaconBlockDeposit{
log: log.WithField("event", BeaconBlockDepositType),
event: event,
}
}

func (b *BeaconBlockDeposit) Type() string {
return BeaconBlockDepositType
}

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

return nil
}

func (b *BeaconBlockDeposit) Filter(ctx context.Context) bool {
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package v2

import (
"context"
"errors"

"github.com/ethpandaops/xatu/pkg/proto/xatu"
"github.com/sirupsen/logrus"
)

const (
BeaconBlockExecutionTransactionType = "BEACON_API_ETH_V2_BEACON_BLOCK_EXECUTION_TRANSACTION"
)

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

func NewBeaconBlockExecutionTransaction(log logrus.FieldLogger, event *xatu.DecoratedEvent) *BeaconBlockExecutionTransaction {
return &BeaconBlockExecutionTransaction{
log: log.WithField("event", BeaconBlockExecutionTransactionType),
event: event,
}
}

func (b *BeaconBlockExecutionTransaction) Type() string {
return BeaconBlockExecutionTransactionType
}

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

return nil
}

func (b *BeaconBlockExecutionTransaction) Filter(ctx context.Context) bool {
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package v2

import (
"context"
"errors"

"github.com/ethpandaops/xatu/pkg/proto/xatu"
"github.com/sirupsen/logrus"
)

const (
BeaconBlockProposerSlashingType = "BEACON_API_ETH_V2_BEACON_BLOCK_PROPOSER_SLASHING"
)

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

func NewBeaconBlockProposerSlashing(log logrus.FieldLogger, event *xatu.DecoratedEvent) *BeaconBlockProposerSlashing {
return &BeaconBlockProposerSlashing{
log: log.WithField("event", BeaconBlockProposerSlashingType),
event: event,
}
}

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

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 {
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package v2

import (
"context"
"errors"

"github.com/ethpandaops/xatu/pkg/proto/xatu"
"github.com/sirupsen/logrus"
)

const (
BeaconBlockVoluntaryExitType = "BEACON_API_ETH_V2_BEACON_BLOCK_VOLUNTARY_EXIT"
)

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

func NewBeaconBlockVoluntaryExit(log logrus.FieldLogger, event *xatu.DecoratedEvent) *BeaconBlockVoluntaryExit {
return &BeaconBlockVoluntaryExit{
log: log.WithField("event", BeaconBlockVoluntaryExitType),
event: event,
}
}

func (b *BeaconBlockVoluntaryExit) Type() string {
return BeaconBlockVoluntaryExitType
}

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

return nil
}

func (b *BeaconBlockVoluntaryExit) Filter(ctx context.Context) bool {
return false
}
17 changes: 17 additions & 0 deletions pkg/server/service/event-ingester/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const (
TypeBeaconEthV1BeaconCommittee Type = v1.BeaconCommitteeType
TypeBeaconEthV1ValidatorAttestationData Type = v1.ValidatorAttestationDataType
TypeBeaconEthV2BeaconBlockAttesterSlashing Type = v2.BeaconBlockAttesterSlashingType
TypeBeaconEthV2BeaconBlockProposerSlashing Type = v2.BeaconBlockProposerSlashingType
TypeBeaconEthV2BeaconBlockVoluntaryExit Type = v2.BeaconBlockVoluntaryExitType
TypeBeaconEthV2BeaconBlockDeposit Type = v2.BeaconBlockDepositType
TypeBeaconEthV2BeaconExecutionTransaction Type = v2.BeaconBlockExecutionTransactionType
TypeBeaconEthV2BeaconBLSToExecutionChange Type = v2.BeaconBlockBLSToExecutionChangeType
)

type Event interface {
Expand All @@ -50,6 +55,7 @@ type Event interface {
Filter(ctx context.Context) bool
}

//nolint:gocyclo //not that complex
func New(eventType Type, log logrus.FieldLogger, event *xatu.DecoratedEvent, cache store.Cache) (Event, error) {
if eventType == TypeUnknown {
return nil, errors.New("event type is required")
Expand Down Expand Up @@ -106,6 +112,17 @@ func New(eventType Type, log logrus.FieldLogger, event *xatu.DecoratedEvent, cac
return v1.NewValidatorAttestationData(log, event), nil
case TypeBeaconEthV2BeaconBlockAttesterSlashing:
return v2.NewBeaconBlockAttesterSlashing(log, event), nil
case TypeBeaconEthV2BeaconBlockProposerSlashing:
return v2.NewBeaconBlockProposerSlashing(log, event), nil
case TypeBeaconEthV2BeaconBlockVoluntaryExit:
return v2.NewBeaconBlockVoluntaryExit(log, event), nil
case TypeBeaconEthV2BeaconBlockDeposit:
return v2.NewBeaconBlockDeposit(log, event), nil
case TypeBeaconEthV2BeaconExecutionTransaction:
return v2.NewBeaconBlockExecutionTransaction(log, event), nil
case TypeBeaconEthV2BeaconBLSToExecutionChange:
return v2.NewBeaconBlockBLSToExecutionChange(log, event), nil

default:
return nil, fmt.Errorf("event type %s is unknown", eventType)
}
Expand Down

0 comments on commit fd241f0

Please sign in to comment.