Skip to content

Conversation

@hanabi1224
Copy link
Contributor

@hanabi1224 hanabi1224 commented Oct 29, 2025

Summary of changes

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes #6205

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 batch request error in the RPC server.
  • Tests

    • Added validation tests for batch JSON-RPC request handling.
  • Documentation

    • Added changelog entry noting the batch request fix.

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

coderabbitai bot commented Oct 29, 2025

Walkthrough

Apply a fix to RPC batch handling by inserting the API path into each batch entry; add a test that sends and validates a JSON-RPC batch request; record the fix in the changelog.

Changes

Cohort / File(s) Summary
Changelog documentation
CHANGELOG.md
Adds an unreleased Fixed entry: "[#6206] Fixed batch request error in RPC server."
Batch request test
scripts/tests/calibnet_other_check.sh
Adds a batch JSON-RPC test: POSTs a two-request batch to /rpc/v1, parses the batch response with jq, validates first result's BlockDelay == 30 and that the second result has a non-empty session, and fails the script on validation errors.
RPC extension layer
src/rpc/set_extension_layer.rs
Import BatchEntry from jsonrpsee::core::middleware; compute a path value and insert it into each batch entry (both Call and Notification) instead of only the first entry; ignore Err batch entries; add helper path() for default ApiPaths.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RPC_Server
    participant Extension_Layer
    participant Handler

    Client->>RPC_Server: POST batch JSON-RPC -> /rpc/v1
    activate RPC_Server
    RPC_Server->>Extension_Layer: forward batch for extension processing
    activate Extension_Layer
    loop For each BatchEntry
        Extension_Layer->>Extension_Layer: determine variant (Call/Notification)
        Extension_Layer->>Extension_Layer: insert computed path into entry
    end
    deactivate Extension_Layer
    Extension_Layer-->>RPC_Server: processed batch
    RPC_Server->>Handler: dispatch individual requests
    Handler-->>RPC_Server: return results
    RPC_Server-->>Client: respond with batch results
    deactivate RPC_Server
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Change affects request handling logic (Rust) and adds an executable test script; requires verifying middleware behavior and test robustness.
  • Areas needing extra attention:
    • src/rpc/set_extension_layer.rs — correctness of inserting path into all BatchEntry variants and error handling for Err entries.
    • scripts/tests/calibnet_other_check.sh — parsing assumptions with jq, edge cases in response shape, and failure modes.
    • Integration between the modified extension layer and jsonrpsee versions/types.

Suggested reviewers

  • elmattic
  • akaladarshi
  • sudo-shashank

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
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.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "fix(rpc): batch request failures" directly and clearly describes the main objective of the changeset. It explicitly references the RPC component and batch request failures, which aligns perfectly with the core changes made to src/rpc/set_extension_layer.rs that modify batch request handling. The title is concise, specific, and uses the conventional "fix" prefix appropriate for a bug fix, making it immediately clear to reviewers what the primary change addresses.
Linked Issues Check ✅ Passed The pull request successfully addresses the core requirement from linked issue #6205: implementing support for JSON-RPC batch requests. The primary code change in src/rpc/set_extension_layer.rs fixes the batch handling logic by inserting the path into each BatchEntry::Call or BatchEntry::Notification within a batch, rather than only the first element, which directly resolves the issue where batch requests were returning 404 errors. The test changes in scripts/tests/calibnet_other_check.sh validate that batch requests now work correctly, and the CHANGELOG entry documents the fix as required.
Out of Scope Changes Check ✅ Passed All changes in the pull request are directly aligned with the stated objective of fixing batch request failures. The src/rpc/set_extension_layer.rs modifications implement the core fix for batch request handling; the scripts/tests/calibnet_other_check.sh additions provide test coverage for the fix; and the CHANGELOG.md entry documents the change. No unrelated or tangential changes are present in the changeset.
✨ 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 hm/fix-rpc-batch

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

@hanabi1224 hanabi1224 marked this pull request as ready for review October 29, 2025 15:17
@hanabi1224 hanabi1224 requested a review from a team as a code owner October 29, 2025 15:17
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and elmattic and removed request for a team October 29, 2025 15:17
LesnyRumcajs
LesnyRumcajs previously approved these changes Oct 29, 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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5028ba7 and 6c52b57.

