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

Add tolerance to nil response for error log #1070

Merged
merged 4 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
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: 19 additions & 6 deletions oracle/price-feeder/oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,15 +701,11 @@ func (o *Oracle) tick(

resp, err := o.oracleClient.BroadcastTx(clientCtx, voteMsg)
if err != nil {
o.logger.Error().Err(err).
Str("status", "failure").
Uint32("response_code", resp.Code).
Str("tx_hash", resp.TxHash).
Int64("tick_duration", time.Since(startTime).Milliseconds()).
Msg(fmt.Sprintf("broadcasted for height %d", blockHeight))
o.logResponseError(err, resp, startTime, blockHeight)
telemetry.IncrCounter(1, "failure", "broadcast")
return err
}

o.logger.Info().
Str("status", "success").
Uint32("response_code", resp.Code).
Expand All @@ -724,6 +720,23 @@ func (o *Oracle) tick(
return nil
}

func (o *Oracle) logResponseError(err error, resp *sdk.TxResponse, startTime time.Time, blockHeight int64) {
responseCode := -1 // success is 0
var txHash string

if resp != nil {
responseCode = int(resp.Code)
txHash = resp.TxHash
}

o.logger.Error().Err(err).
Str("status", "failure").
Int("response_code", responseCode).
Str("tx_hash", txHash).
Int64("tick_duration", time.Since(startTime).Milliseconds()).
Msg(fmt.Sprintf("broadcasted for height %d", blockHeight))
}

func (o *Oracle) healthchecksPing() {
for url, client := range o.healthchecks {
o.logger.Info().Msg("updating healthcheck status")
Expand Down
31 changes: 31 additions & 0 deletions oracle/price-feeder/oracle/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ func TestTickScenarios(t *testing.T) {
blockHeight int64
previousVotePeriod float64
votePeriod uint64
mockBroadcastErr error

// expectations
expectedVoteMsg *oracletypes.MsgAggregateExchangeRateVote
Expand Down Expand Up @@ -617,6 +618,31 @@ func TestTickScenarios(t *testing.T) {
Validator: validatorAddr,
},
},
{
name: "Should not crash if broadcast returns nil response with error",
isJailed: false,
blockHeight: 1,
previousVotePeriod: 0,
votePeriod: 1,
pairs: []config.CurrencyPair{
{Base: "USDT", ChainDenom: "uusdt", Quote: "USD"},
{Base: "BTC", ChainDenom: "ubtc", Quote: "USD"},
{Base: "ETH", ChainDenom: "ueth", Quote: "USD"},
},
prices: map[string]sdk.Dec{
"USDT": sdk.MustNewDecFromStr("1.1"),
"BTC": sdk.MustNewDecFromStr("2.2"),
"ETH": sdk.MustNewDecFromStr("3.3"),
},
whitelist: denomList("uusdt", "ubtc", "ueth"),
expectedVoteMsg: &oracletypes.MsgAggregateExchangeRateVote{
ExchangeRates: "2.200000000000000000ubtc,3.300000000000000000ueth,1.100000000000000000uusdt",
Feeder: feederAddr,
Validator: validatorAddr,
},
mockBroadcastErr: fmt.Errorf("test error"),
expectedErr: fmt.Errorf("test error"),
},
{
name: "Same voting period should avoid broadcasting without error",
isJailed: false,
Expand Down Expand Up @@ -682,6 +708,11 @@ func TestTickScenarios(t *testing.T) {
require.Equal(t, test.expectedVoteMsg.Validator, voteMsg.Validator, test.name)

broadcastCount++

if test.mockBroadcastErr != nil {
return nil, test.mockBroadcastErr
}

return &sdk.TxResponse{TxHash: "0xhash", Code: 200}, nil
},
},
Expand Down