Skip to content

Commit

Permalink
Merge pull request #21 from ethpandaops/feat/blob-sidecar
Browse files Browse the repository at this point in the history
feat(beacon): blob sidecar event
  • Loading branch information
Savid authored Oct 5, 2023
2 parents 8fc9b74 + 0f8c888 commit 1019d16
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 505 deletions.
40 changes: 22 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,49 @@ module github.com/ethpandaops/beacon

go 1.19

replace github.com/attestantio/go-eth2-client v0.15.7 => github.com/samcm/go-eth2-client v0.15.8

require (
github.com/attestantio/go-eth2-client v0.15.7
github.com/attestantio/go-eth2-client v0.18.4-0.20231004102804-73681300fc5f
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9
github.com/ethpandaops/ethwallclock v0.2.0
github.com/go-co-op/gocron v1.16.2
github.com/prometheus/client_golang v1.13.0
github.com/rs/zerolog v1.27.0
github.com/prometheus/client_golang v1.16.0
github.com/rs/zerolog v1.29.1
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cast v1.5.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/ferranbt/fastssz v0.1.2 // indirect
github.com/ferranbt/fastssz v0.1.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/goccy/go-yaml v1.9.5 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/holiman/uint256 v1.2.2 // indirect
github.com/klauspost/cpuid/v2 v2.1.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7 // indirect
github.com/r3labs/sse/v2 v2.7.4 // indirect
github.com/r3labs/sse/v2 v2.10.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/sys v0.2.0 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
542 changes: 55 additions & 487 deletions go.sum

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pkg/beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ type Node interface {
OnVoluntaryExit(ctx context.Context, handler func(ctx context.Context, ev *phase0.SignedVoluntaryExit) error)
// OnContributionAndProof is called when a contribution and proof is received.
OnContributionAndProof(ctx context.Context, handler func(ctx context.Context, ev *altair.SignedContributionAndProof) error)
// OnBlobSidecar is called when a blob sidecar is received.
OnBlobSidecar(ctx context.Context, handler func(ctx context.Context, ev *v1.BlobSidecarEvent) error)

// - Custom events
// OnReady is called when the node is ready.
Expand Down
1 change: 1 addition & 0 deletions pkg/beacon/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
topicHead = "head"
topicVoluntaryExit = "voluntary_exit"
topicContributionAndProof = "contribution_and_proof"
topicBlobSidecar = "blob_sidecar"
topicEvent = "raw_event"
)

Expand Down
4 changes: 4 additions & 0 deletions pkg/beacon/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func (n *node) publishContributionAndProof(ctx context.Context, event *altair.Si
n.broker.Emit(topicContributionAndProof, event)
}

func (n *node) publishBlobSidecar(ctx context.Context, event *v1.BlobSidecarEvent) {
n.broker.Emit(topicBlobSidecar, event)
}

func (n *node) publishEvent(ctx context.Context, event *v1.Event) {
n.broker.Emit(topicEvent, event)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/beacon/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func (n *node) OnContributionAndProof(ctx context.Context, handler func(ctx cont
})
}

func (n *node) OnBlobSidecar(ctx context.Context, handler func(ctx context.Context, event *v1.BlobSidecarEvent) error) {
n.broker.On(topicBlobSidecar, func(event *v1.BlobSidecarEvent) {
n.handleSubscriberError(handler(ctx, event), topicBlobSidecar)
})
}

func (n *node) OnEvent(ctx context.Context, handler func(ctx context.Context, event *v1.Event) error) {
n.broker.On(topicEvent, func(event *v1.Event) {
n.handleSubscriberError(handler(ctx, event), topicEvent)
Expand Down
13 changes: 13 additions & 0 deletions pkg/beacon/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ func (n *node) handleEvent(ctx context.Context, event *v1.Event) error {
return n.handleVoluntaryExit(ctx, event)
case topicContributionAndProof:
return n.handleContributionAndProof(ctx, event)
case topicBlobSidecar:
return n.handleBlobSidecar(ctx, event)

default:
return fmt.Errorf("unknown event topic %s", event.Topic)
Expand Down Expand Up @@ -175,3 +177,14 @@ func (n *node) handleContributionAndProof(ctx context.Context, event *v1.Event)

return nil
}

func (n *node) handleBlobSidecar(ctx context.Context, event *v1.Event) error {
blobSidecar, valid := event.Data.(*v1.BlobSidecarEvent)
if !valid {
return errors.New("invalid blob sidecar event")
}

n.publishBlobSidecar(ctx, blobSidecar)

return nil
}

0 comments on commit 1019d16

Please sign in to comment.