diff --git a/cmd/rpcdaemon/commands/trace_filtering.go b/cmd/rpcdaemon/commands/trace_filtering.go index d2581b0f6..ff4dcbd1a 100644 --- a/cmd/rpcdaemon/commands/trace_filtering.go +++ b/cmd/rpcdaemon/commands/trace_filtering.go @@ -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 { dbtx, err1 := api.kv.BeginRo(ctx) if err1 != nil { + stream.WriteNil() return fmt.Errorf("traceFilter cannot open tx: %v", err1) } defer dbtx.Rollback() @@ -212,6 +213,7 @@ func (api *TraceAPIImpl) Filter(ctx context.Context, req TraceFilterRequest, str } if fromBlock > toBlock { + stream.WriteNil() 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 hash, hashErr := rawdb.ReadCanonicalHash(dbtx, b) if hashErr != nil { + stream.WriteNil() return hashErr } @@ -274,6 +277,7 @@ func (api *TraceAPIImpl) Filter(ctx context.Context, req TraceFilterRequest, str return bErr } if block == nil { + stream.WriteNil() 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() t, tErr := api.callManyTransactions(ctx, dbtx, txs, block.ParentHash(), rpc.BlockNumber(block.NumberU64()-1), block.Header()) if tErr != nil { + stream.WriteNil() return tErr } includeAll := len(fromAddresses) == 0 && len(toAddresses) == 0 diff --git a/common/dbutils/bucket.go b/common/dbutils/bucket.go index b40f9ae3d..a7ca08eae 100644 --- a/common/dbutils/bucket.go +++ b/common/dbutils/bucket.go @@ -9,8 +9,8 @@ import ( ) // DBSchemaVersion -var DBSchemaVersionLMDB = types.VersionReply{Major: 1, Minor: 0, Patch: 0} -var DBSchemaVersionMDBX = types.VersionReply{Major: 2, Minor: 0, Patch: 0} +var DBSchemaVersionLMDB = types.VersionReply{Major: 1, Minor: 1, Patch: 0} +var DBSchemaVersionMDBX = types.VersionReply{Major: 2, Minor: 1, Patch: 0} // Buckets diff --git a/ethdb/remote/remotedbserver/server.go b/ethdb/remote/remotedbserver/server.go index 045d1f112..1d9fe3829 100644 --- a/ethdb/remote/remotedbserver/server.go +++ b/ethdb/remote/remotedbserver/server.go @@ -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.2.0 - Added separated services for mining and txpool methods // 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 { remote.UnimplementedKVServer // must be embedded to have forward compatible implementations. diff --git a/migrations/call_trace_index.go b/migrations/call_trace_index.go new file mode 100644 index 000000000..bad3177df --- /dev/null +++ b/migrations/call_trace_index.go @@ -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) + }, +} diff --git a/migrations/migrations.go b/migrations/migrations.go index 66ed59ffa..e2efd1fe9 100644 --- a/migrations/migrations.go +++ b/migrations/migrations.go @@ -58,6 +58,7 @@ var migrations = []Migration{ headerPrefixToSeparateBuckets, removeCliqueBucket, dbSchemaVersion, + rebuilCallTraceIndex, } type Migration struct {