erigon-pulse/migrations/call_trace_index.go
Alex Sharov c3e1cfdac8
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 21:03:19 +01:00

57 lines
1.6 KiB
Go

package migrations
import (
"context"
"encoding/binary"
"github.com/ledgerwatch/erigon/common/dbutils"
"github.com/ledgerwatch/erigon/common/etl"
"github.com/ledgerwatch/erigon/eth/stagedsync"
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
"github.com/ledgerwatch/erigon/ethdb"
"github.com/ledgerwatch/erigon/ethdb/prune"
"github.com/ledgerwatch/erigon/log"
)
var rebuilCallTraceIndex = Migration{
Name: "rebuild_call_trace_index",
Up: func(db ethdb.Database, tmpdir string, progress []byte, CommitProgress etl.LoadCommitHandler) (err error) {
// Find the lowest key in the TraceCallSet table
tx := db.(ethdb.HasTx).Tx().(ethdb.RwTx)
c, err := tx.CursorDupSort(dbutils.CallTraceSet)
if err != nil {
return err
}
defer c.Close()
var k []byte
k, _, err = c.First()
if err != nil {
return err
}
if k == nil {
log.Warn("Nothing to rebuild, CallTraceSet table is empty")
return CommitProgress(db, nil, true)
}
blockNum := binary.BigEndian.Uint64(k)
if blockNum == 0 {
log.Warn("Nothing to rebuild, CallTraceSet's first record", "number", blockNum)
return CommitProgress(db, nil, true)
}
logPrefix := "db migration rebuild_call_trace_index"
pm, err := prune.Get(tx)
if err != nil {
return err
}
if err = stagedsync.DoUnwindCallTraces(logPrefix, tx, 999_999_999, blockNum-1, context.Background(), stagedsync.StageCallTracesCfg(nil, pm, 0, tmpdir)); err != nil {
return err
}
log.Info("First record in CallTraceTable", "number", blockNum)
if err = stages.SaveStageProgress(db, stages.CallTraces, blockNum-1); err != nil {
return err
}
return CommitProgress(db, nil, true)
},
}