AcalaNetwork / chopsticks

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

Getting RuntimeVersionDecode error when testing with the md5 rococo parachain #663

Closed sebastianmontero closed 5 months ago

sebastianmontero commented 8 months ago

I'm trying to test for the md5 rococo parachain but I get the following error:

called `Result::unwrap()` on an `Err` value: RuntimeVersion(RuntimeVersionDecode)

Stack:

Error
    at imports.wbg.__wbg_new_abda76e883ba8a5f (/home/sebastian/.npm/_npx/84d26c864c64a94e/node_modules/@acala-network/chopsticks-executor/dist/cjs/chopsticks_executor.js:748:19)
    at wasm://wasm/00966b66:wasm-function[701]:0x1269bf
    at wasm://wasm/00966b66:wasm-function[866]:0x130a13
    at wasm://wasm/00966b66:wasm-function[795]:0x12b783
    at wasm://wasm/00966b66:wasm-function[105]:0xa7664
    at wasm://wasm/00966b66:wasm-function[380]:0x10eb7c
    at wasm://wasm/00966b66:wasm-function[917]:0x1312f9
    at __wbg_adapter_48 (/home/sebastian/.npm/_npx/84d26c864c64a94e/node_modules/@acala-network/chopsticks-executor/dist/cjs/chopsticks_executor.js:410:10)
    at real (/home/sebastian/.npm/_npx/84d26c864c64a94e/node_modules/@acala-network/chopsticks-executor/dist/cjs/chopsticks_executor.js:394:22)
    at node:internal/process/task_queues:140:7

node:internal/event_target:1010
  process.nextTick(() => { throw err; });
                           ^
Error [RuntimeError]: unreachable
    at wasm://wasm/00966b66:wasm-function[701]:0x126ad5
    at wasm://wasm/00966b66:wasm-function[866]:0x130a13
    at wasm://wasm/00966b66:wasm-function[795]:0x12b783
    at wasm://wasm/00966b66:wasm-function[105]:0xa7664
    at wasm://wasm/00966b66:wasm-function[380]:0x10eb7c
    at wasm://wasm/00966b66:wasm-function[917]:0x1312f9
    at __wbg_adapter_48 (/home/sebastian/.npm/_npx/84d26c864c64a94e/node_modules/@acala-network/chopsticks-executor/dist/cjs/chopsticks_executor.js:410:10)
    at real (/home/sebastian/.npm/_npx/84d26c864c64a94e/node_modules/@acala-network/chopsticks-executor/dist/cjs/chopsticks_executor.js:394:22)
    at node:internal/process/task_queues:140:7
    at AsyncResource.runInAsyncScope (node:async_hooks:204:9)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:290:10)
    at [kOnMessage] (node:internal/worker:301:37)
    at MessagePort.<anonymous> (node:internal/worker:202:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:735:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)

This is the config file I'm using:

endpoint: wss://c1md5.hashed.live
mock-signature-host: true
block: ${env.MD5_BLOCK_NUMBER}
db: ./md5.rococo.db.sqlite
# wasm-override: ../../ComposableFi/composable/result/lib/runtime.optimized.wasm

import-storage:
  Sudo:
    Key: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
  System:
    Account:
      -
        -
          - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
        - providers: 1
          data:
            free: "100000000000000000000000"

Why might this be?

ermalkaleci commented 8 months ago

can read runtime version from runtime.wasm. you need to use compressed one

sebastianmontero commented 8 months ago

@ermalkaleci so do I need to use the wasm-override parameter?

ermalkaleci commented 8 months ago

yes

ermalkaleci commented 8 months ago

to be clear. I thought you're trying custom wasm runtime. are you trying to use chopsticks for wss://c1md5.hashed.live?

ermalkaleci commented 8 months ago

you have the same issue. https://github.com/AcalaNetwork/chopsticks/issues/564

sebastianmontero commented 8 months ago

Thanks @ermalkaleci! Yes for wss://c1md5.hashed.live, but md5 is using polkadot v1.3.0, from what I understand from the issue is that they are using an old version, correct?

ermalkaleci commented 8 months ago

yes, there're using old version but in your case it seems smoldot can find version from your wasm runtime

sebastianmontero commented 8 months ago

Ok, I'll try using the branch mentioned in the issue, thanks!

sebastianmontero commented 8 months ago

