From 64a06143a428e6db1efc582ddad5efe3d489ca7c Mon Sep 17 00:00:00 2001 From: Sam Calder-Mason Date: Fri, 7 Feb 2025 09:16:53 +1000 Subject: [PATCH] feat(beacon): refactor HTTP client initialization to use a parameter slice for better flexibility and maintainability feat(beacon): add methods to Options struct for managing GoEth2Client parameters to enhance configurability --- pkg/beacon/bootstrap.go | 9 ++++++--- pkg/beacon/options.go | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pkg/beacon/bootstrap.go b/pkg/beacon/bootstrap.go index 4fd124e..03ea58b 100644 --- a/pkg/beacon/bootstrap.go +++ b/pkg/beacon/bootstrap.go @@ -30,13 +30,16 @@ func (n *node) ensureClients(ctx context.Context) error { default: timeout := 10 * time.Minute - client, err := ehttp.New(ctx, + params := []ehttp.Parameter{ ehttp.WithAddress(n.config.Addr), ehttp.WithLogLevel(zerologLevel), ehttp.WithTimeout(timeout), ehttp.WithExtraHeaders(n.config.Headers), - ehttp.WithEnforceJSON(true), // TODO(sam): HACK: Remove this once we have a proper spec - ) + } + + params = append(params, n.options.GetGoEth2ClientParams()...) + + client, err := ehttp.New(ctx, params...) if err != nil { failures++ diff --git a/pkg/beacon/options.go b/pkg/beacon/options.go index c6e3414..cb0ee39 100644 --- a/pkg/beacon/options.go +++ b/pkg/beacon/options.go @@ -3,6 +3,7 @@ package beacon import ( "time" + ehttp "github.com/attestantio/go-eth2-client/http" "github.com/ethpandaops/beacon/pkg/human" ) @@ -12,6 +13,7 @@ type Options struct { HealthCheck HealthCheckOptions PrometheusMetrics bool DetectEmptySlots bool + GoEth2ClientParams []ehttp.Parameter } // EnablePrometheusMetrics enables Prometheus metrics. @@ -122,3 +124,15 @@ func DefaultHealthCheckOptions() HealthCheckOptions { FailedResponses: 3, } } + +// AddGoEth2ClientParams adds the given parameters to the options. +func (o *Options) AddGoEth2ClientParams(params ...ehttp.Parameter) *Options { + o.GoEth2ClientParams = append(o.GoEth2ClientParams, params...) + + return o +} + +// GetGoEth2ClientParams returns the parameters for the go-eth2-client. +func (o *Options) GetGoEth2ClientParams() []ehttp.Parameter { + return o.GoEth2ClientParams +}