Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/scripts/rpc_version.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
RPC_VERSION=v2.16.0
RPC_VERSION=v2.17.0

42 changes: 42 additions & 0 deletions rpc/jsonrpc/debug_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,48 @@ func TestTraceTransactionNotFound(t *testing.T) {
require.ErrorContains(t, err, "transaction not found")
}

// TestTraceErrorPathsWriteNoStream verifies that streaming trace methods write nothing to the
// stream on early error paths. This is required for JSON-RPC 2.0 compliance: the handler omits
// the "result" field when the stream is untouched, producing {error:...} without result:null.
func TestTraceErrorPathsWriteNoStream(t *testing.T) {
m, _, _ := rpcdaemontest.CreateTestExecModule(t)
api := NewPrivateDebugAPI(newBaseApiForTest(m), m.DB, nil, 0, false)

newStream := func() (*bytes.Buffer, jsonstream.Stream) {
var buf bytes.Buffer
return &buf, jsonstream.New(jsoniter.NewStream(jsoniter.ConfigDefault, &buf, 4096))
}

t.Run("TraceBlockByNumber_genesis", func(t *testing.T) {
buf, s := newStream()
err := api.TraceBlockByNumber(m.Ctx, rpc.BlockNumber(0), &tracersConfig.TraceConfig{}, s)
require.ErrorContains(t, err, "genesis is not traceable")
require.NoError(t, s.Flush())
require.Empty(t, buf.Bytes(), "stream must be empty on early error")
})

t.Run("TraceBlockByHash_genesis", func(t *testing.T) {
var genesisHash common.Hash
require.NoError(t, m.DB.View(m.Ctx, func(tx kv.Tx) error {
genesisHash, _, _ = m.BlockReader.CanonicalHash(m.Ctx, tx, 0)
return nil
}))
buf, s := newStream()
err := api.TraceBlockByHash(m.Ctx, genesisHash, &tracersConfig.TraceConfig{}, s)
require.ErrorContains(t, err, "genesis is not traceable")
require.NoError(t, s.Flush())
require.Empty(t, buf.Bytes(), "stream must be empty on early error")
})

t.Run("TraceTransaction_genesis", func(t *testing.T) {
buf, s := newStream()
err := api.TraceTransaction(m.Ctx, common.HexToHash("0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"), &tracersConfig.TraceConfig{}, s)
require.ErrorContains(t, err, "transaction not found")
require.NoError(t, s.Flush())
require.Empty(t, buf.Bytes(), "stream must be empty on early error")
})
}

func TestTraceTransactionNoRefund(t *testing.T) {
m, _, _ := rpcdaemontest.CreateTestExecModule(t)
api := NewPrivateDebugAPI(newBaseApiForTest(m), m.DB, nil, 0, false)
Expand Down
9 changes: 0 additions & 9 deletions rpc/jsonrpc/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ func (api *DebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rpc.Block
}

if (blockNrOrHash.BlockHash == nil && hash == common.Hash{}) {
stream.WriteNil()
return fmt.Errorf("block #%d not found", *blockNrOrHash.BlockNumber)
}

if blockNumber == 0 {
stream.WriteNil()
return fmt.Errorf("genesis is not traceable")
}

Expand All @@ -88,7 +86,6 @@ func (api *DebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rpc.Block
return err
}
if block == nil {
stream.WriteNil()
return fmt.Errorf("invalid arguments; block with hash %x not found", hash)
}

Expand Down Expand Up @@ -290,7 +287,6 @@ func (api *DebugAPIImpl) TraceTransaction(ctx context.Context, hash common.Hash,
}

if blockNum == 0 {
stream.WriteNil()
return fmt.Errorf("genesis is not traceable")
}

Expand Down Expand Up @@ -319,12 +315,10 @@ func (api *DebugAPIImpl) TraceTransaction(ctx context.Context, hash common.Hash,
return err
}
if txNumMin+1 > txNum {
stream.WriteNil()
return fmt.Errorf("uint underflow txnums error txNum: %d, txNumMin: %d, blockNum: %d", txNum, txNumMin, blockNum)
}
txnIndex = int(txNum - txNumMin - 1)
if txnIndex >= block.Transactions().Len() {
stream.WriteNil()
return fmt.Errorf("transaction %#x not found", hash)
}
}
Expand Down Expand Up @@ -511,7 +505,6 @@ func (api *DebugAPIImpl) TraceCallMany(ctx context.Context, bundles []Bundle, si
return err
}
if len(bundles) == 0 {
stream.WriteNil()
return errors.New("empty bundles")
}
empty := true
Expand All @@ -522,7 +515,6 @@ func (api *DebugAPIImpl) TraceCallMany(ctx context.Context, bundles []Bundle, si
}

if empty {
stream.WriteNil()
return errors.New("empty bundles")
}

Expand All @@ -544,7 +536,6 @@ func (api *DebugAPIImpl) TraceCallMany(ctx context.Context, bundles []Bundle, si
return err
}
if header == nil {
stream.WriteNil()
return fmt.Errorf("block %d(%x) not found", blockNum, hash)
}

Expand Down
Loading