Skip to content

fix: charge RPC batches by operation cost - #728

Open
Seranged wants to merge 1 commit into
developmentfrom
fix/rpc-batch-rate-limits
Open

fix: charge RPC batches by operation cost#728
Seranged wants to merge 1 commit into
developmentfrom
fix/rpc-batch-rate-limits

Conversation

@Seranged

Copy link
Copy Markdown
Contributor

Summary

  • Make RPC proxy rate-limit consumption reflect every batch operation and the upstream work each request can trigger.
  • Reject unbounded log queries and oversized simulation inputs before budget consumption or an upstream fetch.

Changes

  • Assign method-specific base costs and add bounded modifiers for calldata, explicit gas, state overrides, log ranges, and fee history.
  • Cap RPC params, calldata, gas, override accounts and storage, fee-history depth, and log-filter breadth.
  • Preserve the Viem and Wagmi request shapes used by Lite, including state overrides, block-hash logs, and latest-block polling.
  • Add deterministic route coverage for exact costs, 100-operation batches, validation boundaries, and limiter rejection.

Test plan

  • npm run test:run -- tests/server/rpc-proxy-route.test.ts
  • npm run test:run
  • npm run typecheck
  • npm run lint
  • git diff --check

Bound expensive RPC parameters and account for method and request complexity before forwarding to the upstream provider.
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 11 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository: euler-xyz/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8db36724-e6db-4b5d-904d-009ab51a593f

📥 Commits

Reviewing files that changed from the base of the PR and between 5b97c37 and 8d707f6.

📒 Files selected for processing (2)
  • server/api/internal/rpc/[chainId].ts
  • tests/server/rpc-proxy-route.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rpc-batch-rate-limits

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

@railway-app

railway-app Bot commented Jul 10, 2026

Copy link
Copy Markdown

🚅 Deployed to the euler-lite-pr-728 environment in euler-lite(dev,PR previews)

Service Status Web Updated (UTC)
dev-build ✅ Success (View Logs) Web Jul 31, 2026 at 9:58 am

@LeonardEulerXYZ LeonardEulerXYZ left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at 8d707f6025ed73eb9bb9895477a1cc0e02097f4e.

Verdict: changes requested — batch aggregation, parameter bounds, state-override accounting, bounded log filters, and fee-history limits are well covered, but eth_call can bypass the gas-cost modifier by omitting the optional gas field. That preserves the expensive upstream execution while receiving only the cheapest call charge; see the inline finding.

Validation:

  • focused RPC route tests: 37 passed
  • Nuxt typecheck: passed
  • focused ESLint: passed
  • git diff --check: passed
  • repository CI and preview deployment: green

The 100-operation batch is now charged operation-by-operation, malformed/oversized inputs are rejected before limiter consumption/upstream fetch, and the abstraction remains centralized. Browser screenshots are not applicable to this server/API cost-accounting change.

}

let cost = steppedModifier(calldataBytes, CALLDATA_COST_CHUNK_BYTES)
if (transaction.gas !== undefined) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Medium — omitting gas bypasses the execution-cost charge. gas is optional for eth_call; when absent, the RPC node still executes with its configured/default call gas cap, which can be as expensive as the maximum allowed explicit gas. Here the modifier only runs when the client supplies transaction.gas, so an adversary can remove that field and reduce a potentially max-cost call to the base cost of 2. Please conservatively charge omitted gas against an appropriate default/cap (or otherwise bound the upstream execution), and add a regression test proving that removing gas cannot make the same expensive call materially cheaper.

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.

2 participants