attestantio/go-eth2-client

Data type mismatch while calling Fork() method

Closed this issue · 6 comments

I am testing my beacon Node APIs by calling Fork(), the issue is at the time of decoding JSON (func decodeJSONResponse in Fork), I can see the below response after the GET call.
The error I am getting is invalid JSON: json: cannot unmarshal number into Go struct field forkJSON.epoch of type string

{
  "execution_optimistic": false,
  "finalized": false,
  "data": {
    "previous_version": "0x04000000",
    "current_version": "0x04000000",
    "epoch": 0
  }
}

epoch field is of type uint64 as per the ETH 2 consensus spec - https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#custom-types

In my case also, I have epoch is of type uint64, however in here epoch is of type string. Wanted to understand the rationale behind it.
I was wondering it should be consistent across as per the spec, I am happy to raise a PR to fix this :)

Please let me know if any other information is required.

uint64 is encoded as a string in the beacon API. Which server is this against?

Yeah! I am running this via custom consensus client - beacon-kit

I called the beaconAPI https://ethereum.github.io/beacon-APIs/#/Beacon/getStateFork by running locally , it returns the above response without any error. I tried this against custom CL client and EL client as geth.

It sounds like beacon-kit needs to fix their API servers, as they are sending an incorrectly formatted response. A good place to start is https://github.com/ethereum/beacon-APIs/blob/master/types/primitive.yaml as it contains details of the encodings of primitive types in the JSON responses.

Gotcha! Thank you, I appreciate your help :) I will refer this and fix it.

@mcdee Would it be possible for you to share your discord. I have few more queries, don't see Discussion section here.