Skip to content

Commit

Permalink
node: Add cache buster for CoinGecko price queries
Browse files Browse the repository at this point in the history
  • Loading branch information
djb15 committed Nov 14, 2023
1 parent 01d4855 commit 0764e2f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions node/pkg/governor/governor_prices.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
"fmt"
"io"
"math/big"
"math/rand"
"net/http"
"net/url"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 0764e2f

Please sign in to comment.