2020-06-10 20:07:14 +00:00
|
|
|
package generate
|
|
|
|
|
|
|
|
import (
|
2020-06-16 13:36:16 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"time"
|
|
|
|
|
2020-06-10 20:07:14 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/common/dbutils"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/eth/stagedsync"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/eth/stagedsync/stages"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func RegenerateTxLookup(chaindata string) error {
|
2020-06-16 13:36:16 +00:00
|
|
|
db := ethdb.MustOpen(chaindata)
|
|
|
|
defer db.Close()
|
|
|
|
if err := db.ClearBuckets(dbutils.TxLookupPrefix); err != nil {
|
2020-06-10 20:07:14 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
startTime := time.Now()
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
log.Info("TxLookup generation started", "start time", startTime)
|
2020-06-28 06:10:27 +00:00
|
|
|
err = stagedsync.TxLookupTransform(db, dbutils.HeaderHashKey(0), dbutils.HeaderHashKey(lastExecutedBlock), quitCh, os.TempDir())
|
2020-06-10 20:07:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.Info("TxLookup index is successfully regenerated", "it took", time.Since(startTime))
|
|
|
|
return nil
|
|
|
|
}
|