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: resolve indexer infinite loop (upstream #82) #83

Merged
merged 1 commit into from
Oct 23, 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
26 changes: 18 additions & 8 deletions server/indexer_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/cenkalti/backoff/v4"
"github.com/cometbft/cometbft/libs/service"
rpcclient "github.com/cometbft/cometbft/rpc/client"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/cometbft/cometbft/types"

ethermint "github.com/evmos/ethermint/types"
Expand Down Expand Up @@ -111,24 +112,33 @@ func (eis *EVMIndexerService) OnStart() error {
if lastBlock == -1 {
lastBlock = latestBlock
}
// blockErr indicates an error fetching an expected block or its results
var blockErr error
for {
if latestBlock <= lastBlock {
// nothing to index. wait for signal of new block
var block *coretypes.ResultBlock
var blockResult *coretypes.ResultBlockResults
if latestBlock <= lastBlock || blockErr != nil {
// two cases:
// 1. nothing to index (indexer is caught up). wait for signal of new block.
// 2. previous attempt to index errored (failed to fetch the Block or BlockResults).
// in this case, wait before retrying the data fetching, rather than infinite looping
// a failing fetch. this can occur due to drive latency between the block existing and its
// block_results getting saved.
select {
case <-newBlockSignal:
case <-time.After(NewBlockWaitTimeout):
}
continue
}
for i := lastBlock + 1; i <= latestBlock; i++ {
block, err := eis.client.Block(ctx, &i)
if err != nil {
eis.Logger.Error("failed to fetch block", "height", i, "err", err)
block, blockErr = eis.client.Block(ctx, &i)
if blockErr != nil {
eis.Logger.Error("failed to fetch block", "height", i, "err", blockErr)
break
}
blockResult, err := eis.client.BlockResults(ctx, &i)
if err != nil {
eis.Logger.Error("failed to fetch block result", "height", i, "err", err)
blockResult, blockErr = eis.client.BlockResults(ctx, &i)
if blockErr != nil {
eis.Logger.Error("failed to fetch block result", "height", i, "err", blockErr)
break
}
if err := eis.txIdxr.IndexBlock(block.Block, blockResult.TxsResults); err != nil {
Expand Down
Loading