-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Migrate from JavaScript number
to string
in JSON RPC API when representing u64
values
#30741
Labels
do-not-close
Add this tag to exempt an issue/PR from being closed by the stalebot
Comments
number
to bigint
in JSON RPC APInumber
to string
in JSON RPC API when representing u64
values
steveluscher
added a commit
to solana-labs/solana-web3.js
that referenced
this issue
Mar 16, 2023
…ed for the Solana JSON RPC ## Summary `u64` values, in the Solana JSON RPC, are implemented as JavaScript numbers. This means that any number greater than `Number.MAX_SAFE_INTEGER` (9007199254740991) can't be trusted. This is tracked in solana-labs/solana#30741. In this PR we create a serializer that converts `bigint` values coming in from `@solana/rpc-core` to JavaScript `number`, as a concession. ## Test Plan ```shell pnpm test:unit:node ```
steveluscher
added a commit
to solana-labs/solana-web3.js
that referenced
this issue
Mar 16, 2023
…ed for the Solana JSON RPC ## Summary `u64` values, in the Solana JSON RPC, are implemented as JavaScript numbers. This means that any number greater than `Number.MAX_SAFE_INTEGER` (9007199254740991) can't be trusted. This is tracked in solana-labs/solana#30741. In this PR we create a serializer that converts `bigint` values coming in from `@solana/rpc-core` to JavaScript `number`, as a concession. ## Test Plan ```shell pnpm test:unit:node ```
steveluscher
added a commit
to solana-labs/solana-web3.js
that referenced
this issue
Mar 16, 2023
…ed for the Solana JSON RPC ## Summary `u64` values, in the Solana JSON RPC, are implemented as JavaScript numbers. This means that any number greater than `Number.MAX_SAFE_INTEGER` (9007199254740991) can't be trusted. This is tracked in solana-labs/solana#30741. In this PR we create a serializer that converts `bigint` values coming in from `@solana/rpc-core` to JavaScript `number`, as a concession. ## Test Plan ```shell pnpm test:unit:node ```
steveluscher
added a commit
to solana-labs/solana-web3.js
that referenced
this issue
Mar 17, 2023
…ed for the Solana JSON RPC ## Summary `u64` values, in the Solana JSON RPC, are implemented as JavaScript numbers. This means that any number greater than `Number.MAX_SAFE_INTEGER` (9007199254740991) can't be trusted. This is tracked in solana-labs/solana#30741. In this PR we create a serializer that converts `bigint` values coming in from `@solana/rpc-core` to JavaScript `number`, as a concession. ## Test Plan ```shell pnpm test:unit:node ```
steveluscher
added a commit
to solana-labs/solana-web3.js
that referenced
this issue
Mar 17, 2023
…ed for the Solana JSON RPC (#1204) ## Summary `u64` values, in the Solana JSON RPC, are implemented as JavaScript numbers. This means that any number greater than `Number.MAX_SAFE_INTEGER` (9007199254740991) can't be trusted. This is tracked in solana-labs/solana#30741. In this PR we create a serializer that converts `bigint` values coming in from `@solana/rpc-core` to JavaScript `number`, as a concession. ## Test Plan ```shell pnpm test:unit:node ```
If solana can break jsonrpc compatibility in minor versions once a year, an important issue like this one, shouldn't be held back. |
Working on it ser. One step at a time. |
Just noting this strategy should apply to |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: this will require a massive multi-year migration plan; this issue is just a stub now to point some
TODOs
to.Problem
Responses from our JSON RPC API represent
u64
numbers as JavaScript numbers. Since JavaScript numbers are IEEE 754 floating point, this will result in truncation above2^53
(ie.9007199254740992
).Example: If you call
getAccountInfo
on an account with more than 9,007,199.254740992◎, thelamports
field will be truncated. You can convince yourself of this by executing the following statement in a JS repl:Proposed Solution
Return
u64
as a value object through the JSON RPC API.A value object is one with some content and a tag that denotes its type.
Where
_
is an enum denoting the type of the value (eg. here0
would be mapped tobigint
) then the rest of the object is the data (eg. herev
is the bigint value as a string).Using value objects makes it so that the client doesn't have to keep a giant map of keypaths that are supposed to actually be strings vs. are strings but need to be cast to
bigint
. All it needs to do is to look for the tag (_
) and deserialize the value accordingly.Deprecation Plan
There are many ways to do a deprecation like this. This GitHub issue is only a stub for now; we will discuss how to move forward in the coming months.
The text was updated successfully, but these errors were encountered: