paritytech / cumulus

Write Parachains on Substrate
GNU General Public License v3.0
618 stars 378 forks source link

Node panics upon serializing `u128` in rpc-endpoint #1224

Open mustermeiszer opened 2 years ago

mustermeiszer commented 2 years ago

I am getting this error when querying a custom rpc-endpoint.

Thread 'tokio-runtime-worker' panicked at 'Expected always-serializable type; qed: Error("u128 is not supported", line: 0, column: 0)', src/rpc/pools.rs:12

This is a bug. Please report it at:

    https://github.com/paritytech/cumulus/issues/new

Code

mustermeiszer commented 2 years ago

Note: Error originates from macro in jsonrpc here https://github.com/paritytech/jsonrpc/blob/0a2702595b8831a9a30dec7dc476157c648c361c/derive/src/to_delegate.rs#L285.

mustermeiszer commented 2 years ago

I also hard-coded the balance as u128 to check whether I mixed the final types in the runtime-api impl. But all compiles fine.

bkchr commented 2 years ago

There are bugs around serde-json and u128 serialized as a serde_json::Value or something. I don't remember all the details, sorry! But now as we have jsonrpsee, this is maybe solved? Maybe @niklasad1 can help here.

niklasad1 commented 2 years ago

I think this particular usecase should work in jsonrpsee as long plain u128/i128 are used and not in a type with serde flatten/untagged attributes. This will only work in the servers, the clients still have this issue.

with serde flatten/untagged it is pretty much the same story you can find more information in https://github.com/paritytech/jsonrpsee/issues/480

but the jsonrpc crate supports arbitrary precision which jsonrpsee doesn't but nothing that prevents folks from enabling that feature on serde_json themselves but then you will run in weird bugs with tagged enums (such as Id::Number(u64)) will not work.

xlc commented 2 years ago

It is known issue u128 doesn't play nicely with RPC. See my fix in Substrate https://github.com/paritytech/substrate/pull/4898