Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: support returning nil pointer big.Ints (null) #16942

Merged
merged 1 commit into from
Jun 11, 2018

Conversation

karalabe
Copy link
Member

@karalabe karalabe commented Jun 11, 2018

Fixes #16925.

We replaced big.Int RPC handling in our codebase a long time ago with a custom type (hexutils.Big). Almost all paths were updated to the new type, but a couple old invocations remained. These legacy cases couldn't cleanly handle nil returns due to a convoluted way our legacy code handled hex encodings (reflect.Value().Interface()) wrappings.

if err != nil {
return nil, err
}
return (*hexutil.Big)(price), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just return (*hexutil.Big)(price), err without the if.

rpc/utils.go Outdated
// to reliably catch these type issues otherwise.
if t.Name() == "Int" && t.PkgPath() == "math/big" {
panic(fmt.Sprintf("big.Int disallowed in RPC (%s)", method))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like this because the RPC server shouldn't be concerned with such details. Imagine documenting this: "This RPC server can be used for any API, but your methods may not return *big.Int".

Copy link
Member Author

Choose a reason for hiding this comment

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

This was the only way I myself could ensure that we caught all API violations and didn't break anything (i.e. I only fixed getBalance and this mechanism caught the other 2-3 occurrences).

@karalabe karalabe added this to the 1.8.11 milestone Jun 11, 2018
@karalabe
Copy link
Member Author

@fjl Fixed, PTAL.

Copy link
Contributor

@fjl fjl left a comment

Choose a reason for hiding this comment

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

LGTM

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