Skip to content
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 request limits for JSON-RPC batch calls #277

Merged
merged 1 commit into from
Jun 3, 2024

Conversation

m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Jun 3, 2024

Closes: #211

Description

Add some sane default limits for batch calls:

  • Maximum number of requests is 5
  • Maximum number of response bytes across all requests is 5 MB

For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • New Features

    • Introduced batch limits for RPC requests and responses to improve performance and handling of large data sets.
  • Tests

    • Added a new test case to verify batch request functionality.
    • Improved test syntax and formatting for better readability and maintenance.

@m-Peter m-Peter added this to the Flow-EVM-M2 milestone Jun 3, 2024
@m-Peter m-Peter self-assigned this Jun 3, 2024
Copy link
Contributor

coderabbitai bot commented Jun 3, 2024

Walkthrough

The recent updates introduce batch request and response limits to the api/server.go file, enhancing the server's handling of RPC calls. Additionally, the tests/web3js/eth_non_interactive_test.js file has been refined to correct syntax and formatting, and a new test case for batch requests has been added.

Changes

File(s) Change Summary
api/server.go Introduced constants batchRequestLimit and batchResponseMaxSize. Updated NewHTTPServer to set batch limits.
tests/web3js/eth_non_interactive_test.js Corrected spacing in async function declarations, updated function call syntax, adjusted JSON formatting, and added a new test case for batch requests.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant Client
    participant HTTPServer
    participant RPCHandler
    
    Client->>HTTPServer: Send batch RPC request
    HTTPServer->>RPCHandler: Forward request with batch limits
    RPCHandler-->>HTTPServer: Process and return response
    HTTPServer-->>Client: Deliver batch RPC response
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Add sane configuration values for batch calls (#211)

Poem

In the server's code, new limits arise,
Batch requests and responses, a wise surprise.
Tests refined, async calls align,
Batch requests now tested, all looks fine.
The rabbit hops, with joy it sings,
For code improvements, these changes bring.
🚀🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 7

Outside diff range and nitpick comments (3)
tests/web3js/eth_non_interactive_test.js (3)

Line range hint 51-51: Use Number.parseFloat instead of the global parseFloat.

- assert.equal(parseFloat(flow), conf.fundedAmount)
+ assert.equal(Number.parseFloat(flow), conf.fundedAmount)
Tools
Biome

[error] 7-7: This let declares a variable that is only assigned once.


Line range hint 76-76: Consider using const instead of let for tx as it is not reassigned.

- let tx = await web3.eth.getTransaction(blockTx.hash)
+ const tx = await web3.eth.getTransaction(blockTx.hash)
Tools
Biome

[error] 7-7: This let declares a variable that is only assigned once.


Line range hint 80-80: Use Number.parseInt instead of the global parseInt.

- assert.isAbove(parseInt(tx.gas), 1)
+ assert.isAbove(Number.parseInt(tx.gas), 1)
Tools
Biome

[error] 7-7: This let declares a variable that is only assigned once.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4ae8ce7 and 3f887d8.

Files selected for processing (2)
  • api/server.go (2 hunks)
  • tests/web3js/eth_non_interactive_test.js (5 hunks)
Additional context used
Biome
tests/web3js/eth_non_interactive_test.js

[error] 7-7: This let declares a variable that is only assigned once.


[error] 13-13: This let declares a variable that is only assigned once.


[error] 16-16: This let declares a variable that is only assigned once.


[error] 24-24: This let declares a variable that is only assigned once.


[error] 28-28: This let declares a variable that is only assigned once.


[error] 29-29: This let declares a variable that is only assigned once.


[error] 35-35: This let declares a variable that is only assigned once.


[error] 42-42: This let declares a variable that is only assigned once.


[error] 47-47: This let declares a variable that is only assigned once.


[error] 50-50: This let declares a variable that is only assigned once.


[error] 51-51: Use Number.parseFloat instead of the equivalent global.


[error] 53-53: This let declares a variable that is only assigned once.


[error] 58-58: This let declares a variable that is only assigned once.


[error] 63-63: This let declares a variable that is only assigned once.


[error] 68-68: This let declares a variable that is only assigned once.


[error] 73-73: This let declares a variable that is only assigned once.


[error] 76-76: This let declares a variable that is only assigned once.


[error] 80-80: Use Number.parseInt instead of the equivalent global.


[error] 86-86: This let declares a variable that is only assigned once.


[error] 99-99: This let declares a variable that is only assigned once.

Additional comments not posted (3)
tests/web3js/eth_non_interactive_test.js (1)

114-196: The new test case for batch requests is well-implemented and adheres to the new limits set for batch processing.

api/server.go (2)

56-58: The new constants for batch processing limits are correctly defined according to the PR objectives.


112-112: The modification in the EnableRPC method to set batch limits is correctly implemented.

@@ -54,22 +54,22 @@ it('get balance', async() => {
assert.equal(wei, weiAtBlock)
})

it('get code', async() => {
it('get code', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using const instead of let for code as it is not reassigned.

- let code = await web3.eth.getCode(conf.eoa.address)
+ const code = await web3.eth.getCode(conf.eoa.address)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
it('get code', async () => {
it('get code', async () => {
const code = await web3.eth.getCode(conf.eoa.address)

@@ -43,7 +43,7 @@
assert.isNull(no)
})

it('get balance', async() => {
it('get balance', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using const instead of let for wei as it is not reassigned.

- let wei = await web3.eth.getBalance(conf.eoa.address)
+ const wei = await web3.eth.getBalance(conf.eoa.address)

Committable suggestion was skipped due low confidence.

let coinbase = await web3.eth.getCoinbase()
assert.equal(coinbase, conf.serviceEOA) // e2e configured account
})

it('get gas price', async() => {
it('get gas price', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using const instead of let for gasPrice as it is not reassigned.

- let gasPrice = await web3.eth.getGasPrice()
+ const gasPrice = await web3.eth.getGasPrice()

Committable suggestion was skipped due low confidence.

@@ -3,7 +3,7 @@
const conf = require('./config')
const web3 = conf.web3

it('get chain ID', async() => {
it('get chain ID', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using const instead of let for chainID as it is not reassigned.

- let chainID = await web3.eth.getChainId()
+ const chainID = await web3.eth.getChainId()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
it('get chain ID', async () => {
it('get chain ID', async () => {
const chainID = await web3.eth.getChainId()

@@ -95,12 +95,12 @@
assert.equal(rcp.gasUsed, tx.gas)
})

it('get mining status', async() => {
it('get mining status', async () => {
let mining = await web3.eth.isMining()
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using const instead of let for mining as it is not reassigned.

- let mining = await web3.eth.isMining()
+ const mining = await web3.eth.isMining()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
let mining = await web3.eth.isMining()
const mining = await web3.eth.isMining()
Tools
Biome

[error] 99-99: This let declares a variable that is only assigned once.

let gasPrice = await web3.eth.getGasPrice()
assert.equal(gasPrice, 0n) // 0 by default in tests
})

it('get transaction', async() => {
it('get transaction', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using const instead of let for blockTx as it is not reassigned.

- let blockTx = await web3.eth.getTransactionFromBlock(conf.startBlockHeight, 0)
+ const blockTx = await web3.eth.getTransactionFromBlock(conf.startBlockHeight, 0)

Committable suggestion was skipped due low confidence.

let code = await web3.eth.getCode(conf.eoa.address)
assert.equal(code, "0x") // empty
})

it('get coinbase', async() => {
it('get coinbase', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using const instead of let for coinbase as it is not reassigned.

- let coinbase = await web3.eth.getCoinbase()
+ const coinbase = await web3.eth.getCoinbase()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
it('get coinbase', async () => {
it('get coinbase', async () => {
const coinbase = await web3.eth.getCoinbase()

@m-Peter m-Peter merged commit b1178ae into onflow:main Jun 3, 2024
2 checks passed
@m-Peter m-Peter deleted the limit-batch-requests branch June 3, 2024 12:18
@coderabbitai coderabbitai bot mentioned this pull request Sep 20, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Add sane configuration values for batch calls
2 participants