2020-06-10 20:07:14 +00:00
|
|
|
package generate
|
|
|
|
|
|
|
|
import (
|
2021-04-02 11:22:25 +00:00
|
|
|
"context"
|
2020-06-16 13:36:16 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"time"
|
|
|
|
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common/dbutils"
|
|
|
|
"github.com/ledgerwatch/erigon/eth/stagedsync"
|
|
|
|
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
|
2021-06-19 08:21:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/ethdb/kv"
|
Pruning for: exec, log_index, tx_lookup, history stages (#2399)
* Pruning for: exec, log_index, tx_lookup, history stages
* Pruning for: exec, log_index, tx_lookup, history stages
* Pruning for: exec, log_index, tx_lookup, history stages
* Pruning for: exec, log_index, tx_lookup, history stages
* add tvm flag
* save
* db migration for storage mode
add flag --prune=
remove flag --storage-mode=
add flag --experiments=tevm,...
rename integration set_storage_mode to set_prune
* fix
* forward move of stages must skip everything before PruneTo
* keep in db progress of prune method
* keep in db progress of prune method
* simplify logs
* simplify logs
* simplify logs
* fix test
* simplify logs
* simplify logs
* simplify logs
* simplify logs
* remove callTraceSet as dupsort
use etl transform for txlookup prune
remove some logs
* cleanup tests a bit
* print_stages and eth_sync to show prune progress
* fix print_stages
* add readme about --prune.to flag
* more docs
* add --prune.history.older and other flags support
* fix migration on empty db
* better toString
* better toString
2021-07-20 20:03:19 +00:00
|
|
|
"github.com/ledgerwatch/erigon/ethdb/prune"
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/log"
|
2020-06-10 20:07:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func RegenerateTxLookup(chaindata string) error {
|
2021-06-19 08:21:53 +00:00
|
|
|
db := kv.MustOpen(chaindata)
|
2020-06-16 13:36:16 +00:00
|
|
|
defer db.Close()
|
2021-07-07 16:15:49 +00:00
|
|
|
tx, err := db.BeginRw(context.Background())
|
2021-04-02 11:22:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer tx.Rollback()
|
2021-07-07 16:15:49 +00:00
|
|
|
if err := tx.ClearBucket(dbutils.TxLookupPrefix); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-04-02 11:22:25 +00:00
|
|
|
|
2020-06-10 20:07:14 +00:00
|
|
|
startTime := time.Now()
|
|
|
|
ch := make(chan os.Signal, 1)
|
|
|
|
quitCh := make(chan struct{})
|
|
|
|
signal.Notify(ch, os.Interrupt)
|
|
|
|
go func() {
|
|
|
|
<-ch
|
|
|
|
close(quitCh)
|
|
|
|
}()
|
|
|
|
|
Pruning for: exec, log_index, tx_lookup, history stages (#2399)
* Pruning for: exec, log_index, tx_lookup, history stages
* Pruning for: exec, log_index, tx_lookup, history stages
* Pruning for: exec, log_index, tx_lookup, history stages
* Pruning for: exec, log_index, tx_lookup, history stages
* add tvm flag
* save
* db migration for storage mode
add flag --prune=
remove flag --storage-mode=
add flag --experiments=tevm,...
rename integration set_storage_mode to set_prune
* fix
* forward move of stages must skip everything before PruneTo
* keep in db progress of prune method
* keep in db progress of prune method
* simplify logs
* simplify logs
* simplify logs
* fix test
* simplify logs
* simplify logs
* simplify logs
* simplify logs
* remove callTraceSet as dupsort
use etl transform for txlookup prune
remove some logs
* cleanup tests a bit
* print_stages and eth_sync to show prune progress
* fix print_stages
* add readme about --prune.to flag
* more docs
* add --prune.history.older and other flags support
* fix migration on empty db
* better toString
* better toString
2021-07-20 20:03:19 +00:00
|
|
|
pm, err := prune.Get(tx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-04-02 11:22:25 +00:00
|
|
|
lastExecutedBlock, err := stages.GetStageProgress(tx, stages.Execution)
|
2020-06-10 20:07:14 +00:00
|
|
|
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)
|
Pruning for: exec, log_index, tx_lookup, history stages (#2399)
* Pruning for: exec, log_index, tx_lookup, history stages
* Pruning for: exec, log_index, tx_lookup, history stages
* Pruning for: exec, log_index, tx_lookup, history stages
* Pruning for: exec, log_index, tx_lookup, history stages
* add tvm flag
* save
* db migration for storage mode
add flag --prune=
remove flag --storage-mode=
add flag --experiments=tevm,...
rename integration set_storage_mode to set_prune
* fix
* forward move of stages must skip everything before PruneTo
* keep in db progress of prune method
* keep in db progress of prune method
* simplify logs
* simplify logs
* simplify logs
* fix test
* simplify logs
* simplify logs
* simplify logs
* simplify logs
* remove callTraceSet as dupsort
use etl transform for txlookup prune
remove some logs
* cleanup tests a bit
* print_stages and eth_sync to show prune progress
* fix print_stages
* add readme about --prune.to flag
* more docs
* add --prune.history.older and other flags support
* fix migration on empty db
* better toString
* better toString
2021-07-20 20:03:19 +00:00
|
|
|
err = stagedsync.TxLookupTransform("txlookup", tx,
|
|
|
|
dbutils.EncodeBlockNumber(pm.TxIndex.PruneTo(lastExecutedBlock)),
|
|
|
|
dbutils.EncodeBlockNumber(lastExecutedBlock+1),
|
|
|
|
quitCh,
|
|
|
|
stagedsync.StageTxLookupCfg(db, pm, 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
|
|
|
|
}
|