@ermalkaleci I'm getting this error when building the wasm on that branch:

error[E0432]: unresolved imports `smoldot::executor::runtime_host`, `smoldot::executor::runtime_host`, `smoldot::verify::body_only::LogEmitInfo`
  --> src/task.rs:7:9
   |
7  |         runtime_host::{self, OffchainContext, RuntimeHostVm},
   |         ^^^^^^^^^^^^   ^^^^ no `runtime_host` in `executor`
   |         |
   |         could not find `runtime_host` in `executor`
   |         help: a similar name exists in the module: `runtime_call`
...
17 |     verify::body_only::LogEmitInfo,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `LogEmitInfo` in `verify::body_only`
   |
   = help: consider importing this enum instead:
           smoldot::executor::runtime_call::LogEmitInfo

error[E0599]: no variant or associated item named `Oneshot` found for enum `ExecHint` in the current scope
   --> src/task.rs:409:53
    |
409 |         exec_hint: smoldot::executor::vm::ExecHint::Oneshot,
    |                                                     ^^^^^^^ variant or associated item not found in `ExecHint`

error[E0599]: no variant or associated item named `Oneshot` found for enum `ExecHint` in the current scope
   --> src/task.rs:130:53
    |
130 |         exec_hint: smoldot::executor::vm::ExecHint::Oneshot,
    |                                                     ^^^^^^^ variant or associated item not found in `ExecHint`

error[E0599]: no method named `iter` found for struct `EntryKeyIter` in the current scope
  --> src/proof.rs:66:37
   |
66 |             trie.node(entry_key.key.iter().map(|x| x.to_owned()))
   |                                     ^^^^ method not found in `EntryKeyIter<'_, Vec<u8>>`

Some errors have detailed explanations: E0432, E0599.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `chopsticks-executor` (lib) due to 4 previous errors
Error: Compiling your crate to WebAssembly failed
Caused by: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
  full command: cd "/home/sebastian/vsc-workspace/chopsticks/executor" && "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"

Do you know why this might be?

ermalkaleci commented 8 months ago

I started debugging smoldot to see if there was any problem and turns out the your problem is stateVersion: 5 the old version is 0 and new trie version is 1.

Screenshot 2024-01-30 at 11 39 26 PM
sebastianmontero commented 8 months ago

Thanks @ermalkaleci! Changing the stateVersion to 1, and overriding the wasm solved that issue. But now I'm getting the following error:

called `Result::unwrap()` on an `Err` value: VirtualMachine(UnresolvedFunctionImport { function: "ext_transaction_index_index_version_1", module_name: "env" })

Stack:

Error
    at imports.wbg.__wbg_new_abda76e883ba8a5f (/home/sebastian/.npm/_npx/84d26c864c64a94e/node_modules/@acala-network/chopsticks-executor/dist/cjs/chopsticks_executor.js:748:19)
    at wasm://wasm/00966b66:wasm-function[701]:0x1269bf
    at wasm://wasm/00966b66:wasm-function[866]:0x130a13
    at wasm://wasm/00966b66:wasm-function[795]:0x12b783
    at wasm://wasm/00966b66:wasm-function[105]:0xa7664
    at wasm://wasm/00966b66:wasm-function[380]:0x10eb7c
    at wasm://wasm/00966b66:wasm-function[917]:0x1312f9
    at __wbg_adapter_48 (/home/sebastian/.npm/_npx/84d26c864c64a94e/node_modules/@acala-network/chopsticks-executor/dist/cjs/chopsticks_executor.js:410:10)
    at real (/home/sebastian/.npm/_npx/84d26c864c64a94e/node_modules/@acala-network/chopsticks-executor/dist/cjs/chopsticks_executor.js:394:22)
    at node:internal/process/task_queues:140:7

node:internal/event_target:1010
  process.nextTick(() => { throw err; });
                           ^
