diff --git a/indexer/indexer.go b/indexer/indexer.go index 6ff4ea4..b77f403 100755 --- a/indexer/indexer.go +++ b/indexer/indexer.go @@ -21,6 +21,7 @@ type Indexer struct { serverAddr string prefix string runMode string + fix bool networkTypeForCccv string indexNamePrefix string aliasNamePrefix string diff --git a/indexer/option.go b/indexer/option.go index d7a2472..3aa2e8e 100644 --- a/indexer/option.go +++ b/indexer/option.go @@ -49,6 +49,13 @@ func SetRunMode(runMode string) IndexerOptionFunc { } } +func SetFix(fix bool) IndexerOptionFunc { + return func(indexer *Indexer) error { + indexer.fix = fix + return nil + } +} + func SetWhiteListAddresses(whiteListAddresses []string) IndexerOptionFunc { return func(indexer *Indexer) error { indexer.balanceWhitelist = whiteListAddresses diff --git a/indexer/run_check.go b/indexer/run_check.go index b672a9a..e849e2f 100755 --- a/indexer/run_check.go +++ b/indexer/run_check.go @@ -16,7 +16,11 @@ func (ns *Indexer) Check(startFrom uint64, stopAt uint64) { if stopAt == 0 { stopAt = ns.GetBestBlock() - 1 } - ns.fixIndex(startFrom, stopAt) + if ns.fix == true { + ns.fixIndex(startFrom, stopAt) + } else { + ns.checkIndex(startFrom, stopAt) + } // remove clean index logic // err := ns.cleanIndex() @@ -25,7 +29,7 @@ func (ns *Indexer) Check(startFrom uint64, stopAt uint64) { // } } -func (ns *Indexer) fixIndex(startFrom uint64, stopAt uint64) { +func (ns *Indexer) checkIndex(startFrom uint64, stopAt uint64) { ns.log.Info().Uint64("startFrom", startFrom).Uint64("stopAt", stopAt).Msg("Check Block range") ns.bulk.StartBulkChannel() @@ -88,6 +92,16 @@ func (ns *Indexer) fixIndex(startFrom uint64, stopAt uint64) { ns.log.Info().Uint64("missing", missingBlocks).Msg("Done with consistency check") } +func (ns *Indexer) fixIndex(startFrom uint64, stopAt uint64) { + ns.log.Info().Uint64("startFrom", startFrom).Uint64("stopAt", stopAt).Msg("Fix Block range") + ns.bulk.StartBulkChannel() + + ns.bulk.InsertBlocksInRange(startFrom, stopAt) + + ns.bulk.StopBulkChannel() + ns.log.Info().Msg("Done with fix") +} + // Start clean the indexer func (ns *Indexer) cleanIndex() error { ns.log.Info().Msg("Clean index Start...")