axonweb3 / axon

Axon is a Layer 2 framework of CKB with native cross-chain and interoperability.
https://axonweb3.io
MIT License
65 stars 39 forks source link

eth_feeHistory returns "reward: null" which is not parseable by some JSON RPC clients #1106

Closed serejke closed 1 year ago

serejke commented 1 year ago

Contact Details

No response

Current Behavior

Problem

Axon node implements eth_feeHistory RPC endpoint but returns "reward": null field.

For example, given a curl:

curl -X POST --location "http://localhost:10002" \
    -H "Content-Type: application/json" \
    -d "{
          \"id\": 1,
          \"jsonrpc\": \"2.0\",
          \"method\": \"eth_feeHistory\",
          \"params\": [
            \"0x10\",
            \"latest\"
          ]
        }"

according to this line: https://github.com/axonweb3/axon/blob/d7d880082d05376b20ab84ad37e25626db44e132/core/api/src/jsonrpc/impl/web3.rs#L615

the response is:

{
  "jsonrpc": "2.0",
  "result": {
    "oldestBlock": "0x0",
    "reward": null,
    "baseFeePerGas": [],
    "gasUsedRatio": []
  },
  "id": 1
}

Some JSON RPC clients are not ready for null value and fail to parse the response.

For example, I use Foundry's cast send command to my local node:

cast send 0xdc796dfc1bb45f21d17be267877c3388d766937b --value 1234 --rpc-url http://localhost:10002 --private-key 0x37aa0f893d05914a4def0460c0a984d3611546cfb26924d7a7ca6e0db9950a2d

it fails with the following error:

Deserialization Error: invalid type: null, expected a sequence at line 1 column 34. Response: {"oldestBlock":"0x0","reward":null,"baseFeePerGas":[],"gasUsedRatio":[]}

Solution

Exclude null values from responses. The Ethereum RPC spec is not strict on the return results but I suppose null values should be ommitted.

Expected Behavior

Expected Behavior:

OS

MacOS

Axon version

No response

Kernel

MacOS

Relevant log output

No response

Anything else?

No response

KaoImin commented 1 year ago

Since the fee of Axon is fixed, Axon returns None currently. We will fix it soon. Thank you for your opinion.

serejke commented 1 year ago

@KaoImin any update on this issue? I checked on v0.1.0-alpha.8 and this still returns reward: null:

Given a POST request:

curl -X POST --location "http://localhost:65476" \
    -H "Content-Type: application/json" \
    -d "{
          \"id\": 1,
          \"jsonrpc\": \"2.0\",
          \"method\": \"eth_feeHistory\",
          \"params\": [\"0xa\", \"latest\", [5.0]]
        }"

the result is:

{
  "jsonrpc": "2.0",
  "result": {
    "oldestBlock": "0x0",
    "reward": null,
    "baseFeePerGas": [],
    "gasUsedRatio": []
  },
  "id": 1
}

this is a quite serious problem. Some clients (Hyperlane) rely on the fact that this method would throw an HTTP error instead of returning non-parseable JSON result.

github-actions[bot] commented 1 year ago

Hello @hongda3141. Please fix this bug.