Sitelet https://github.com/NethermindEth/juno/pull/4146
Skip to content

fix(jsonrpc): suppress error responses for notifications - #4146

Open
arunimshukla wants to merge 4 commits into
NethermindEth:mainfrom
arunimshukla:fix/notification-errors
Open

arunimshukla wants to merge 4 commits into
NethermindEth:mainfrom
arunimshukla:fix/notification-errors

Conversation

@arunimshukla

Copy link
Copy Markdown

Problem

JSON-RPC notifications are requests without an id, so the server must not send a response, including an error response. Juno's request dispatcher currently emits error responses for notification requests that use an unknown method or have invalid parameters.

Changes

  • Suppress error responses for unknown-method notifications.
  • Suppress error responses for invalid-params notifications.
  • Keep normal error responses for requests that include an id.
  • Add regression coverage for notification-only and mixed batches.

Validation

I reproduced the bug with four focused cases: unknown-method notification, invalid-params notification, a notification-only failing batch, and a mixed batch. The new cases fail on the base commit and pass after the fix.

go test -race ./jsonrpc ./utils/broadcast ./core/trie2/trieutils -count=1

All three packages pass with the race detector enabled.

Reference: https://www.jsonrpc.org/specification

@brbrr brbrr 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.

Thanks for the contribution!

Please take a look at the inline comment.

Nit: the PR body lists utils/broadcast and core/trie2/trieutils under validation. Those packages are not touched, and are irrelevant to your changes.

Comment thread jsonrpc/server.go Outdated
calledMethod, found := s.methods[req.Method]
if !found {
res.Error = Err(MethodNotFound, nil)
if req.ID == nil {

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.

handleRequest already has a notification check after the handler call (if res.ID == nil { // notification). This PR adds two more before it, so the same rule now lives in three places, and the new branches assign res.Error and then throw it away. Please keep one check.

This branch has not been deployed

No deployments
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