-
Notifications
You must be signed in to change notification settings - Fork 182
fix(rpc): batch request failures #6206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughApply 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this 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
📒 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
BatchEntryimport is required for pattern matching on batch entries in the updatedbatchmethod.
47-53: LGTM: Consistent use of path helper.The
callmethod now uses thepath()helper, ensuring consistent and safe path insertion.
74-80: LGTM: Consistent notification handling.The
notificationmethod now uses thepath()helper, completing the consistent pattern across allRpcServiceTmethods.
33-37: Verification confirms V1 is the correct default.The
ApiPathsenum shows that V1 is the current stable API version, with V2 marked as unreleased. The codebase explicitly excludes V2 from theall()method until it's released in Lotus, treating only V0 (legacy) and V1 (current) as fully supported. Using V1 as the default in thepath()helper is therefore correct and well-justified.
| 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) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 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"
fiLength 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=rustLength 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 testLength 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
SetExtensionLayeror 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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))
}
Summary of changes
Changes introduced in this pull request:
Reference issue to close (if applicable)
Closes #6205
Other information and links
Change checklist
Summary by CodeRabbit
Bug Fixes
Tests
Documentation