mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-27 22:28:21 +00:00
eca0f233ec
* save state * walkAsOf by cs test passed * cs search for plain state * save state * fix accounts tests * refactor walkAsOf account tests * fix storage test * refactor walkAsOf storage tests * fix lint * fix test * save state * save state * add test with fixed bits * fmt * add stages check * fix lint * fix lint * remove obsoleted methods
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package generate
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/ledgerwatch/turbo-geth/common/changeset"
|
|
"os"
|
|
"os/signal"
|
|
"time"
|
|
|
|
"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"
|
|
)
|
|
|
|
func RegenerateIndex(chaindata string, csBucket []byte) error {
|
|
db := ethdb.MustOpen(chaindata)
|
|
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 := changeset.Mapper[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
|
|
}
|