feat(l1): implement debug_traceBlockByHash RPC endpoint#6692
feat(l1): implement debug_traceBlockByHash RPC endpoint#6692azteca1998 wants to merge 5 commits into
Conversation
Add debug_traceBlockByHash which traces all transactions in a block identified by hash. Extracts shared block tracing logic into a `trace_block` helper used by both traceBlockByNumber and traceBlockByHash, avoiding code duplication. Part of #6572
|
🤖 Kimi Code ReviewThe PR correctly implements Code Quality & Correctness:
Security & Robustness:
Performance:
Overall: Automated review by Kimi (Moonshot AI) · kimi-k2.5 · custom prompt |
🤖 Claude Code ReviewHere is the full review for PR #6692: PR Review:
|
🤖 Codex Code ReviewNo correctness or security findings in the RPC implementation itself. The new Residual gaps:
I couldn’t run a full compile/test pass in this environment because Automated review by OpenAI Codex · gpt-5.4 · custom prompt |
Lines of code reportTotal lines added: Detailed view |
Greptile SummaryThis PR adds
Confidence Score: 5/5The change is straightforward — new endpoint wired into an existing router, shared helper extracted from already-working code, and block-not-found errors made more accurate. No storage writes, no auth changes, no new async state. The refactoring is mechanical and the logic is well-covered by the existing test suite for No files require special attention.
|
| Filename | Overview |
|---|---|
| crates/networking/rpc/tracing.rs | Introduces TraceBlockByHashRequest and refactors shared block tracing into a trace_block helper; also improves block-not-found error from RpcErr::Internal to RpcErr::BadParams in TraceBlockByNumberRequest. |
| crates/networking/rpc/rpc.rs | Wires debug_traceBlockByHash into the debug request router alongside existing debug endpoints. |
| tooling/repl/src/commands/debug.rs | Adds traceBlockByHash REPL command using HASH_OPTIONS, but the shared HASH_OPTIONS param description says "Transaction hash" — misleading when applied to traceBlockByHash which accepts a block hash. |
| test/tests/rpc/debug_trace_tests.rs | New integration test for debug_traceBlockByHash that builds a real block with a transfer transaction and validates the callTracer response shape end-to-end. |
| test/tests/rpc/mod.rs | Adds debug_trace_tests module to the test suite. |
Sequence Diagram
sequenceDiagram
participant C as Client
participant R as RPC Router
participant H as TraceBlockByHashRequest
participant S as Storage
participant T as trace_block()
participant BC as Blockchain
C->>R: debug_traceBlockByHash(hash, config?)
R->>H: parse(params)
H-->>R: TraceBlockByHashRequest
R->>H: handle(context)
H->>S: get_block_by_hash(hash)
S-->>H: Block (or None → BadParams)
H->>T: trace_block(block, config, context)
alt callTracer
T->>BC: trace_block_calls(...)
BC-->>T: "Vec<(H256, CallTrace)>"
else prestateTracer
T->>BC: trace_block_prestate(...)
BC-->>T: "Vec<(H256, PrestateResult)>"
else opcodeTracer
T->>BC: trace_block_opcodes(...)
BC-->>T: "Vec<(H256, OpcodeTrace)>"
end
T-->>H: serde_json::Value
H-->>C: JSON response
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
tooling/repl/src/commands/debug.rs:19-26
The `HASH_OPTIONS` constant is shared between `traceTransaction` and `traceBlockByHash`, but its first parameter description says "Transaction hash". When the REPL renders help for `traceBlockByHash`, users will see "Transaction hash" for a parameter that actually expects a block hash. Consider splitting this into separate constants so each command can have an accurate description.
```suggestion
const TX_HASH_OPTIONS: &[ParamDef] = &[
ParamDef {
name: "hash",
param_type: ParamType::Hash,
required: true,
default_value: None,
description: "Transaction hash",
},
```
Reviews (2): Last reviewed commit: "style: run cargo fmt on test and source ..." | Re-trigger Greptile
Tests for parse, config validation, and tracer type deserialization including the new TraceBlockByHashRequest.
Build a real block with a signed transfer, then query
debug_traceBlockByHash by block hash. Assert the response
contains {txHash, result} with a CALL trace.
Block-not-found was returning RpcErr::Internal (JSON-RPC -32603), the code reserved for unexpected server failures. Geth returns -32000 for application-level errors like missing blocks. Changed to RpcErr::BadParams so callers can distinguish "not found" from "server crashed". Also added traceBlockByHash to the REPL.
🤖 Kimi Code ReviewThe PR implements Code Quality & Correctness
Testing The new unit tests (lines 434-621) cover parsing edge cases for all three request types, and the integration test ( Minor Observations
Conclusion The code is correct, follows Rust best practices, and improves maintainability through DRY principles. The error handling fix and test coverage are particularly good additions. No blocking issues found. Automated review by Kimi (Moonshot AI) · kimi-k2.5 · custom prompt |
🤖 Codex Code ReviewNo correctness, security, or consensus-risk findings in the implementation itself. Minor items:
I could not run the tests in this environment: Automated review by OpenAI Codex · gpt-5.4 · custom prompt |
🤖 Claude Code ReviewHere is the review: PR Review:
|
Summary
debug_traceBlockByHashwhich traces all transactions in a block identified by its hashtrace_blockhelper used by bothtraceBlockByNumberandtraceBlockByHash, eliminating code duplicationcallTracer,prestateTracer,opcodeTracerCloses part of #6572
Test plan
debug_traceBlockByHashreturns same results asdebug_traceBlockByNumberfor the same block