tomusdrw / rust-web3

Ethereum JSON-RPC multi-transport client. Rust implementation of web3 library. ENS address: rust-web3.eth
MIT License
1.45k stars 471 forks source link

Decoding issue with failing transaction on ganache #563

Open palango opened 3 years ago

palango commented 3 years ago

I'm sending some transaction using Contract.signed_call_with_confirmations on a ganache test chain.

This transaction reverts, but web3 is unable to properly decode the error:

failed to deserialize response: data did not match any variant of untagged enum Output

This looks a bit like https://github.com/tomusdrw/rust-web3/issues/460 , but that has been fixed. Any hints?

Complete logs:


[2021-10-29T15:57:29Z DEBUG web3::transports::http] [id:4] sending request: "{\"jsonrpc\":\"2.0\",\"method\":\"eth_sendRawTransaction\",\"params\":[\"0xf9010e82010e8504a817c800830f424094e7f1725e7734ce288f8367e1bb143e90bb3f051280b8a40e0fe0eb00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001820a96a00f4f00811f42307ccb03b40c6e68de289ce3d95de4ef079061e69ba4eca3e676a01e1a9bdb4e25f1dcfda36cfa376eb6da9e10653df43e255a9f0f9f60251734d5\"],\"id\":4}"
[2021-10-29T15:57:29Z DEBUG reqwest::async_impl::client] response '200 OK' for http://127.0.0.1:8545/
[2021-10-29T15:57:29Z DEBUG web3::transports::http] [id:4] received response: "{\"id\":4,\"jsonrpc\":\"2.0\",\"result\":\"0x4b1a874402f1a69c819222bca5e0d5fc0da6290d42cbe11fe9b5c7aee194ccc2\",\"error\":{\"message\":\"VM Exception while processing transaction: revert\",\"code\":-32000,\"data\":{\"0x4b1a874402f1a69c819222bca5e0d5fc0da6290d42cbe11fe9b5c7aee194ccc2\":{\"error\":\"revert\",\"program_counter\":481,\"return\":\"0x\"},\"stack\":\"c: VM Exception while processing transaction: revert\\n    at Function.c.fromResults (/usr/local/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:4:192416)\\n    at w.processBlock (/usr/local/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:42:50915)\\n    at runMicrotasks (<anonymous>)\\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\",\"name\":\"c\"}}}"
got tx: Err(Transport("failed to deserialize response: data did not match any variant of untagged enum Output"))
tomusdrw commented 3 years ago

It's because Ganache sends a response which is not a valid JSON-RPC response, since it contains both result and error. It's a bit similar to https://github.com/tomusdrw/rust-web3/issues/544

The fix would need to be implemented in jsonrpc-core library. Or we could somehow try to override that in rust-web3 level. I'd prefer to stay strict in terms of spec-adherence, so maybe there is some way to workaround that by parsing to a custom Output first.

palango commented 3 years ago

Yes, I see your point. Feel free to close this issue then.