Skip to content

fix(evmrpc): omit notifications from legacy JSON-RPC batch responses per spec#3246

Merged
amir-deris merged 5 commits intomainfrom
amir/plt-258-json-rpc-batch-legacy-omit-response-for-notifications
Apr 15, 2026
Merged

fix(evmrpc): omit notifications from legacy JSON-RPC batch responses per spec#3246
amir-deris merged 5 commits intomainfrom
amir/plt-258-json-rpc-batch-legacy-omit-response-for-notifications

Conversation

@amir-deris
Copy link
Copy Markdown
Contributor

@amir-deris amir-deris commented Apr 14, 2026

Summary

Fixes the sei-legacy-http batch gateway to correctly handle JSON-RPC 2.0 notifications (requests with no id field).

Previous behavior:

  • Notifications were assigned "leftover" inner responses in FIFO order, producing spurious response entries
  • When all items in a batch produced no responses, the gateway returned [] (an empty JSON array)

New behavior per JSON-RPC 2.0 §6:

  • Notifications are silently omitted from the batch response array
  • If every item in a batch is a notification (or produces no response), the server sends an empty HTTP body rather than []
  • Batch response array length is no longer 1:1 with the request batch when notifications are present

Changes:

  • Switched from fixed-size indexed output arrays to append-based slices so response count naturally matches non-notification items
  • Extracted seiLegacyBatchResponsesNoForward helper for the no-forward path
  • Extracted appendMergeFailure closure in mergeSeiLegacyHTTPBatch to eliminate repeated merge-failure blocks
  • Added writeJSONRPCBatchResponse which handles the empty-body case (replaces direct writeJSONArrayResponse calls)
  • Updated AGENTS.md to document the notification-omission and empty-body behaviour
  • Added four unit tests covering: notification omitted from merged response, notification + blocked call, invalid + notification, all-notifications → empty body

Test plan

  • go test ./evmrpc/... -run TestWrapSeiLegacyHTTP_Batch
  • Existing legacy batch tests continue to pass

@amir-deris amir-deris self-assigned this Apr 14, 2026
@amir-deris amir-deris changed the title modified sei-legacy-http to not send response for notifications fix(evmrpc): omit notifications from legacy JSON-RPC batch responses per spec Apr 14, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 14, 2026

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

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

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

❌ Patch coverage is 86.04651% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.26%. Comparing base (8aeb6ca) to head (14f7301).

Files with missing lines Patch % Lines
evmrpc/sei_legacy_http.go 86.04% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3246   +/-   ##
=======================================
  Coverage   59.25%   59.26%           
=======================================
  Files        2070     2070           
  Lines      169784   169764   -20     
=======================================
+ Hits       100600   100605    +5     
+ Misses      60382    60359   -23     
+ Partials     8802     8800    -2     
Flag Coverage Δ
sei-chain-pr 64.22% <86.04%> (?)
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 80.23% <86.04%> (+7.70%) ⬆️
🚀 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.

@amir-deris amir-deris requested review from bdchatham and masih April 14, 2026 20:45
Comment thread evmrpc/sei_legacy_http.go Outdated
out := make([]json.RawMessage, 0, lenMsgs)
for i := 0; i < lenMsgs; i++ {
if invalidReq[i] {
out = append(out, marshalJSONRPCError(orNullID(ids[i]), -32600, seiLegacyBatchInvalidReqMsg))
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.

nit: can you set a constant with a self-describing name for -32600? I had to look this up. Without context, it's a magic number to a reader.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is a good point. Will make the fix for it.

Comment thread evmrpc/sei_legacy_http.go
// read more than the inner JSON-RPC stack will accept (see rpc.Server.SetHTTPBodyLimit).
const seiLegacyHTTPMaxBody = 5 * 1024 * 1024

const (
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.

Nice 👍🏻

Comment thread evmrpc/sei_legacy_http.go Outdated
lenMsgs int,
) []json.RawMessage {
out := make([]json.RawMessage, 0, lenMsgs)
for i := 0; i < lenMsgs; i++ {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Use the newer for range syntax

Suggested change
for i := 0; i < lenMsgs; i++ {
for i := range lenMsgs {

@amir-deris amir-deris added this pull request to the merge queue Apr 15, 2026
Merged via the queue into main with commit 89aed57 Apr 15, 2026
39 checks passed
@amir-deris amir-deris deleted the amir/plt-258-json-rpc-batch-legacy-omit-response-for-notifications branch April 15, 2026 16:08
yzang2019 added a commit that referenced this pull request Apr 16, 2026
* main:
  Fix buffer offset in ProposerPriorityHash (CON-200) (#3255)
  Handle error case in light client divergence detector (#3254)
  perf(evmrpc): eliminate redundant block fetches in simulate backend (#3208)
  fix(evmrpc): omit notifications from legacy JSON-RPC batch responses per spec (#3246)
  fix: deduplicate block fetch in getTransactionReceipt (#3244)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants