AcalaNetwork / chopsticks

Create parallel reality of your Substrate network.
Apache License 2.0
133 stars 80 forks source link

`chain_getBlock` returns decoded `logs` but a real RPC returns it encoded #684

Closed fluiderson closed 6 months ago

fluiderson commented 6 months ago

Problem

I use Chopsticks with the subxt crate and get a error while it tries to decode a response from the chain_getBlock method. It fails on deserializing expecting a string where Chopsticks's response has a map. After looking into a difference between chain_getBlock responses from Chopsticks and a real RPC, I noticed that Chopsticks returns logs as an array of decoded maps where a real RPC returns it as an array of encoded strings.

For example, the following command

curl https://rpc.polkadot.io -H "Content-Type: application/json" \
    -d '{
        "method": "chain_getBlock",
        "params": ["0x8d9d76d520ead04eceff1f431436afa0cd9742495485c08a4ee453a80a7486b2"],
        "id": 1,
        "jsonrpc": "2.0"
    }'

returns

{
    "jsonrpc": "2.0",
    "result": {
        "block": {
            "header": {
                "parentHash": "0xacf842c1e28c0e3d7b9c90e2fbd3cb27ad299c4e4e03242cb3ad1cb2cc01fe75",
                "number": "0x12de80e",
                "stateRoot": "0xa613591b58431bbd22eeffacc54e8d67857d4bcda18eed257803e855b8c44148",
                "extrinsicsRoot": "0xad2ddae4abdf516bdd077a1cc8b7d1890dd643574eda6b1219f9a01a630175bf",
                "digest": {
                    "logs": [
                        "0x0642414245b501010c0000001722fc1000000000c6f3bcfa426f47345ad8795d2d3663e5b06304cbe104682d870b42754a93bb787b82b79ef51f5f2584f05a8f2934b352448f5c88b1ca871d89e827b4852bc008309afd8ba774f5d92b6094c4bf07b8a0283ffa8b9372cbd5c41d376bae0b910c",
                        "0x044245454684030d8b7d0a33c7199bf70ac9fc75d3ae36efaeae6abe85a615501ffaadf3bcd3c9",
                        "0x05424142450101726aa5d3f4132e4a60aba460e9960f8da72d7962db7b5e4b68b9f0505e8f940fab91aeee0f4a407b2c8e35a5e48035337ea5ad96d8d4fde24d7bbfaf2c576786"
                    ]
                }
            },
            "extrinsics": [...]
        },
        "justifications": null
    },
    "id": 1
}

And if Chopsticks is started by this command

npx @acala-network/chopsticks@latest -c polkadot

then a respective request

echo '{
    "method": "chain_getBlock",
    "params": ["0x8d9d76d520ead04eceff1f431436afa0cd9742495485c08a4ee453a80a7486b2"],
    "id": 1,
    "jsonrpc": "2.0"
}' | websocat -0 ws://localhost:8000

returns

{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "block": {
            "header": {
                "parentHash": "0xacf842c1e28c0e3d7b9c90e2fbd3cb27ad299c4e4e03242cb3ad1cb2cc01fe75",
                "number": "0x12de80e",
                "stateRoot": "0xa613591b58431bbd22eeffacc54e8d67857d4bcda18eed257803e855b8c44148",
                "extrinsicsRoot": "0xad2ddae4abdf516bdd077a1cc8b7d1890dd643574eda6b1219f9a01a630175bf",
                "digest": {
                    "logs": [
                        {
                            "preRuntime": [
                                "0x42414245",
                                "0x010c0000001722fc1000000000c6f3bcfa426f47345ad8795d2d3663e5b06304cbe104682d870b42754a93bb787b82b79ef51f5f2584f05a8f2934b352448f5c88b1ca871d89e827b4852bc008309afd8ba774f5d92b6094c4bf07b8a0283ffa8b9372cbd5c41d376bae0b910c"
                            ]
                        },
                        {
                            "consensus": [
                                "0x42454546",
                                "0x030d8b7d0a33c7199bf70ac9fc75d3ae36efaeae6abe85a615501ffaadf3bcd3c9"
                            ]
                        },
                        {
                            "seal": [
                                "0x42414245",
                                "0x726aa5d3f4132e4a60aba460e9960f8da72d7962db7b5e4b68b9f0505e8f940fab91aeee0f4a407b2c8e35a5e48035337ea5ad96d8d4fde24d7bbfaf2c576786"
                            ]
                        }
                    ]
                }
            },
            "extrinsics": [...]
        },
        "justifications": null
    }
}

Proposed solution

Make Chopsticks return encoded logs as a real RPC does.

ermalkaleci commented 6 months ago

Thank you for reporting. New version will be available soon