Skip to content

Commit 2b2b562

Browse files
committed
add extra logging and always use calculated start index
1 parent 7e6d5cf commit 2b2b562

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

main.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,12 @@ func run(ctx context.Context) error {
8787
}
8888
}
8989

90-
newStartIndex, err := getStartIndex(ctx, db, ethClient, cfg, historyDrop)
90+
startIndex, err := getStartIndex(ctx, db, ethClient, cfg, historyDrop)
9191
if err != nil {
9292
return errors.Wrap(err, "getStartIndex error")
9393
}
9494

95-
if newStartIndex > cfg.Indexer.StartIndex {
96-
logger.Info("Setting new startIndex to: %d", newStartIndex)
97-
cfg.Indexer.StartIndex = newStartIndex
98-
}
95+
cfg.Indexer.StartIndex = startIndex
9996

10097
return runIndexer(ctx, cfg, db, ethClient, historyDrop)
10198
}
@@ -112,7 +109,7 @@ func getStartIndex(
112109

113110
// If a latest indexed block is found, return the next block number
114111
if err == nil {
115-
logger.Info("Latest indexed block from DB: %d", latestIndexedBlock.Number)
112+
logger.Info("Starting after latest indexed block from DB: %d", latestIndexedBlock.Number)
116113
return latestIndexedBlock.Number + 1, nil
117114
}
118115

@@ -124,6 +121,7 @@ func getStartIndex(
124121
// No blocks are indexed yet
125122
// If history drop is disabled, return the configured start index
126123
if historyDrop == 0 {
124+
logger.Info("No indexed blocks found in DB, starting from configured start index: %d", cfg.Indexer.StartIndex)
127125
return cfg.Indexer.StartIndex, nil
128126
}
129127

@@ -141,6 +139,7 @@ func getStartIndex(
141139
return 0, errors.Wrap(err, "GetStartBlock error")
142140
}
143141

142+
logger.Info("No indexed blocks found in DB, starting from calculated start index based on history drop: %d", firstBlockNumber)
144143
return firstBlockNumber, nil
145144
}
146145

0 commit comments

Comments
 (0)