Skip to content

Commit

Permalink
fix(sentry): Hard exit if unknown ethereum network (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Dec 22, 2023
1 parent 6350812 commit 99633fd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/sentry/ethereum/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewBeaconNode(ctx context.Context, name string, config *Config, log logrus.
Headers: config.BeaconNodeHeaders,
}, "xatu_sentry", opts)

metadata := services.NewMetadataService(log, node)
metadata := services.NewMetadataService(log, node, config.OverrideNetworkName)
duties := services.NewDutiesService(log, node, &metadata)

svcs := []services.Service{
Expand Down
21 changes: 15 additions & 6 deletions pkg/sentry/ethereum/services/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@ type MetadataService struct {

onReadyCallbacks []func(context.Context) error

overrideNetworkName string

mu sync.Mutex
}

func NewMetadataService(log logrus.FieldLogger, sbeacon beacon.Node) MetadataService {
func NewMetadataService(log logrus.FieldLogger, sbeacon beacon.Node, overrideNetworkName string) MetadataService {
return MetadataService{
beacon: sbeacon,
log: log.WithField("module", "sentry/ethereum/metadata"),
Network: &networks.Network{Name: networks.NetworkNameNone},
onReadyCallbacks: []func(context.Context) error{},
mu: sync.Mutex{},
beacon: sbeacon,
log: log.WithField("module", "sentry/ethereum/metadata"),
Network: &networks.Network{Name: networks.NetworkNameNone},
onReadyCallbacks: []func(context.Context) error{},
mu: sync.Mutex{},
overrideNetworkName: overrideNetworkName,
}
}

Expand Down Expand Up @@ -157,6 +160,12 @@ func (m *MetadataService) DeriveNetwork(_ context.Context) error {

network := networks.DeriveFromGenesisRoot(xatuethv1.RootAsString(m.Genesis.GenesisValidatorsRoot))

if m.overrideNetworkName != "" {
network.Name = networks.NetworkName(m.overrideNetworkName)

network.ID = m.Spec.DepositChainID
}

if network.Name != m.Network.Name {
m.log.WithFields(logrus.Fields{
"name": network.Name,
Expand Down
7 changes: 7 additions & 0 deletions pkg/sentry/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/attestantio/go-eth2-client/spec/altair"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/beevik/ntp"
"github.com/ethpandaops/xatu/pkg/networks"
"github.com/ethpandaops/xatu/pkg/output"
xatuethv1 "github.com/ethpandaops/xatu/pkg/proto/eth/v1"
"github.com/ethpandaops/xatu/pkg/proto/xatu"
Expand Down Expand Up @@ -116,6 +117,10 @@ func (s *Sentry) Start(ctx context.Context) error {
s.beacon.OnReady(ctx, func(ctx context.Context) error {
s.log.Info("Internal beacon node is ready, subscribing to events")

if s.beacon.Metadata().Network.Name == networks.NetworkNameUnknown {
s.log.Fatal("Unable to determine Ethereum network. Provide an override network name via ethereum.overrideNetworkName")
}

s.beacon.Node().OnAttestation(ctx, func(ctx context.Context, attestation *phase0.Attestation) error {
now := time.Now().Add(s.clockDrift)

Expand Down Expand Up @@ -399,6 +404,8 @@ func (s *Sentry) Start(ctx context.Context) error {
}

for _, sink := range s.sinks {
s.log.WithField("type", sink.Type()).WithField("name", sink.Name()).Info("Starting sink")

if err := sink.Start(ctx); err != nil {
return err
}
Expand Down

0 comments on commit 99633fd

Please sign in to comment.