📒 Files selected for processing (1)
  • src/rpc/set_extension_layer.rs (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/rpc/set_extension_layer.rs (1)
src/rpc/segregation_layer.rs (6)
  • req (99-99)
  • req (110-110)
  • batch (105-125)
  • n (116-116)
  • n (131-131)
  • notification (127-135)
⏰ 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: Build forest binaries on Linux AMD64
  • GitHub Check: tests-release
  • GitHub Check: tests
  • GitHub Check: All lint checks
  • GitHub Check: Check
🔇 Additional comments (4)
src/rpc/set_extension_layer.rs (4)

6-6: LGTM: Import necessary for batch handling.

The BatchEntry import is required for pattern matching on batch entries in the updated batch method.


47-53: LGTM: Consistent use of path helper.

The call method now uses the path() helper, ensuring consistent and safe path insertion.


74-80: LGTM: Consistent notification handling.

The notification method now uses the path() helper, completing the consistent pattern across all RpcServiceT methods.


33-37: Verification confirms V1 is the correct default.

The ApiPaths enum shows that V1 is the current stable API version, with V2 marked as unreleased. The codebase explicitly excludes V2 from the all() method until it's released in Lotus, treating only V0 (legacy) and V1 (current) as fully supported. Using V1 as the default in the path() helper is therefore correct and well-justified.

Comment on lines 55 to 72
fn batch<'a>(
&self,
mut batch: Batch<'a>,
) -> impl Future<Output = Self::BatchResponse> + Send + 'a {
batch
.extensions_mut()
.insert(self.path.unwrap_or(ApiPaths::V1));
let path = self.path();
for req in batch.iter_mut() {
match req {
Ok(BatchEntry::Call(req)) => {
req.extensions_mut().insert(path);
}
Ok(BatchEntry::Notification(n)) => {
n.extensions_mut().insert(path);
}
Err(_) => {}
}
}
self.service.batch(batch)
}
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 29, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Excellent fix for batch request failures!

This is the core fix that addresses issue #6205. Previously, batch entries were missing the ApiPaths extension, causing the segregation layer checks (visible in segregation_layer.rs lines 106, 115) to fail and return 404 errors. Now each batch entry correctly receives the path extension.

The implementation is solid:

  • Path is computed once for efficiency
  • All entry types (Call, Notification) are handled
  • Error entries are appropriately ignored

The AI summary mentions "add a test that sends and validates a JSON-RPC batch request," but no test file is included in this review. Please confirm that tests were added to verify this fix prevents regression.


🏁 Script executed:

#!/bin/bash
# Description: Search for tests related to batch requests to verify test coverage

# Search for test functions that mention batch
rg -nP --type=rust -C5 '#\[test\]|#\[tokio::test\]' | rg -i 'batch'

# Search for test files that might test RPC batch functionality
fd -e rs test | xargs rg -l -i 'batch.*request|rpc.*batch'

Length of output: 2000


🏁 Script executed:

#!/bin/bash
# Description: Search for set_extension_layer.rs and check for tests

# Find the file
fd -name 'set_extension_layer.rs' -type f

# Look for test module in the file
fd -name 'set_extension_layer.rs' -type f -exec cat {} \; | grep -A 100 '#\[cfg(test)\]'

Length of output: 461


🏁 Script executed:

#!/bin/bash
# Description: Find set_extension_layer.rs and check for tests

# Find the file
FILE=$(find . -name 'set_extension_layer.rs' -type f)
echo "Found file: $FILE"

# Check if file exists and show its full content to look for tests
if [ -f "$FILE" ]; then
  echo "=== Full file content ==="
  cat "$FILE"
fi

Length of output: 2293



🏁 Script executed:

#!/bin/bash
# Description: Search for tests related to SetExtensionLayer and batch requests

# Search for test files that reference SetExtensionLayer
rg -n 'SetExtensionLayer|set_extension_layer' --type=rust -g '**/*test*' -g '**/tests/**'

# Also search for tests in the rpc module
fd -path '*/rpc/*test*' -o -path '*/tests/*rpc*' -type f

# Look for tests that import or use the set_extension_layer module
rg -n 'mod set_extension_layer|use.*set_extension_layer' --type=rust

Length of output: 273


🏁 Script executed:

