Skip to content

Conversation

@LesnyRumcajs
Copy link
Member

@LesnyRumcajs LesnyRumcajs commented Oct 21, 2025

Summary of changes

Changes introduced in this pull request:

  • the RPC error code was 404 but it's an HTTP code. Fixed it to -32601.
❯ curl localhost:2345/ \
           --request POST \
           -s -w "%{http_code}" \
           --header 'accept: application/json' \
           --header 'content-type: application/json' \
           --data '{"id":1,"jsonrpc":"2.0","method":"eth_feeHistoryyy","params":["0x5","latest",[20,30]]}'
{"jsonrpc":"2.0","id":1,"error":{"code":404,"message":"Not Found"}}200⏎
❯ curl localhost:2345/ \
           --request POST \
           -s -w "%{http_code}" \
           --header 'accept: application/json' \
           --header 'content-type: application/json' \
           --data '{"id":1,"jsonrpc":"2.0","method":"eth_feeHistoryyy","params":["0x5","latest",[20,30]]}'
{"jsonrpc":"2.0","id":1,"error":{"code":-32601,"message":"Method not found"}}200⏎

Reference issue to close (if applicable)

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed the error code returned for unsupported RPC method calls to properly reflect error conditions and align with technical standards.
  • Tests

    • Added test validation to verify that unsupported RPC method calls return the correct error code consistently.

@LesnyRumcajs LesnyRumcajs added the RPC requires calibnet RPC checks to run on CI label Oct 21, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 21, 2025

Walkthrough

This pull request fixes the error code returned for unsupported RPC methods by replacing hard-coded values with the standard JSON-RPC error constants from jsonrpsee. The fix is verified by a new integration test and documented in the changelog.

Changes

Cohort / File(s) Summary
RPC Error Handling Fix
src/rpc/segregation_layer.rs
Imports METHOD_NOT_FOUND_CODE and METHOD_NOT_FOUND_MSG from jsonrpsee and replaces hard-coded error status and message with these standard constants in the error response path.
Verification Test
scripts/tests/calibnet_other_check.sh
Adds a test block that sends a JSON-RPC request to an unsupported method (Invoke.Cthulhu) and verifies the response returns HTTP 200 with error code -32601 (METHOD_NOT_FOUND).
Documentation
CHANGELOG.md
Adds changelog entry documenting the fix for incorrect error code on unsupported RPC methods under the Fixed section.

Sequence Diagram

sequenceDiagram
    participant Client
    participant RPC Server
    participant Segregation Layer
    
    Client->>RPC Server: POST /rpc/v1<br/>(unsupported method)
    RPC Server->>Segregation Layer: check(method)
    
    alt Method Not Found
        Segregation Layer->>Segregation Layer: Use METHOD_NOT_FOUND_CODE (-32601)<br/>and METHOD_NOT_FOUND_MSG
        Segregation Layer-->>RPC Server: ErrorObject with -32601
    end
    
    RPC Server-->>Client: HTTP 200<br/>{"error": {"code": -32601, ...}}
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

The changes follow a straightforward pattern: importing standard error constants and applying them consistently across one implementation file, one test file, and documentation. The logic density is low with no complex control flow modifications.

Suggested reviewers

  • akaladarshi
  • hanabi1224
  • elmattic

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The PR title "fix: RPC response code mapping to HTTP" relates to the main change topic (RPC response codes), but it lacks clarity about the specific fix being implemented. The actual change corrects an error code from 404 (an HTTP status code) to -32601 (the proper JSON-RPC error code) for unsupported RPC methods. While the title touches on the right area of concern, a teammate scanning the commit history might not immediately understand that the primary fix involves using the correct JSON-RPC error code rather than an HTTP status code. The title is somewhat vague about what aspect of "RPC response code mapping" was actually corrected. Consider clarifying the title to explicitly indicate what was fixed, such as "fix: use JSON-RPC error code for unsupported methods" or "fix: return -32601 for unknown RPC methods" to make the primary change immediately clear to someone reviewing the commit history. This would directly communicate that the fix involves using the proper JSON-RPC error code instead of an HTTP status code.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-rpc-resp-code

Comment @coderabbitai help to get the list of available commands and usage tips.

@LesnyRumcajs LesnyRumcajs force-pushed the fix-rpc-resp-code branch 7 times, most recently from 92139d6 to 22642ea Compare October 24, 2025 10:25
@LesnyRumcajs LesnyRumcajs marked this pull request as ready for review October 24, 2025 10:27
@LesnyRumcajs LesnyRumcajs requested a review from a team as a code owner October 24, 2025 10:27
@LesnyRumcajs LesnyRumcajs requested review from elmattic and hanabi1224 and removed request for a team October 24, 2025 10:27
@LesnyRumcajs LesnyRumcajs changed the title fix: RPC response code mapping to HTTP fix: RPC response code for unsupported methods Oct 24, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
scripts/tests/calibnet_other_check.sh (1)

87-94: Good test coverage for the RPC error code fix.

The test correctly verifies that unsupported RPC methods return the JSON-RPC standard error code -32601. This will prevent regression of the issue.

Optional enhancement: You could also verify the error message to ensure complete correctness:

 error_code=$(echo "$unsupported_response" | jq -r '.error.code')
+error_message=$(echo "$unsupported_response" | jq -r '.error.message')
 if [ "$error_code" != "-32601" ]; then
   echo "Unexpected error code for unsupported method: $error_code"
   exit 1
 fi
+if [ "$error_message" != "Method not found" ]; then
+  echo "Unexpected error message for unsupported method: $error_message"
+  exit 1
+fi
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a86d740 and 5f0d38f.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • scripts/tests/calibnet_other_check.sh (1 hunks)
  • src/rpc/segregation_layer.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Build MacOS
  • GitHub Check: cargo-publish-dry-run
  • GitHub Check: Build Ubuntu
  • GitHub Check: All lint checks
  • GitHub Check: Check
  • GitHub Check: Build forest binaries on Linux AMD64
  • GitHub Check: tests
  • GitHub Check: tests-release
🔇 Additional comments (3)
CHANGELOG.md (1)

48-49: LGTM! Changelog entry is clear and properly formatted.

The entry accurately describes the fix for the incorrect error code issue. The formatting is consistent with other entries in the changelog.

src/rpc/segregation_layer.rs (2)

12-12: LGTM! Correct import of JSON-RPC standard error constants.

Using the library-provided constants ensures consistency with the JSON-RPC specification and makes the code more maintainable.


72-73: Excellent fix! Correctly uses JSON-RPC error codes instead of HTTP status codes.

This change properly aligns the error response with the JSON-RPC 2.0 specification. The error code -32601 ("Method not found") is the standard code for unsupported methods, replacing the previously incorrect HTTP 404 status code. Using METHOD_NOT_FOUND_CODE and METHOD_NOT_FOUND_MSG constants from jsonrpsee ensures consistency and maintainability.

@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Oct 24, 2025
Merged via the queue into main with commit 738e151 Oct 24, 2025
55 checks passed
@LesnyRumcajs LesnyRumcajs deleted the fix-rpc-resp-code branch October 24, 2025 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RPC requires calibnet RPC checks to run on CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants