diff --git a/api/api.go b/api/api.go index d10ba01..9816fd0 100644 --- a/api/api.go +++ b/api/api.go @@ -8,7 +8,6 @@ import ( "io" "net/http" "net/url" - "time" "github.com/samcm/beacon/api/types" "github.com/sirupsen/logrus" @@ -29,11 +28,7 @@ type consensusClient struct { } // NewConsensusClient creates a new ConsensusClient. -func NewConsensusClient(ctx context.Context, log logrus.FieldLogger, url string) ConsensusClient { - client := http.Client{ - Timeout: time.Second * 10, - } - +func NewConsensusClient(ctx context.Context, log logrus.FieldLogger, url string, client http.Client) ConsensusClient { return &consensusClient{ url: url, log: log, diff --git a/bootstrap.go b/bootstrap.go index e26d31b..4557734 100644 --- a/bootstrap.go +++ b/bootstrap.go @@ -2,10 +2,11 @@ package beacon import ( "context" + "net/http" "time" eth2client "github.com/attestantio/go-eth2-client" - "github.com/attestantio/go-eth2-client/http" + ehttp "github.com/attestantio/go-eth2-client/http" "github.com/rs/zerolog" "github.com/samcm/beacon/api" ) @@ -25,10 +26,12 @@ func (n *node) ensureClients(ctx context.Context) error { case <-ctx.Done(): return ctx.Err() default: - client, err := http.New(ctx, - http.WithAddress(n.config.Addr), - http.WithLogLevel(zerolog.Disabled), - http.WithTimeout(90*time.Second), + timeout := 90 * time.Second + + client, err := ehttp.New(ctx, + ehttp.WithAddress(n.config.Addr), + ehttp.WithLogLevel(zerolog.Disabled), + ehttp.WithTimeout(timeout), ) if err != nil { failures++ @@ -48,7 +51,12 @@ func (n *node) ensureClients(ctx context.Context) error { } n.client = client - n.api = api.NewConsensusClient(ctx, n.log, n.config.Addr) + + httpClient := http.Client{ + Timeout: timeout, + } + + n.api = api.NewConsensusClient(ctx, n.log, n.config.Addr, httpClient) break }