mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-01 08:41:21 +00:00
57777e7c60
* Add kv.tx.bucket.Clear() and db.ClearBuckets() methods * Add kv.tx.bucket.Clear() and db.ClearBuckets() methods * choose db based on file suffix * implement db.id method * implement db.id method * use ethdb.NewDatabase method * use ethb.MustOpen method * cleanup * support TEST_DB env flag * create db path automatically needed * bolt - don't change prefix on happy path
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package generate
|
|
|
|
import (
|
|
"os"
|
|
"os/signal"
|
|
"time"
|
|
|
|
"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 {
|
|
db := ethdb.MustOpen(chaindata)
|
|
defer db.Close()
|
|
if err := db.ClearBuckets(dbutils.TxLookupPrefix); err != nil {
|
|
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)
|
|
err = stagedsync.TxLookupTransform(db, dbutils.HeaderHashKey(0), dbutils.HeaderHashKey(lastExecutedBlock), quitCh, os.TempDir(), [][]byte{
|
|
dbutils.HeaderHashKey(4000000),
|
|
dbutils.HeaderHashKey(6000000),
|
|
dbutils.HeaderHashKey(8000000),
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
log.Info("TxLookup index is successfully regenerated", "it took", time.Since(startTime))
|
|
return nil
|
|
}
|