2021-06-04 11:45:06 +00:00
|
|
|
package migrations
|
|
|
|
|
|
|
|
import (
|
2021-07-17 14:14:51 +00:00
|
|
|
"context"
|
2021-06-04 11:45:06 +00:00
|
|
|
"encoding/binary"
|
|
|
|
|
|
|
|
"github.com/ledgerwatch/erigon/common/dbutils"
|
|
|
|
"github.com/ledgerwatch/erigon/common/etl"
|
2021-07-17 14:14:51 +00:00
|
|
|
"github.com/ledgerwatch/erigon/eth/stagedsync"
|
2021-06-04 11:45:06 +00:00
|
|
|
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
|
|
|
|
"github.com/ledgerwatch/erigon/ethdb"
|
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-06-04 11:45:06 +00:00
|
|
|
"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
|
2021-07-17 14:14:51 +00:00
|
|
|
tx := db.(ethdb.HasTx).Tx().(ethdb.RwTx)
|
2021-06-04 11:45:06 +00:00
|
|
|
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")
|
2021-06-04 14:08:22 +00:00
|
|
|
return CommitProgress(db, nil, true)
|
2021-06-04 11:45:06 +00:00
|
|
|
}
|
2021-07-17 14:14:51 +00:00
|
|
|
blockNum := binary.BigEndian.Uint64(k)
|
2021-06-04 11:45:06 +00:00
|
|
|
if blockNum == 0 {
|
|
|
|
log.Warn("Nothing to rebuild, CallTraceSet's first record", "number", blockNum)
|
2021-06-04 14:08:22 +00:00
|
|
|
return CommitProgress(db, nil, true)
|
2021-06-04 11:45:06 +00:00
|
|
|
}
|
2021-07-17 14:14:51 +00:00
|
|
|
logPrefix := "db migration rebuild_call_trace_index"
|
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
|
|
|
|
}
|
|
|
|
if err = stagedsync.DoUnwindCallTraces(logPrefix, tx, 999_999_999, blockNum-1, context.Background(), stagedsync.StageCallTracesCfg(nil, pm, 0, tmpdir)); err != nil {
|
2021-07-17 14:14:51 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-06-04 11:45:06 +00:00
|
|
|
log.Info("First record in CallTraceTable", "number", blockNum)
|
2021-07-17 14:14:51 +00:00
|
|
|
if err = stages.SaveStageProgress(db, stages.CallTraces, blockNum-1); err != nil {
|
2021-06-04 11:45:06 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return CommitProgress(db, nil, true)
|
|
|
|
},
|
|
|
|
}
|