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

CosmosChainProcessor - skip blocks after max retries #1154

Merged
merged 1 commit into from
Mar 29, 2023
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
23 changes: 18 additions & 5 deletions relayer/chains/cosmos/cosmos_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const (
defaultMinQueryLoopDuration = 1 * time.Second
defaultBalanceUpdateWaitDuration = 60 * time.Second
inSyncNumBlocksThreshold = 2
blockMaxRetries = 5
)

// latestClientState is a map of clientID to the latest clientInfo for that client.
Expand Down Expand Up @@ -180,11 +181,12 @@ func (ccp *CosmosChainProcessor) clientState(ctx context.Context, clientID strin

// queryCyclePersistence hold the variables that should be retained across queryCycles.
type queryCyclePersistence struct {
latestHeight int64
latestQueriedBlock int64
minQueryLoopDuration time.Duration
lastBalanceUpdate time.Time
balanceUpdateWaitDuration time.Duration
latestHeight int64
latestQueriedBlock int64
retriesAtLatestQueriedBlock int
minQueryLoopDuration time.Duration
lastBalanceUpdate time.Time
balanceUpdateWaitDuration time.Duration
}

// Run starts the query loop for the chain which will gather applicable ibc messages and push events out to the relevant PathProcessors.
Expand Down Expand Up @@ -374,9 +376,20 @@ func (ccp *CosmosChainProcessor) queryCycle(ctx context.Context, persistence *qu

if err := eg.Wait(); err != nil {
ccp.log.Warn("Error querying block data", zap.Error(err))

persistence.retriesAtLatestQueriedBlock++
if persistence.retriesAtLatestQueriedBlock >= blockMaxRetries {
ccp.log.Warn("Reached max retries querying for block, skipping", zap.Int64("height", i))
// skip this block. now depends on flush to pickup anything missed in the block.
persistence.latestQueriedBlock = i
persistence.retriesAtLatestQueriedBlock = 0
continue
}
break
}

persistence.retriesAtLatestQueriedBlock = 0

latestHeader = ibcHeader.(provider.TendermintIBCHeader)

heightUint64 := uint64(i)
Expand Down