From f1adba7cf469158816caf7c9cde3c44094b4c0dd Mon Sep 17 00:00:00 2001 From: "Biru C. Sainju" Date: Tue, 6 Aug 2024 12:31:51 +0545 Subject: [PATCH] fix: added retry when fetching client state which resulted in packets missing procesing --- relayer/chains/wasm/wasm_chain_processor.go | 29 +++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/relayer/chains/wasm/wasm_chain_processor.go b/relayer/chains/wasm/wasm_chain_processor.go index 5dd19d2c6..f4f946846 100644 --- a/relayer/chains/wasm/wasm_chain_processor.go +++ b/relayer/chains/wasm/wasm_chain_processor.go @@ -89,7 +89,9 @@ const ( queryTimeout = 5 * time.Second blockResultsQueryTimeout = 2 * time.Minute latestHeightQueryRetryDelay = 1 * time.Second + clientStateQueryRetryDelay = 1 * time.Second latestHeightQueryRetries = 5 + clientStateQueryRetries = 5 // TODO: review transfer to providerConfig defaultMinQueryLoopDuration = 1 * time.Second @@ -579,15 +581,32 @@ func (ccp *WasmChainProcessor) queryCycle(ctx context.Context, persistence *quer } for _, pp := range ccp.pathProcessors { - clientID := pp.RelevantClientID(chainID) - clientState, err := ccp.clientState(ctx, clientID) - if err != nil { - ccp.log.Error("Error fetching client state", - zap.String("client_id", clientID), + var clientState provider.ClientState + var clientID string + retry.Do(func() error { + clientID = pp.RelevantClientID(chainID) + clientState, err = ccp.clientState(ctx, clientID) + return err + }, retry.Context(ctx), retry.Attempts(clientStateQueryRetries), + retry.Delay(clientStateQueryRetryDelay), + retry.OnRetry(func(n uint, err error) { + ccp.log.Error( + "Error fetching client state", + zap.Uint("attempt", n+1), + zap.Uint("max_attempts", clientStateQueryRetries), + zap.Error(err), + ) + })) + if clientState.ClientID == "" { + ccp.log.Error( + "Error fetching client state after max retries", + zap.Int64("latest_queried_block", newLatestQueriedBlock), + zap.Int64("last_queried_block", persistence.latestQueriedBlock), zap.Error(err), ) continue } + pp.HandleNewData(chainID, processor.ChainProcessorCacheData{ LatestBlock: ccp.latestBlock, LatestHeader: latestHeader,