Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wallet balance metric occasionally reporting false 0 amounts #1433

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions relayer/chains/cosmos/cosmos_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand All @@ -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

Expand All @@ -559,28 +564,19 @@ 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
}

// 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
Expand All @@ -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
}
Loading