From 466a88776f433e803267ef389451b6aa1da9d6f2 Mon Sep 17 00:00:00 2001 From: Sam Calder-Mason Date: Wed, 20 Dec 2023 19:48:01 +1000 Subject: [PATCH] fix(sentry): Hard exit if unknown ethereum network --- pkg/sentry/ethereum/beacon.go | 2 +- pkg/sentry/ethereum/services/metadata.go | 21 +++++++++++++++------ pkg/sentry/sentry.go | 7 +++++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/pkg/sentry/ethereum/beacon.go b/pkg/sentry/ethereum/beacon.go index 51243f77..913be3b9 100644 --- a/pkg/sentry/ethereum/beacon.go +++ b/pkg/sentry/ethereum/beacon.go @@ -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{ diff --git a/pkg/sentry/ethereum/services/metadata.go b/pkg/sentry/ethereum/services/metadata.go index aa448eb9..10901ffa 100644 --- a/pkg/sentry/ethereum/services/metadata.go +++ b/pkg/sentry/ethereum/services/metadata.go @@ -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, } } @@ -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, diff --git a/pkg/sentry/sentry.go b/pkg/sentry/sentry.go index ff90f125..2bbdb2b8 100644 --- a/pkg/sentry/sentry.go +++ b/pkg/sentry/sentry.go @@ -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" @@ -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) @@ -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 }