Error [RuntimeError]: unreachable
    at wasm://wasm/00966b66:wasm-function[701]:0x126ad5
    at wasm://wasm/00966b66:wasm-function[866]:0x130a13
    at wasm://wasm/00966b66:wasm-function[795]:0x12b783
    at wasm://wasm/00966b66:wasm-function[105]:0xa7664
    at wasm://wasm/00966b66:wasm-function[380]:0x10eb7c
    at wasm://wasm/00966b66:wasm-function[917]:0x1312f9
    at __wbg_adapter_48 (/home/sebastian/.npm/_npx/84d26c864c64a94e/node_modules/@acala-network/chopsticks-executor/dist/cjs/chopsticks_executor.js:410:10)
    at real (/home/sebastian/.npm/_npx/84d26c864c64a94e/node_modules/@acala-network/chopsticks-executor/dist/cjs/chopsticks_executor.js:394:22)
    at node:internal/process/task_queues:140:7
    at AsyncResource.runInAsyncScope (node:async_hooks:204:9)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:290:10)
    at [kOnMessage] (node:internal/worker:301:37)
    at MessagePort.<anonymous> (node:internal/worker:202:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:735:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)
ermalkaleci commented 8 months ago

That means your runtime has methods unrecognized by smoldot. Try with allow-unresolved-imports: true

sebastianmontero commented 8 months ago

That worked, but I guess it won't work until I upgrade the on chain runtime with the correct state version, because now it runs, but when I go into polkadotjs app, it crashes and I get the RuntimeVersion(RuntimeVersionDecode) error, is this correct?

ermalkaleci commented 8 months ago

It should work with both wasm-override and allow-unresolved-imports.

sebastianmontero commented 8 months ago

It runs: image

But when I go to the polkadotjsapp it throws the error: image

ermalkaleci commented 8 months ago

how do you override wasm?

ermalkaleci commented 8 months ago

if you upload your custom wasm with correct trie version number I can give it a try

sebastianmontero commented 8 months ago

This is my config file:

endpoint: wss://c1md5.hashed.live
mock-signature-host: true
block: ${env.MD5_BLOCK_NUMBER}
db: ./md5.rococo.db.sqlite
allow-unresolved-imports: true
wasm-override: ../hashed-substrate-parachain/target/release/wbuild/hashed-parachain-runtime/hashed_parachain_runtime.compact.compressed.wasm

import-storage:
  Sudo:
    Key: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
  System:
    Account:
      -
        -
          - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
        - providers: 1
          data:
            free: "100000000000000000000000"

Here is the wasm Thanks!

ermalkaleci commented 8 months ago

ok the problem is this. we're overriding wasm and it works for that block but as soon at it loads parent, it will fail because trie is invalid

ermalkaleci commented 8 months ago

I did modify vendor/smoldot to parse your version 5 as 1 but it will end up calling unknown host function ext_transaction_index_index_version_1. This function is not implemented in smoldot

Screenshot 2024-01-31 at 5 35 46 PM
sebastianmontero commented 8 months ago

Thanks for looking into it @ermalkaleci! So for it to work I need to update the on chain runtime with the correct state version?

ermalkaleci commented 8 months ago

I think that won't be enough. Your runtime has a host function unimplemented in smoldot.

sebastianmontero commented 8 months ago

So I won't be able to use chopsticks? How can I know which is the function that is not implemented?

ermalkaleci commented 8 months ago

the unimplemented method is ext_transaction_index_index_version_1 which seems to be used by those 2 pallet https://github.com/search?q=repo%3Aparitytech%2Fpolkadot-sdk%20sp_io%3A%3Atransaction_index%3A%3Aindex&type=code

ermalkaleci commented 8 months ago

I added an empty implementation of ext_transaction_index_index_version_1 and it appears to work

Screenshot 2024-01-31 at 9 28 06 PM
ermalkaleci commented 8 months ago

https://github.com/smol-dot/smoldot/pull/1644

sebastianmontero commented 8 months ago

Great! Thanks! are you using the latest beta?

ermalkaleci commented 8 months ago

no, PR was rejected. we can't add the implementation to smoldot. If you wish you can fork and build your custom version with above implementation

sebastianmontero commented 7 months ago

@ermalkaleci thank you for all your help! I've forked the chopsticks repo and changed smoldot submodule to use the pr you created. But I still have the same issue, chopstick runs initially but when I go to the polkadotjs app it fails with the RuntimeVersionDecode error. Do I need to do anything else? image

ermalkaleci commented 7 months ago

I did modify vendor/smoldot to parse your version 5 as 1 but it will end up calling unknown host function ext_transaction_index_index_version_1. This function is not implemented in smoldot

Screenshot 2024-01-31 at 5 35 46 PM

You need this as well

sebastianmontero commented 7 months ago

Thanks @ermalkaleci! That worked!