Repository navigation
fix(jsonrpc): suppress error responses for notifications - #4146
Conversation
brbrr
left a comment
There was a problem hiding this comment.
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.
brbrr
left a comment
There was a problem hiding this comment.
Thanks for the update. One check is good, but the fix moved the whole dispatch into a nested if/else, and that brings its own problem:
tupleis declared up front and stays nil on both error paths. The only thing that stopstuple[errorIndex]from panicking is theif res.Error != nilreturn above it. That link is implicit, and the next person to edit this function will not see it.- The happy path now sits three levels deep.
Keep the gate in one place, but put it outside the dispatch instead of inside it. Something like:
- Move the body of
handleRequestfromres := &response{...}to the end into a new methodcallMethod(ctx, req) (*response, http.Header). Keep its original early returns as they were onmain. Drop theerrorreturn value, it was always nil pastisSane. - Remove the
res.ID == nilcheck from inside the dispatch. - Leave
handleRequestas:
if err := req.isSane(); err != nil {
s.logger.Trace("Request sanity check failed", zap.Error(err))
return nil, http.Header{}, err
}
res, header := s.callMethod(ctx, req)
if req.ID == nil { // notification
s.logger.Trace("Notification received, no response expected")
return nil, header, nil
}
return res, header, nil
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4146 +/- ##
==========================================
- Coverage 80.27% 80.17% -0.11%
==========================================
Files 502 502
Lines 38341 38343 +2
==========================================
- Hits 30779 30741 -38
- Misses 7553 7593 +40
Partials 9 9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
8af8a35 to
a525b35
Compare
|
@arunimshukla can you please rebase the PR, to make sure the commits are verified (I've noted that you've set it up already on your end). Thanks! |
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
id.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.
All three packages pass with the race detector enabled.
Reference: https://www.jsonrpc.org/specification