From af481985faee0e68259bb7be6e0dc655f9e3a739 Mon Sep 17 00:00:00 2001 From: Felipe Andrade Date: Mon, 15 May 2023 19:30:03 -0700 Subject: [PATCH] lint --- proxyd/proxyd/lvc.go | 87 ---------------------------------------- proxyd/proxyd/methods.go | 3 +- proxyd/proxyd/metrics.go | 16 -------- proxyd/proxyd/proxyd.go | 38 ------------------ 4 files changed, 2 insertions(+), 142 deletions(-) delete mode 100644 proxyd/proxyd/lvc.go diff --git a/proxyd/proxyd/lvc.go b/proxyd/proxyd/lvc.go deleted file mode 100644 index 146bbce..0000000 --- a/proxyd/proxyd/lvc.go +++ /dev/null @@ -1,87 +0,0 @@ -package proxyd - -import ( - "context" - "time" - - "github.com/ethereum/go-ethereum/ethclient" - "github.com/ethereum/go-ethereum/log" -) - -const cacheSyncRate = 1 * time.Second - -type lvcUpdateFn func(context.Context, *ethclient.Client) (string, error) - -type EthLastValueCache struct { - client *ethclient.Client - cache Cache - key string - updater lvcUpdateFn - quit chan struct{} -} - -func newLVC(client *ethclient.Client, cache Cache, cacheKey string, updater lvcUpdateFn) *EthLastValueCache { - return &EthLastValueCache{ - client: client, - cache: cache, - key: cacheKey, - updater: updater, - quit: make(chan struct{}), - } -} - -func (h *EthLastValueCache) Start() { - go func() { - ticker := time.NewTicker(cacheSyncRate) - defer ticker.Stop() - - for { - select { - case <-ticker.C: - lvcPollTimeGauge.WithLabelValues(h.key).SetToCurrentTime() - - value, err := h.getUpdate() - if err != nil { - log.Error("error retrieving latest value", "key", h.key, "error", err) - continue - } - log.Trace("polling latest value", "value", value) - - if err := h.cache.Put(context.Background(), h.key, value); err != nil { - log.Error("error writing last value to cache", "key", h.key, "error", err) - } - - case <-h.quit: - return - } - } - }() -} - -func (h *EthLastValueCache) getUpdate() (string, error) { - const maxRetries = 5 - var err error - - for i := 0; i <= maxRetries; i++ { - var value string - value, err = h.updater(context.Background(), h.client) - if err != nil { - backoff := calcBackoff(i) - log.Warn("http operation failed. retrying...", "error", err, "backoff", backoff) - lvcErrorsTotal.WithLabelValues(h.key).Inc() - time.Sleep(backoff) - continue - } - return value, nil - } - - return "", wrapErr(err, "exceeded retries") -} - -func (h *EthLastValueCache) Stop() { - close(h.quit) -} - -func (h *EthLastValueCache) Read(ctx context.Context) (string, error) { - return h.cache.Get(ctx, h.key) -} diff --git a/proxyd/proxyd/methods.go b/proxyd/proxyd/methods.go index 82f6138..43f93c5 100644 --- a/proxyd/proxyd/methods.go +++ b/proxyd/proxyd/methods.go @@ -3,9 +3,10 @@ package proxyd import ( "context" "encoding/json" - "github.com/ethereum/go-ethereum/log" "strings" "sync" + + "github.com/ethereum/go-ethereum/log" ) type RPCMethodHandler interface { diff --git a/proxyd/proxyd/metrics.go b/proxyd/proxyd/metrics.go index 66c1358..891cc9a 100644 --- a/proxyd/proxyd/metrics.go +++ b/proxyd/proxyd/metrics.go @@ -190,22 +190,6 @@ var ( "method", }) - lvcErrorsTotal = promauto.NewCounterVec(prometheus.CounterOpts{ - Namespace: MetricsNamespace, - Name: "lvc_errors_total", - Help: "Count of lvc errors.", - }, []string{ - "key", - }) - - lvcPollTimeGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: MetricsNamespace, - Name: "lvc_poll_time_gauge", - Help: "Gauge of lvc poll time.", - }, []string{ - "key", - }) - batchRPCShortCircuitsTotal = promauto.NewCounter(prometheus.CounterOpts{ Namespace: MetricsNamespace, Name: "batch_rpc_short_circuits_total", diff --git a/proxyd/proxyd/proxyd.go b/proxyd/proxyd/proxyd.go index a49f84e..15fd916 100644 --- a/proxyd/proxyd/proxyd.go +++ b/proxyd/proxyd/proxyd.go @@ -1,13 +1,11 @@ package proxyd import ( - "context" "crypto/tls" "errors" "fmt" "net/http" "os" - "strconv" "time" "github.com/ethereum/go-ethereum/common/math" @@ -370,39 +368,3 @@ func configureBackendTLS(cfg *BackendConfig) (*tls.Config, error) { return tlsConfig, nil } - -func makeUint64LastValueFn(client *ethclient.Client, cache Cache, key string, updater lvcUpdateFn) (*EthLastValueCache, func(context.Context) (uint64, error)) { - lvc := newLVC(client, cache, key, updater) - lvc.Start() - return lvc, func(ctx context.Context) (uint64, error) { - value, err := lvc.Read(ctx) - if err != nil { - return 0, err - } - if value == "" { - return 0, fmt.Errorf("%s is unavailable", key) - } - valueUint, err := strconv.ParseUint(value, 10, 64) - if err != nil { - return 0, err - } - return valueUint, nil - } -} - -func makeGetLatestBlockNumFn(client *ethclient.Client, cache Cache) (*EthLastValueCache, GetLatestBlockNumFn) { - return makeUint64LastValueFn(client, cache, "lvc:block_number", func(ctx context.Context, c *ethclient.Client) (string, error) { - blockNum, err := c.BlockNumber(ctx) - return strconv.FormatUint(blockNum, 10), err - }) -} - -func makeGetLatestGasPriceFn(client *ethclient.Client, cache Cache) (*EthLastValueCache, GetLatestGasPriceFn) { - return makeUint64LastValueFn(client, cache, "lvc:gas_price", func(ctx context.Context, c *ethclient.Client) (string, error) { - gasPrice, err := c.SuggestGasPrice(ctx) - if err != nil { - return "", err - } - return gasPrice.String(), nil - }) -}