From 3fcd1bfd3ef406f316d451782e2cf71572e24a9a Mon Sep 17 00:00:00 2001 From: Andrew Davis <1709934+Savid@users.noreply.github.com> Date: Thu, 12 Oct 2023 21:21:27 +1000 Subject: [PATCH] feat(sentry): allow config subscription of topics --- docs/sentry.md | 1 + pkg/sentry/ethereum/beacon.go | 10 +++++++++- pkg/sentry/ethereum/config.go | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/sentry.md b/docs/sentry.md index 7f09e67a..58aa6f67 100644 --- a/docs/sentry.md +++ b/docs/sentry.md @@ -47,6 +47,7 @@ Sentry requires a single `yaml` config file. An example file can be found [here] | name | string | | Unique name of the sentry | | labels | object | | A key value map of labels to append to every sentry event | | ethereum.beaconNodeAddress | string | | [Ethereum consensus client](https://ethereum.org/en/developers/docs/nodes-and-clients/#consensus-clients) http server endpoint | +| ethereum.beaconSubscriptions | array | | List of [topcis](https://ethereum.github.io/beacon-APIs/#/Events/eventstream) to subscribe to. If empty, all subscriptions are subscribed to. | ntpServer | string | `pool.ntp.org` | NTP server to calculate clock drift for events | | outputs | array | | List of outputs for the sentry to send data to | | outputs[].name | string | | Name of the output | diff --git a/pkg/sentry/ethereum/beacon.go b/pkg/sentry/ethereum/beacon.go index 5c5becf3..51243f77 100644 --- a/pkg/sentry/ethereum/beacon.go +++ b/pkg/sentry/ethereum/beacon.go @@ -27,9 +27,17 @@ type BeaconNode struct { func NewBeaconNode(ctx context.Context, name string, config *Config, log logrus.FieldLogger) (*BeaconNode, error) { opts := *beacon. DefaultOptions(). - EnableDefaultBeaconSubscription(). DisablePrometheusMetrics() + if config.BeaconSubscriptions != nil { + opts.BeaconSubscription = beacon.BeaconSubscriptionOptions{ + Enabled: true, + Topics: *config.BeaconSubscriptions, + } + } else { + opts.EnableDefaultBeaconSubscription() + } + opts.HealthCheck.Interval.Duration = time.Second * 3 opts.HealthCheck.SuccessfulResponses = 1 diff --git a/pkg/sentry/ethereum/config.go b/pkg/sentry/ethereum/config.go index 2a6b4134..c8e86cf3 100644 --- a/pkg/sentry/ethereum/config.go +++ b/pkg/sentry/ethereum/config.go @@ -10,6 +10,8 @@ type Config struct { OverrideNetworkName string `yaml:"overrideNetworkName" default:""` // BeaconNodeHeaders is a map of headers to send to the beacon node. BeaconNodeHeaders map[string]string `yaml:"beaconNodeHeaders"` + // BeaconSubscriptions is a list of beacon subscriptions to subscribe to. + BeaconSubscriptions *[]string `yaml:"beaconSubscriptions"` } func (c *Config) Validate() error {