Governor: Increase the CoinGecko interval (#1837)

* Governor: Increase the CoinGecko interval

Change-Id: I4f97a012284c75d544a1fe7d43e5914210c4b441

* Suppress a chatty message for pythnet

Change-Id: I2149b056bfc430b6dedd180e951f345180e8a56d
This commit is contained in:
bruce-riley 2022-11-01 10:13:19 -05:00 committed by GitHub
parent a7d79407f4
commit 2ae9f65a76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View File

@ -301,7 +301,9 @@ func (gov *ChainGovernor) ProcessMsgForTime(msg *common.MessagePublication, now
// If we don't care about this chain, the VAA can be published.
if !exists {
gov.logger.Info("cgov: ignoring vaa because the emitter chain is not configured", zap.String("msgID", msg.MessageIDString()))
if msg.EmitterChain != vaa.ChainIDPythNet {
gov.logger.Info("cgov: ignoring vaa because the emitter chain is not configured", zap.String("msgID", msg.MessageIDString()))
}
return true, nil
}

View File

@ -14,6 +14,7 @@ import (
"math/big"
"net/http"
"net/url"
"strings"
"time"
"go.uber.org/zap"
@ -25,7 +26,7 @@ import (
// The CoinGecko API is documented here: https://www.coingecko.com/en/api/documentation
// An example of the query to be generated: https://api.coingecko.com/api/v3/simple/price?ids=gemma-extending-tech,bitcoin,weth&vs_currencies=usd
const coinGeckoQueryIntervalInMins = 5
const coinGeckoQueryIntervalInMins = 15
func (gov *ChainGovernor) initCoinGecko(ctx context.Context, run bool) error {
ids := ""
@ -80,7 +81,10 @@ func (gov *ChainGovernor) PriceQuery(ctx context.Context) error {
}
}
// This does not return an error. Instead, it just logs the error and we will try again five minutes later.
// queryCoinGecko sends a query to the CoinGecko server to get the latest prices. It can
// return an error, but that is only used by the tool that validates the query. In the actual governor,
// it just logs the error and we will try again next interval. If an error happens, any tokens that have
// not been updated will be assigned their pre-configured price.
func (gov *ChainGovernor) queryCoinGecko() error {
response, err := http.Get(gov.coinGeckoQuery)
if err != nil {
@ -105,6 +109,17 @@ func (gov *ChainGovernor) queryCoinGecko() error {
return fmt.Errorf("failed to parse CoinGecko response")
}
resp := string(responseData)
if strings.Contains(resp, "error_code") {
gov.logger.Error("cgov: coin gecko query failed, reverting to configured prices",
zap.String("response", resp),
zap.String("query", gov.coinGeckoQuery),
)
gov.revertAllPrices()
return fmt.Errorf("coin gecko query failed: %s", resp)
}
var result map[string]interface{}
if err := json.Unmarshal(responseData, &result); err != nil {
gov.logger.Error("cgov: failed to unmarshal coin gecko json, reverting to configured prices", zap.Error(err))
@ -174,7 +189,7 @@ func (gov *ChainGovernor) revertAllPrices() {
for _, cge := range gov.tokensByCoinGeckoId {
for _, te := range cge {
gov.logger.Error("cgov: reverting to configured price",
gov.logger.Info("cgov: reverting to configured price",
zap.String("symbol", te.symbol),
zap.String("coinGeckoId",
te.coinGeckoId),