Skip to content

rpc: fix null result unmarshalling in CallContext#20393

Merged
AskAlexSharov merged 5 commits intomainfrom
lupin012/fix-callcontext-null-unmarshal
Apr 10, 2026
Merged

rpc: fix null result unmarshalling in CallContext#20393
AskAlexSharov merged 5 commits intomainfrom
lupin012/fix-callcontext-null-unmarshal

Conversation

@lupin012
Copy link
Copy Markdown
Contributor

@lupin012 lupin012 commented Apr 7, 2026

Using &result (double indirection on interface{} already holding a pointer) prevented correct unmarshalling of JSON null responses. Fix mirrors go-ethereum PR #26723.

For erigon fixes:
https://github.com/orgs/erigontech/projects/21?pane=issue&itemId=94164858&issue=erigontech%7Csecurity%7C7

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes JSON-RPC client unmarshalling when the server returns a JSON null result by removing the accidental double-indirection (&result) and adding a regression test to ensure null results are preserved correctly.

Changes:

  • Update Client.CallContext to unmarshal into the provided result pointer (not &result) and skip unmarshalling when result is nil.
  • Add testService.ReturnNull and a client test that asserts null responses are returned as "null" (via json.RawMessage).
  • Update server registration test expectations to account for the newly exposed callback.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
rpc/client.go Fixes result unmarshalling by passing the actual result pointer to json.Unmarshal (avoids double indirection).
rpc/client_test.go Adds a regression test validating correct handling of JSON null results.
rpc/testservice_test.go Adds a ReturnNull RPC method used by the new client regression test.
rpc/server_test.go Adjusts callback count expectation due to the added ReturnNull method.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rpc/testservice_test.go Outdated
return testError{}
}

func (s *testService) ReturnNull() interface{} {
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

For consistency with the rest of this test service (which uses any elsewhere), consider changing the return type from interface{} to any here. This avoids mixing the two spellings in the same file and matches current Go style.

Suggested change
func (s *testService) ReturnNull() interface{} {
func (s *testService) ReturnNull() any {

Copilot uses AI. Check for mistakes.
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.

done

@lupin012 lupin012 marked this pull request as ready for review April 8, 2026 06:44
@lupin012 lupin012 requested a review from canepat as a code owner April 8, 2026 06:44
@yperbasis yperbasis added the RPC label Apr 8, 2026
@lupin012 lupin012 added this pull request to the merge queue Apr 8, 2026
@lupin012 lupin012 removed this pull request from the merge queue due to a manual request Apr 8, 2026
lupin012 and others added 3 commits April 9, 2026 14:00
Using &result (double indirection on interface{} already holding a pointer)
prevented correct unmarshalling of JSON null responses. Fix mirrors
go-ethereum PR #26723.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ReturnNull adds one more registered callback to testService.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lupin012 lupin012 force-pushed the lupin012/fix-callcontext-null-unmarshal branch from e936e44 to ae839c1 Compare April 9, 2026 12:06
@AskAlexSharov AskAlexSharov added this pull request to the merge queue Apr 10, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 10, 2026
@AskAlexSharov AskAlexSharov enabled auto-merge April 10, 2026 06:09
@AskAlexSharov AskAlexSharov added this pull request to the merge queue Apr 10, 2026
Merged via the queue into main with commit 4f0034b Apr 10, 2026
35 checks passed
@AskAlexSharov AskAlexSharov deleted the lupin012/fix-callcontext-null-unmarshal branch April 10, 2026 08:14
AskAlexSharov added a commit that referenced this pull request Apr 13, 2026
AskAlexSharov added a commit that referenced this pull request Apr 14, 2026
…0521)

Cherry-pick of #20393 from main.

Fixes double indirection on interface{} preventing correct unmarshalling
of JSON null responses. Mirrors go-ethereum PR #26723.
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.

4 participants