-
Notifications
You must be signed in to change notification settings - Fork 214
Add batch request limit and response size limit in a RPC batch request #2357
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
Add batch request limit and response size limit in a RPC batch request #2357
Conversation
Coverage from tests in coverage: 54.8% of statements across all listed packagescoverage: 68.6% of statements in consensus/istanbul coverage: 63.3% of statements in consensus/istanbul/announce coverage: 57.0% of statements in consensus/istanbul/backend coverage: 0.0% of statements in consensus/istanbul/backend/backendtest coverage: 24.3% of statements in consensus/istanbul/backend/internal/replica coverage: 65.2% of statements in consensus/istanbul/core coverage: 50.0% of statements in consensus/istanbul/db coverage: 0.0% of statements in consensus/istanbul/proxy coverage: 64.2% of statements in consensus/istanbul/uptime coverage: 52.4% of statements in consensus/istanbul/validator coverage: 79.2% of statements in consensus/istanbul/validator/random |
|
// Once total size of responses exceeds an allowed maximum, | ||
// generate error messages for all remaining calls and stop further processing | ||
if responseBytes += len(answer.Result); responseBytes > BatchResponseMaxSize { | ||
for i := idx; i < len(calls); i++ { |
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.
Since we added one answer
above, don't we have to either
- start at
idx +1
to reject all the following requests (and live with the fact that we slightly exceededresponseBytes
) or - do this check before appending the current
answer
toanswers
?
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.
+1 to check before
// Once total size of responses exceeds an allowed maximum, | ||
// generate error messages for all remaining calls and stop further processing | ||
if responseBytes += len(answer.Result); responseBytes > BatchResponseMaxSize { | ||
for i := idx; i < len(calls); i++ { |
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.
+1 to check before
Description
This PR adds limitations of number of batch items and response size in JSON-RPC request for avoiding an excessive memory usage.
After this change, a batch request can contain up to a maximum of 1000 requests, and the total size of all result data is limited to 25 MB.
The hardcoded boundary values are based on the default values in the current implementation of go-ethereum.
Other changes
Describe any minor or "drive-by" changes here.
Tested
I added unit tests for each change
Related issues
Backwards compatibility
Brief explanation of why these changes are/are not backwards compatible.