mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 11:41:19 +00:00
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 <alexsharp@Alexs-MacBook-Pro.local>
This commit is contained in:
parent
801784ff8f
commit
43915a73a8
@ -192,6 +192,7 @@ func (api *TraceAPIImpl) Block(ctx context.Context, blockNr rpc.BlockNumber) (Pa
|
|||||||
func (api *TraceAPIImpl) Filter(ctx context.Context, req TraceFilterRequest, stream *jsoniter.Stream) error {
|
func (api *TraceAPIImpl) Filter(ctx context.Context, req TraceFilterRequest, stream *jsoniter.Stream) error {
|
||||||
dbtx, err1 := api.kv.BeginRo(ctx)
|
dbtx, err1 := api.kv.BeginRo(ctx)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
|
stream.WriteNil()
|
||||||
return fmt.Errorf("traceFilter cannot open tx: %v", err1)
|
return fmt.Errorf("traceFilter cannot open tx: %v", err1)
|
||||||
}
|
}
|
||||||
defer dbtx.Rollback()
|
defer dbtx.Rollback()
|
||||||
@ -212,6 +213,7 @@ func (api *TraceAPIImpl) Filter(ctx context.Context, req TraceFilterRequest, str
|
|||||||
}
|
}
|
||||||
|
|
||||||
if fromBlock > toBlock {
|
if fromBlock > toBlock {
|
||||||
|
stream.WriteNil()
|
||||||
return fmt.Errorf("invalid parameters: fromBlock cannot be greater than toBlock")
|
return fmt.Errorf("invalid parameters: fromBlock cannot be greater than toBlock")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,6 +267,7 @@ func (api *TraceAPIImpl) Filter(ctx context.Context, req TraceFilterRequest, str
|
|||||||
// Extract transactions from block
|
// Extract transactions from block
|
||||||
hash, hashErr := rawdb.ReadCanonicalHash(dbtx, b)
|
hash, hashErr := rawdb.ReadCanonicalHash(dbtx, b)
|
||||||
if hashErr != nil {
|
if hashErr != nil {
|
||||||
|
stream.WriteNil()
|
||||||
return hashErr
|
return hashErr
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,6 +277,7 @@ func (api *TraceAPIImpl) Filter(ctx context.Context, req TraceFilterRequest, str
|
|||||||
return bErr
|
return bErr
|
||||||
}
|
}
|
||||||
if block == nil {
|
if block == nil {
|
||||||
|
stream.WriteNil()
|
||||||
return fmt.Errorf("could not find block %x %d", hash, b)
|
return fmt.Errorf("could not find block %x %d", hash, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,6 +286,7 @@ func (api *TraceAPIImpl) Filter(ctx context.Context, req TraceFilterRequest, str
|
|||||||
txs := block.Transactions()
|
txs := block.Transactions()
|
||||||
t, tErr := api.callManyTransactions(ctx, dbtx, txs, block.ParentHash(), rpc.BlockNumber(block.NumberU64()-1), block.Header())
|
t, tErr := api.callManyTransactions(ctx, dbtx, txs, block.ParentHash(), rpc.BlockNumber(block.NumberU64()-1), block.Header())
|
||||||
if tErr != nil {
|
if tErr != nil {
|
||||||
|
stream.WriteNil()
|
||||||
return tErr
|
return tErr
|
||||||
}
|
}
|
||||||
includeAll := len(fromAddresses) == 0 && len(toAddresses) == 0
|
includeAll := len(fromAddresses) == 0 && len(toAddresses) == 0
|
||||||
|
@ -9,8 +9,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// DBSchemaVersion
|
// DBSchemaVersion
|
||||||
var DBSchemaVersionLMDB = types.VersionReply{Major: 1, Minor: 0, Patch: 0}
|
var DBSchemaVersionLMDB = types.VersionReply{Major: 1, Minor: 1, Patch: 0}
|
||||||
var DBSchemaVersionMDBX = types.VersionReply{Major: 2, Minor: 0, Patch: 0}
|
var DBSchemaVersionMDBX = types.VersionReply{Major: 2, Minor: 1, Patch: 0}
|
||||||
|
|
||||||
// Buckets
|
// Buckets
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ const MaxTxTTL = 30 * time.Second
|
|||||||
// 1.1.0 - added pending transactions, add methods eth_getRawTransactionByHash, eth_retRawTransactionByBlockHashAndIndex, eth_retRawTransactionByBlockNumberAndIndex| Yes | |
|
// 1.1.0 - added pending transactions, add methods eth_getRawTransactionByHash, eth_retRawTransactionByBlockHashAndIndex, eth_retRawTransactionByBlockNumberAndIndex| Yes | |
|
||||||
// 1.2.0 - Added separated services for mining and txpool methods
|
// 1.2.0 - Added separated services for mining and txpool methods
|
||||||
// 2.0.0 - Rename all buckets
|
// 2.0.0 - Rename all buckets
|
||||||
var KvServiceAPIVersion = &types.VersionReply{Major: 2, Minor: 0, Patch: 0}
|
var KvServiceAPIVersion = &types.VersionReply{Major: 2, Minor: 1, Patch: 0}
|
||||||
|
|
||||||
type KvServer struct {
|
type KvServer struct {
|
||||||
remote.UnimplementedKVServer // must be embedded to have forward compatible implementations.
|
remote.UnimplementedKVServer // must be embedded to have forward compatible implementations.
|
||||||
|
51
migrations/call_trace_index.go
Normal file
51
migrations/call_trace_index.go
Normal file
@ -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)
|
||||||
|
},
|
||||||
|
}
|
@ -58,6 +58,7 @@ var migrations = []Migration{
|
|||||||
headerPrefixToSeparateBuckets,
|
headerPrefixToSeparateBuckets,
|
||||||
removeCliqueBucket,
|
removeCliqueBucket,
|
||||||
dbSchemaVersion,
|
dbSchemaVersion,
|
||||||
|
rebuilCallTraceIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
type Migration struct {
|
type Migration struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user