From bc46373aad07747bbc3c8e1e01d11664a042edba Mon Sep 17 00:00:00 2001 From: Dan Kanefsky <56059752+boojamya@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:32:27 -0700 Subject: [PATCH] fix wallet balance metric (#1433) Co-authored-by: Justin Tieri <37750742+jtieri@users.noreply.github.com> --- .../chains/cosmos/cosmos_chain_processor.go | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/relayer/chains/cosmos/cosmos_chain_processor.go b/relayer/chains/cosmos/cosmos_chain_processor.go index 26004e64c..4a95d66a3 100644 --- a/relayer/chains/cosmos/cosmos_chain_processor.go +++ b/relayer/chains/cosmos/cosmos_chain_processor.go @@ -538,7 +538,12 @@ func (ccp *CosmosChainProcessor) CollectMetrics(ctx context.Context, persistence // Wait a while before updating the balance if time.Since(persistence.lastBalanceUpdate) > persistence.balanceUpdateWaitDuration { - ccp.CurrentRelayerBalance(ctx) + err := ccp.CurrentRelayerBalance(ctx) + if err != nil { + ccp.log.Error(fmt.Sprintf("Failed to update wallet balance metric. Will retry in %v.", persistence.balanceUpdateWaitDuration), + zap.Error(err)) + return + } persistence.lastBalanceUpdate = time.Now() } } @@ -547,7 +552,7 @@ func (ccp *CosmosChainProcessor) CurrentBlockHeight(ctx context.Context, persist ccp.metrics.SetLatestHeight(ccp.chainProvider.ChainId(), persistence.latestHeight) } -func (ccp *CosmosChainProcessor) CurrentRelayerBalance(ctx context.Context) { +func (ccp *CosmosChainProcessor) CurrentRelayerBalance(ctx context.Context) error { // memoize the current gas prices to only show metrics for "interesting" denoms gasPrice := ccp.chainProvider.PCfg.GasPrices @@ -559,10 +564,7 @@ func (ccp *CosmosChainProcessor) CurrentRelayerBalance(ctx context.Context) { gp, err := sdk.ParseDecCoins(gasPrice) if err != nil { - ccp.log.Error( - "Failed to parse gas prices", - zap.Error(err), - ) + return fmt.Errorf("failed to parse gas prices: %w", err) } ccp.parsedGasPrices = &gp } @@ -570,17 +572,11 @@ func (ccp *CosmosChainProcessor) CurrentRelayerBalance(ctx context.Context) { // Get the balance for the chain provider's key relayerWalletBalances, err := ccp.chainProvider.QueryBalance(ctx, ccp.chainProvider.Key()) if err != nil { - ccp.log.Error( - "Failed to query relayer balance", - zap.Error(err), - ) + return fmt.Errorf("failed to query relayer balance: %w", err) } address, err := ccp.chainProvider.Address() if err != nil { - ccp.log.Error( - "Failed to get relayer bech32 wallet address", - zap.Error(err), - ) + return fmt.Errorf("failed to get relayer bech32 address: %w", err) } // Print the relevant gas prices @@ -591,4 +587,5 @@ func (ccp *CosmosChainProcessor) CurrentRelayerBalance(ctx context.Context) { f, _ := big.NewFloat(0.0).SetInt(bal.BigInt()).Float64() ccp.metrics.SetWalletBalance(ccp.chainProvider.ChainId(), gasPrice, ccp.chainProvider.Key(), address, gasDenom.Denom, f) } + return nil }