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

[API] add batch size limit for jsonrpc #3805

Merged
merged 14 commits into from
Feb 15, 2023
Merged

[API] add batch size limit for jsonrpc #3805

merged 14 commits into from
Feb 15, 2023

Conversation

millken
Copy link
Contributor

@millken millken commented Feb 9, 2023

Description

Limit the count of batch requests in websocket

Fixes #(issue)

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

@codecov
Copy link

codecov bot commented Feb 9, 2023

Codecov Report

Merging #3805 (cd980f2) into master (263ff82) will increase coverage by 0.93%.
The diff coverage is 80.54%.

❗ Current head cd980f2 differs from pull request most recent head 107acd3. Consider uploading reports for the commit 107acd3 to get more accurate results

@@            Coverage Diff             @@
##           master    #3805      +/-   ##
==========================================
+ Coverage   74.47%   75.40%   +0.93%     
==========================================
  Files         269      303      +34     
  Lines       23925    25855    +1930     
==========================================
+ Hits        17818    19496    +1678     
- Misses       5174     5340     +166     
- Partials      933     1019      +86     
Impacted Files Coverage Δ
action/actctx.go 90.62% <ø> (+6.25%) ⬆️
action/action.go 82.35% <ø> (ø)
action/action_deserializer.go 57.14% <ø> (ø)
action/candidate_update.go 88.88% <0.00%> (-4.14%) ⬇️
action/consignment_transfer.go 90.41% <ø> (ø)
action/const.go 100.00% <ø> (ø)
action/execution.go 83.78% <ø> (ø)
action/grantreward.go 68.57% <ø> (ø)
action/protocol/account/protocol.go 86.90% <ø> (ø)
action/protocol/dock.go 100.00% <ø> (ø)
... and 283 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Liuhaai
Copy link
Member

Liuhaai commented Feb 10, 2023

@millken
Copy link
Contributor Author

millken commented Feb 10, 2023

its limited at https://github.com/iotexproject/iotex-core/blob/master/api/websocket.go#L64

only the message body size is limited here(15M), there needs to limit jsonRPC batch request array size.

@@ -41,6 +41,7 @@ type (
}

web3Handler struct {
cfg Config
Copy link
Member

Choose a reason for hiding this comment

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

can just add batchSizeLimit, since web3handler does not need the entire Config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

api/config.go Outdated Show resolved Hide resolved
@@ -81,10 +82,11 @@ func init() {
}

// NewWeb3Handler creates a handle to process web3 requests
func NewWeb3Handler(core CoreService, cacheURL string) Web3Handler {
func NewWeb3Handler(core CoreService, cfg Config) Web3Handler {
Copy link
Collaborator

Choose a reason for hiding this comment

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

(core CoreService, limit uint16)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cacheURL string also from cfg Config

@@ -41,8 +41,9 @@ type (
}

web3Handler struct {
coreService CoreService
cache apiCache
batchSizeLimit uint16
Copy link
Collaborator

Choose a reason for hiding this comment

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

batchSizeLimit int

return &web3Handler{
coreService: core,
cache: newAPICache(15*time.Minute, cacheURL),
batchSizeLimit: cfg.BatchSizeLimit,
Copy link
Collaborator

Choose a reason for hiding this comment

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

convert type here

@sonarcloud
Copy link

sonarcloud bot commented Feb 15, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
12.9% 12.9% Duplication

@Liuhaai Liuhaai merged commit 79b6052 into iotexproject:master Feb 15, 2023
dustinxie pushed a commit that referenced this pull request Feb 18, 2023
* add batch size limit for jsonrpc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants