erigon-pulse/cmd/state/generate/regenerate_index.go
b00ris b4ba764fb1
[WIP] TxLookup stage (#646)
* save state

* txlookup full results

* save state

* save state

* remove experiments

* some fix&lint

* add end key to txLookup and index generation

* change log message

* change log

* fix lint

* lint

* fix test
2020-06-10 23:07:14 +03:00

52 lines
1.2 KiB
Go

package generate
import (
"errors"
"github.com/ledgerwatch/turbo-geth/core"
"github.com/ledgerwatch/turbo-geth/eth/stagedsync/stages"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/ledgerwatch/turbo-geth/log"
"os"
"os/signal"
"time"
)
func RegenerateIndex(chaindata string, csBucket []byte) error {
db, err := ethdb.NewBoltDatabase(chaindata)
if err != nil {
return err
}
ch := make(chan os.Signal, 1)
quitCh := make(chan struct{})
signal.Notify(ch, os.Interrupt)
go func() {
<-ch
close(quitCh)
}()
lastExecutedBlock, _, err := stages.GetStageProgress(db, stages.Execution)
if err != nil {
//There could be headers without block in the end
log.Error("Cant get last executed block", "err", err)
}
ig := core.NewIndexGenerator(db, quitCh)
cs, ok := core.CSMapper[string(csBucket)]
if !ok {
return errors.New("unknown changeset")
}
err = ig.DropIndex(cs.IndexBucket)
if err != nil {
return err
}
startTime := time.Now()
log.Info("Index generation started", "start time", startTime)
err = ig.GenerateIndex(0, lastExecutedBlock, csBucket)
if err != nil {
return err
}
log.Info("Index is successfully regenerated", "it took", time.Since(startTime))
return nil
}