From 630c5c3231b92ec39c03849a6c590edb119e4eb4 Mon Sep 17 00:00:00 2001 From: Dirk Brink Date: Tue, 21 Nov 2023 11:40:11 -0800 Subject: [PATCH] node: Add cache buster for CoinGecko price queries (#3528) --- node/pkg/governor/governor_prices.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/node/pkg/governor/governor_prices.go b/node/pkg/governor/governor_prices.go index 1cecfd7f4..9741c367c 100644 --- a/node/pkg/governor/governor_prices.go +++ b/node/pkg/governor/governor_prices.go @@ -12,8 +12,10 @@ import ( "fmt" "io" "math/big" + "math/rand" "net/http" "net/url" + "strconv" "strings" "time" @@ -128,7 +130,13 @@ func (gov *ChainGovernor) PriceQuery(ctx context.Context) error { // not been updated will be assigned their pre-configured price. func (gov *ChainGovernor) queryCoinGecko() error { result := make(map[string]interface{}) + + // Cache buster of Unix timestamp concatenated with random number + params := url.Values{} + params.Add("bust", strconv.Itoa(int(time.Now().Unix()))+strconv.Itoa(rand.Int())) // #nosec G404 + for queryIdx, query := range gov.coinGeckoQueries { + query := query + "&" + params.Encode() thisResult, err := gov.queryCoinGeckoChunk(query) if err != nil { gov.logger.Error("CoinGecko query failed", zap.Int("queryIdx", queryIdx), zap.String("query", query), zap.Error(err))