Skip to content

Commit

Permalink
add fix mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitprincess committed Aug 30, 2023
1 parent 4fe914b commit f0f299c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Indexer struct {
serverAddr string
prefix string
runMode string
fix bool
networkTypeForCccv string
indexNamePrefix string
aliasNamePrefix string
Expand Down
7 changes: 7 additions & 0 deletions indexer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions indexer/run_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()

Expand Down Expand Up @@ -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...")
Expand Down

0 comments on commit f0f299c

Please sign in to comment.