Skip to content

Fix gzip corruption in EVM JSON-RPC responses via seiLegacyHTTPGate#3181

Merged
masih merged 6 commits into
mainfrom
masih/evp-rpc-fix
Apr 3, 2026
Merged

Fix gzip corruption in EVM JSON-RPC responses via seiLegacyHTTPGate#3181
masih merged 6 commits into
mainfrom
masih/evp-rpc-fix

Conversation

@masih

@masih masih commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator

The seiLegacyHTTPGate middleware wraps outside the gzip handler, so its
httptest.Recorder captures gzip-compressed bytes from the inner handler.
This causes two problems:

  1. For single and all-forwarded batches the gate replays compressed
    bytes to the real http.ResponseWriter, breaking gzip framing for
    clients like ethers.js v6 (Z_DATA_ERROR).

  2. For mixed/gated batches the gate calls json.Unmarshal on compressed
    bytes, which fails, causing all results to be replaced with -32603
    errors — and then writes plain JSON with a Content-Encoding: gzip
    header copied from the recorder.

Fix both paths:

  • Non-gated methods (eth_, web3_, net_*) now bypass the recorder
    entirely via serveInnerWithBody, so the gzip handler writes directly
    to the real response writer.

  • Recorder paths (gated sei_* singles, mixed batches) strip
    Accept-Encoding from the cloned request so the inner gzip handler
    is a no-op. The recorder captures plain JSON, merge logic works,
    and no stale Content-Encoding: gzip header is propagated.

Update two existing batch tests that relied on the recorder/merge path
for all-eth batches: add a blocked sei_* element to each so they still
exercise mergeSeiLegacyHTTPBatch through the recorder path.

The seiLegacyHTTPGate middleware wraps outside the gzip handler, so for
every eth_*/web3_*/net_* request it captures the gzip-compressed response
into an httptest.Recorder then replays the already-compressed bytes to
the real http.ResponseWriter. This record-and-replay of compressed data
breaks gzip framing and causes Z_DATA_ERROR in clients like ethers.js v6.

For non-sei_*/sei2_* methods the recorder adds no value — the gate
check returns nil immediately and no deprecation header is needed. Skip
the recorder for these methods and call serveInnerWithBody so the gzip
handler writes directly to the real response writer.
@github-actions

github-actions Bot commented Apr 3, 2026

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedApr 3, 2026, 3:59 PM

@codecov

codecov Bot commented Apr 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.70%. Comparing base (fcc15a3) to head (b4fef9c).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3181   +/-   ##
=======================================
  Coverage   58.69%   58.70%           
=======================================
  Files        2055     2055           
  Lines      168384   168381    -3     
=======================================
+ Hits        98838    98840    +2     
+ Misses      60742    60732   -10     
- Partials     8804     8809    +5     
Flag Coverage Δ
sei-chain-pr 66.89% <100.00%> (?)
sei-db 70.41% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
evmrpc/sei_legacy_http.go 72.52% <100.00%> (+3.20%) ⬆️

... and 44 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@masih masih changed the title Fix gzip decompression error for EVM JSON-RPC responses Fix gzip corruption in EVM JSON-RPC responses via seiLegacyHTTPGate Apr 3, 2026
@masih masih requested review from kollegian and sei-will April 3, 2026 14:23
@masih masih marked this pull request as ready for review April 3, 2026 14:23
@masih masih added backport release/v6.4 Backport to release v6.4 labels Apr 3, 2026
@masih masih enabled auto-merge April 3, 2026 14:53
@masih masih added this pull request to the merge queue Apr 3, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 3, 2026
@masih masih added this pull request to the merge queue Apr 3, 2026
Merged via the queue into main with commit b0de857 Apr 3, 2026
54 of 56 checks passed
@masih masih deleted the masih/evp-rpc-fix branch April 3, 2026 16:33
github-actions Bot pushed a commit that referenced this pull request Apr 3, 2026
…3181)

The seiLegacyHTTPGate middleware wraps outside the gzip handler, so its
httptest.Recorder captures gzip-compressed bytes from the inner handler.
This causes two problems:

1. For single and all-forwarded batches the gate replays compressed
   bytes to the real http.ResponseWriter, breaking gzip framing for
   clients like ethers.js v6 (Z_DATA_ERROR).

2. For mixed/gated batches the gate calls json.Unmarshal on compressed
   bytes, which fails, causing all results to be replaced with -32603
   errors — and then writes plain JSON with a Content-Encoding: gzip
   header copied from the recorder.

Fix both paths:

- Non-gated methods (eth_*, web3_*, net_*) now bypass the recorder
  entirely via serveInnerWithBody, so the gzip handler writes directly
  to the real response writer.

- Recorder paths (gated sei_* singles, mixed batches) strip
  Accept-Encoding from the cloned request so the inner gzip handler
  is a no-op. The recorder captures plain JSON, merge logic works,
  and no stale Content-Encoding: gzip header is propagated.

Update two existing batch tests that relied on the recorder/merge path
for all-eth batches: add a blocked sei_* element to each so they still
exercise mergeSeiLegacyHTTPBatch through the recorder path.

(cherry picked from commit b0de857)
@seidroid

seidroid Bot commented Apr 3, 2026

Copy link
Copy Markdown

Successfully created backport PR for release/v6.4:

masih added a commit that referenced this pull request Apr 3, 2026
…s via seiLegacyHTTPGate (#3188)

Backport of #3181 to `release/v6.4`.

Co-authored-by: Masih H. Derkani <m@derkani.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants