Skip to content
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

JSON-RPC endpoint does not accept []-enclosed requests #169

Closed
jsoares opened this issue Nov 3, 2023 · 5 comments · Fixed by consensus-shipyard/fendermint#395
Closed
Assignees
Labels
bug Something isn't working s:fendermint

Comments

@jsoares
Copy link
Contributor

jsoares commented Nov 3, 2023

Issue type

Bug

Have you reproduced the bug with the latest dev version?

Yes

Version

dev

Custom code

No

OS platform and distribution

No response

Describe the issue

While trying to deploy blockscout, I met the following error:

request:
backend                         | 
backend                         |     url: http://host.docker.internal:8545/
backend                         | 
backend                         |     body: [{"id":0,"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest",false]}]
backend                         | 
backend                         |   response:
backend                         | 
backend                         |     status code: 422
backend                         | 
backend                         |     body: Failed to deserialize the JSON body into the target type: [0]: invalid type: map, expected a borrowed string at line 1 column 1

This seems to be caused by those array brackets [ ] surrounding the body. Turns out that blockscout formats every request as batched, and we don't support it.

Without [ ]

ubuntu@ip-172-26-4-182:~/ipc$ curl http://localhost:8545/   -X POST   -H "Content-Type: application/json"   --data '{"method":"eth_getBlockByNumber","params":["latest",false],"id":1,"jsonrpc":"2.0"}' 
{"jsonrpc":"2.0","result":{"hash":"0x54a59570be03a907ffe81fc5cddb7a89baf9c4e8580d34df35ff3076eab54cb5","parentHash":"0xf69882a9edd08c04ee93864241599c8dcbe9dbad189a9c369891a18972112949","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","miner":"0x4a8066af00db95d7e2b0d8f20bc37de52d284882","stateRoot":"0xa175763416f64f25127e963ba6ad626a65718e4b11f6e33197e97c6b7ab7a0a5","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","number":"0x12c","gasUsed":"0x0","gasLimit":"0x0","extraData":"0x","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x6545427d","difficulty":"0x0","totalDifficulty":null,"sealFields":[],"uncles":[],"transactions":[],"size":"0x0","mixHash":null,"nonce":null,"baseFeePerGas":"0x3e8"},"id":1}

With [ ]

ubuntu@ip-172-26-4-182:~/ipc$ curl http://localhost:8545/   -X POST   -H "Content-Type: application/json"   --data '[{"method":"eth_getBlockByNumber","params":["latest",false],"id":1,"jsonrpc":"2.0"}]'
Failed to deserialize the JSON body into the target type: [0]: invalid type: map, expected a borrowed string at line 1 column 1

On the contrary, both work fine with public ethereum endpoints, e.g.

ubuntu@ip-172-26-4-182:~/ipc$ curl https://eth.public-rpc.com   -X POST   -H "Content-Type: application/json"   --data '{"method":"eth_getBlockByNumber","params":["latest",false],"id":1,"jsonrpc":"2.0"}' 
{"jsonrpc":"2.0","id":1,"result":{"baseFeePerGas":"0x4f46ceaab","difficulty":"0x0","extraData":"0x496c6c756d696e61746520446d6f63726174697a6520447374726962757465","gasLimit":"0x1c9c380","gasUsed":"0x10b5fd0","hash":"0xf6307927df417bcdd7ba260d8d24a10421d8d86a7c5456c3fc1e8db3a3d863ff","logsBloom":"0x4529822e697bd119750567eabca95aff33de58222e911f482acf0846644ae7be95d4559c218090e9539c79b5142e0b6e2a81e83c9ed07c84fe25c44a447ad8053cb29558016d6eb8387e738ab07611f651efa44daae53a8483226cea80f4224212702fc3bb731143c7cd50b148487a694238114510d83facdb0949791a4825d7da4ad4575a04846076dfa4560d201cef7010051de9d2b38ea835b8fac7f1d4608f374f071db8e5513f936fa4d9202e2a142dc58c7a16810e4ae5486391a7932520d80ed32e4342604a0fa4fe47de26e58be29103cd6595b43319715aedc5354ca17fb80f5aa020410a0f165818191d43737c12089d2a0d619061533030c63c14","miner":"0xdafea492d9c6733ae3d56b7ed1adb60692c98bc5","mixHash":"0xc632397c9c35fa65832c99aa1addefc060902827b2672c7430b1c7a07375bc57","nonce":"0x0000000000000000","number":"0x11a3164","parentHash":"0x420fa95c62d4aff62c9f6303df8b5bc0d049bce1a6db0e52bcb9212f0741e75c","receiptsRoot":"0x45929f10063f3d61910073c0e89fe92e1daae09542d273666c0952af57126563","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x16343","stateRoot":"0x71105e13a224a9925eeaf948702627057af0b15dc876c966cbaed4a1fbee9d7b","timestamp":"0x65455247","totalDifficulty":"0xc70d815d562d3cfa955","transactions": ...
...
ubuntu@ip-172-26-4-182:~/ipc$ curl https://eth.public-rpc.com   -X POST   -H "Content-Type: application/json"   --data '[{"method":"eth_getBlockByNumber","params":["latest",false],"id":1,"jsonrpc":"2.0"}]' 
[{"jsonrpc":"2.0","id":1,"result":{"baseFeePerGas":"0x5145110a4","difficulty":"0x0","extraData":"0x496c6c756d696e61746520446d6f63726174697a6520447374726962757465","gasLimit":"0x1c9c380","gasUsed":"0xe41009","hash":"0x8ece208e6a923d1795e47b075e3f5dbca9ac08f1b16275c9326995b836541069","logsBloom":"0xe52d84025c8a70d8d2eda784c805506041d352404b839af978d9018a40b3488ac9cf3d1003010315c05933249103078b73210111bb443e0613c49318bc6c20385767b02849a00839184bf22d0c1500b2924154cd0aec0f106507c640a57d3349734215014b12190128aedc2a499cfce96eb00e6319c846c9160d10b6d80a2440ac20865c9f0409e106c580410bb089323e15f029ef05a30a6b2776f3847294908b8d814e352121450309cae1fba8542444fcc638e08761a20a05825b20f70235808a9b724e1064440052924a026da86308bea41042196278846a758b19fcf3cca07ca48ed914b1455084849455291070d52870d8c3bb93482a413c707bd1d509","miner":"0xdafea492d9c6733ae3d56b7ed1adb60692c98bc5","mixHash":"0x9aec5613084c02be7f9210e0ad3aa17f1b17e1437584c90cf2ed27539012de1a","nonce":"0x0000000000000000","number":"0x11a3169","parentHash":"0x6888961f7eb5077d5d45923dc33cd36cab036ab418622460a46d3500e2be25e8","receiptsRoot":"0x0e5bf192204a4b08e2e99f347b70710a92834f52c07ecab335275b0eee0d6321","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x575ca","stateRoot":"0x4a8bdfee493dc45bed7527bb48874625d85b16158dbd84cefb8c80a822fc7810","timestamp":"0x65455283","totalDifficulty":"0xc70d815d562d3cfa955","transactions": ...

This may break compatibility with other ethereum tooling.

Repro steps

Run curl above against a fendermint eth rpc.

Relevant log output

No response

@jsoares jsoares added the bug Something isn't working label Nov 3, 2023
@jsoares jsoares changed the title JSON-RPC endpoint does not accept map-formatted requests JSON-RPC endpoint does not accept []-enclosed requests Nov 3, 2023
@jsoares jsoares transferred this issue from consensus-shipyard/ipc-libs Nov 3, 2023
@raulk
Copy link
Contributor

raulk commented Nov 3, 2023

Lotus does not support batched requests either -- but they have less need to because the Filecoin network has other explorers, and this isn't a popular feature in general (esp. when both the client and server support WebSockets as a transport). However, it should be easy to implement here. Ideally we'd want to handle individual requests in parallel, with some limit to prevent attacks.

@jsoares
Copy link
Contributor Author

jsoares commented Nov 3, 2023

@raulk We already have a fix in consensus-shipyard/fendermint#395.

Fwiw, this is not even a batched request; it's just formatted as such. It might be enough to accept said formatting, but we'll see what other surprises blockscout has in store (inc. actual batched requests, maybe).

@raulk
Copy link
Contributor

raulk commented Nov 3, 2023

@jsoares I'd expect to find multiple requests when loading listing and detail pages, or when indexing blocks and transactions. I suspect the explorer became blocked here and we didn't get to see further, more elaborate requests.

@jsoares
Copy link
Contributor Author

jsoares commented Nov 4, 2023

Indeed, that's what I expect too. That and tracing...

@jsoares
Copy link
Contributor Author

jsoares commented Nov 6, 2023

The fix works and allows for batch requests. New issues in #168.

@jsoares jsoares transferred this issue from consensus-shipyard/fendermint Dec 19, 2023
@jsoares jsoares closed this as not planned Won't fix, can't repro, duplicate, stale Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working s:fendermint
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants