Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

JSON serialisation of numbers (specifically u64) #1270

Closed
jacogr opened this issue Dec 14, 2018 · 2 comments
Closed

JSON serialisation of numbers (specifically u64) #1270

jacogr opened this issue Dec 14, 2018 · 2 comments
Assignees
Labels
I4-annoyance The client behaves within expectations, however this “expected behaviour” itself is at issue. Z2-medium Can be fixed by a coder with good Rust knowledge but little knowledge of the codebase.
Milestone

Comments

@jacogr
Copy link
Contributor

jacogr commented Dec 14, 2018

Currently we serialise u64 (e.g. BlockNumber) into a plain number in the JSON over RPC, e.g. for a header we would return -

  "result": {
    "digest": {
      "logs": [
        {
          "Seal": [
            256804359,
            "0x2c0e0ee8a5d1a073da3f8db002b8eaebcd7b1a7eb25662e09f9ef0ac58d96bf17896256cd5f0bc672f96aab49fe5163ca5cb4c1a0f047dc39e89cd4a9eb2ea05"
          ]
        }
      ]
    },
    "extrinsicsRoot": "0x1da0d30001d07991baef3c5c65234c2e88bec659dc0d7138a7e7267e2bacbeb7",
    "number": 2918,
    "parentHash": "0xb58e4d84c2e0db1cdc8c8830aa719015f8c855f29a0dff2b158a160f29f73ba0",
    "stateRoot": "0x22f6f5b6992ab87ea5f52b2732ed9e22a88643ed3a97251986857633687fbc54"
  },
  "id": 1
}

(This is a good example since BlockNumber = u64 and Seal = (u64, Signature))

This is problematic for some middleware, e.g. in JavaScript where the maximum integer number is 2^53 - 1, anything over this and the JSON will not be parsed. We have not run into this yet, since we are reasonably far from limits, however there is a possibility of problems down the line. I would suggest that anything over u32 be encoded as the hex value.

@gavofyork gavofyork added this to the 1.0 (final) milestone Dec 15, 2018
@gavofyork gavofyork added J0-enhancement An additional feature request. I4-annoyance The client behaves within expectations, however this “expected behaviour” itself is at issue. and removed J0-enhancement An additional feature request. labels Dec 15, 2018
@gavofyork gavofyork modified the milestones: 1.0 (final), 1.0gamma Dec 18, 2018
@gavofyork gavofyork added the Z2-medium Can be fixed by a coder with good Rust knowledge but little knowledge of the codebase. label Jan 7, 2019
@gavofyork
Copy link
Member

@tomusdrw any chance you could look into this?

@tomusdrw
Copy link
Contributor

tomusdrw commented Jan 9, 2019

@gavofyork yeah, I'm actually working on it just now.

@tomusdrw tomusdrw self-assigned this Jan 9, 2019
liuchengxu added a commit to liuchengxu/substrate that referenced this issue May 31, 2023
…-transition-proof-part-2

Revamp invalid state transition proof (part 2)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
I4-annoyance The client behaves within expectations, however this “expected behaviour” itself is at issue. Z2-medium Can be fixed by a coder with good Rust knowledge but little knowledge of the codebase.
Projects
None yet
Development

No branches or pull requests

3 participants