-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration to fix trace_filter (#2095)
* Migration to fix trace_filter * Fix to db/tx * Fix to db/tx * Error fixes * Bump KV version Co-authored-by: Alex Sharp <[email protected]>
- Loading branch information
1 parent
801784f
commit 43915a7
Showing
5 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package migrations | ||
|
||
import ( | ||
"encoding/binary" | ||
|
||
"github.com/ledgerwatch/erigon/common/dbutils" | ||
"github.com/ledgerwatch/erigon/common/etl" | ||
"github.com/ledgerwatch/erigon/eth/stagedsync/stages" | ||
"github.com/ledgerwatch/erigon/ethdb" | ||
"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) { | ||
sm, err := ethdb.GetStorageModeFromDB(db) | ||
if err != nil { | ||
return err | ||
} | ||
if !sm.CallTraces { | ||
// Call traces are not on, nothing to migrate | ||
return nil | ||
} | ||
// Find the lowest key in the TraceCallSet table | ||
tx := db.(ethdb.HasTx).Tx() | ||
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 nil | ||
} | ||
blockNum := binary.BigEndian.Uint64((k)) | ||
if blockNum == 0 { | ||
log.Warn("Nothing to rebuild, CallTraceSet's first record", "number", blockNum) | ||
return nil | ||
} | ||
log.Info("First record in CallTraceTable", "number", blockNum) | ||
if err = stages.SaveStageUnwind(db, stages.CallTraces, blockNum-1); err != nil { | ||
return err | ||
} | ||
return CommitProgress(db, nil, true) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters