node: Add cache buster for CoinGecko price queries (#3528)

This commit is contained in:
Dirk Brink 2023-11-21 11:40:11 -08:00 committed by GitHub
parent 49549eb01c
commit 630c5c3231
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -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))