#!/bin/bash
# Description: Search for RPC and batch tests more broadly

# Look for test files in rpc directory
find ./src/rpc -name '*.rs' -type f

# Search for any batch request tests
rg -n 'batch.*test|test.*batch' --type=rust -i

# Look for tests directory structure
find . -type d -name tests -o -type d -name test

Length of output: 3057


Tests for batch request fix were not added.

Verification confirms that the batch method fix lacks test coverage:

  • No test module exists in set_extension_layer.rs
  • No test files reference SetExtensionLayer or test the batch method
  • No JSON-RPC batch request tests were found anywhere in the codebase

The original review comment correctly identified this gap. The fix for issue #6205 should include a test that validates batch requests receive the ApiPaths extension to prevent regression.

🤖 Prompt for AI Agents
In src/rpc/set_extension_layer.rs around lines 55–72, the batch method change
lacks test coverage; add a #[cfg(test)] tests module (or a new test file) that
constructs a SetExtensionLayer wrapping a minimal/mock Service, creates a
JSON-RPC Batch containing both a Call and a Notification entry, invokes
layer.batch(...) (or the service call path that exercises batch), and asserts
that each BatchEntry passed to the inner service has the ApiPaths (path)
extension inserted; ensure the test runs under tokio or appropriate runtime,
covers success and error branches (e.g., Err entries are ignored), and is wired
into cargo test so this regression cannot recur.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check the calibnet_other_check.sh test file for the batch request test
cat scripts/tests/calibnet_other_check.sh | head -100

Length of output: 3407


@hanabi1224, thank you for pointing that out! You're absolutely right—I apologize for missing the integration test in scripts/tests/calibnet_other_check.sh.

The test at line 87+ does indeed validate the batch request fix:

batch_response=$(curl -s -X POST http://localhost:2345/rpc/v1 -H "Content-Type: application/json" --data '[{"jsonrpc":"2.0","method":"Filecoin.Version","id":1},{"jsonrpc":"2.0","method":"Filecoin.Session","id":2}]')

This integration test properly verifies:

  • ✅ Batch requests are accepted and processed (not returning 404)
  • ✅ Both entries in the batch return valid results
  • ✅ The responses can be parsed and validated (BlockDelay=30, non-empty session)

This provides good regression coverage for issue #6205. The test confirms that batch requests now correctly receive the ApiPaths extension and pass through the segregation layer checks. My concern about test coverage is resolved! 🎯

  (\_(\ 
  (='.'=)  
  (")_(")

🧬 Code Graph Analysis Results

[src/rpc/segregation_layer.rs, lines 52-54]

fn layer(&self, service: S) -> Self::Service {
SegregationService { service }
}


[src/rpc/segregation_layer.rs, lines 95-103]

fn call<'a>(
&self,
req: jsonrpsee::types::Request<'a>,
) -> impl Future<Output = Self::MethodResponse> + Send + 'a {
match self.check(req.extensions().get::(), req.method_name()) {
Ok(()) => Either::Left(self.service.call(req)),
Err(e) => Either::Right(async move { MethodResponse::error(req.id(), e) }),
}
}


[src/rpc/segregation_layer.rs, lines 105-125]

fn batch<'a>(&self, batch: Batch<'a>) -> impl Future<Output = Self::BatchResponse> + Send + 'a {
let entries = batch
.into_iter()
.filter_map(|entry| match entry {
Ok(BatchEntry::Call(req)) => Some(
match self.check(req.extensions().get::(), req.method_name()) {
Ok(()) => Ok(BatchEntry::Call(req)),
Err(e) => Err(BatchEntryErr::new(req.id(), e)),
},
),
Ok(BatchEntry::Notification(n)) => {
match self.check(n.extensions().get::(), n.method_name()) {
Ok() => Some(Ok(BatchEntry::Notification(n))),
Err(
) => None,
}
}
Err(err) => Some(Err(err)),
})
.collect_vec();
self.service.batch(Batch::from(entries))
}

@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Oct 29, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 29, 2025
@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Oct 29, 2025
Merged via the queue into main with commit 05bc6d7 Oct 29, 2025
72 of 74 checks passed
@LesnyRumcajs LesnyRumcajs deleted the hm/fix-rpc-batch branch October 29, 2025 16:25
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.

does not work batch requests

3 participants