AcalaNetwork / chopsticks

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

Failing `dev_setStorage` #630

Closed NachoPal closed 8 months ago

NachoPal commented 8 months ago

After this commit: https://github.com/AcalaNetwork/chopsticks/commit/5c81c80e5c60bec090376cb53c58b2fa9f7570db dev_setStorage stopped working for me.

I have:

        await api.rpc('dev_setStorage', {
            preimage: {
                preimageFor: [
                    [
                        [[hashedCall, callLength]],
                        call
                    ]
                ]
            }
        })

I do not know if I have to do some modification to the arguments format.

ermalkaleci commented 8 months ago

can you post more details, keys, values? I can't tell what you need to modify

NachoPal commented 8 months ago

These are the logs:

[12:51:49.792] TRACE (ws/17807): Received single request
    app: "chopsticks"
    req: {
      "id": 13,
      "jsonrpc": "2.0",
      "method": "dev_setStorage",
      "params": [
        {
          "preimage": {
            "preimageFor": [
              [
                [
                  [
                    "0x4677e43381a888a45e7c72497a2e0c93f39d1805b72f70b14e32fa35a48af8b4",
                    11
                  ]
                ],
                "0x6304000100a10f03000000"
              ]
            ]
          }
        }
      ]
    }
[12:51:49.792] TRACE (ws/17807): Received message
    app: "chopsticks"
    id: 13
    method: "dev_setStorage"
[12:51:49.792] TRACE (17807): Handling dev_setStorage
    app: "chopsticks"
    module: "rpc"
[12:51:49.793] DEBUG (plugin/17807): Registered plugin set-storage RPC
    app: "chopsticks"
[12:51:49.794] DEBUG (17807): dev_setStorage
    app: "chopsticks"
    hash: "0x65f3279eb676bb6c73f67575e7477cbd6d78654b8df04d4ebadf785837304ec0"
    values: {
      "preimage": {
        "preimageFor": [
          [
            [
              [
                "0x4677e43381a888a45e7c72497a2e0c93f39d1805b72f70b14e32fa35a48af8b4",
                11
              ]
            ],
            "0x6304000100a10f03000000"
          ]
        ]
      }
    }
[12:51:49.794] TRACE (ws/17807): Response for request
    app: "chopsticks"
    id: 13
    method: "dev_setStorage"
    result: "0x65f3279eb676bb6c73f67575e7477cbd6d78654b8df04d4ebadf785837304ec0"

As result of the dev_setStorage call, preimage.preimageFor database key gets corrupted. It used to work. As I mentioned before, I think the change was introduced by https://github.com/AcalaNetwork/chopsticks/commit/5c81c80e5c60bec090376cb53c58b2fa9f7570db

ermalkaleci commented 8 months ago

We did some changes how encode/decode import storage #606. Now hex storage value is imported as is. So make sure your hex doesn't have length. Somewhere you convert this call into hex, make sure you use u8aToHex(call.toU8a()), it will give you the call itself with encoding length

ermalkaleci commented 8 months ago

is this polkadot?

ermalkaleci commented 8 months ago

ok seems like in this case value is Option and it requires length. Your hex only have the call, you need to append length (use compactAddLength) or pass the call as json instead of hex

NachoPal commented 8 months ago

It worked, I had to do: u8aToHex(compactAddLength(hexToU8a(call)))

Thanks for the support.