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

WasmEdge for Substrate milestones #1 and #2 #547

Merged
merged 2 commits into from
Sep 19, 2022
Merged

WasmEdge for Substrate milestones #1 and #2 #547

merged 2 commits into from
Sep 19, 2022

Conversation

juntao
Copy link
Contributor

@juntao juntao commented Aug 23, 2022

Milestone Delivery Checklist

Link to the application pull request: w3f/Grants-Program#862

juntao added 2 commits August 23, 2022 23:39
Signed-off-by: Michael Yuan <michael@michaelyuan.com>
Signed-off-by: Michael Yuan <michael@michaelyuan.com>
@alxs alxs self-assigned this Aug 24, 2022
@alxs
Copy link
Contributor

alxs commented Aug 24, 2022

HI @juntao. Thank you for filling out the delivery files. I will be taking over your delivery.

Regarding the upstream PR, please submit an amendment to your application to move the deliverable to milestone 3 and any other changes, and feel free to adjust the cost to reflect the changes.

And regarding the article, could you write a short piece talking about e.g. your experience working on this, current limitations and/or benefits? You can send a draft to grantsPR@web3.foundation for proofreading before you publish it and cross-promotion.

@juntao
Copy link
Contributor Author

juntao commented Aug 26, 2022

I proposed an amendment and emailed an article draft to the grantsPR email address for approval. Thank you.

w3f/Grants-Program#1146

@alxs
Copy link
Contributor

alxs commented Aug 26, 2022

Many thanks. Is there any way to check the diff for the changes you made to Substrate, as well as for WasmEdge and the node template? Currently, this is very hard to see since it looks like you added the Substrate folder to the repository with your work already merged. Why did you choose to use a monorepo instead of working on forks to more easily be able to merge upstream?

@juntao
Copy link
Contributor Author

juntao commented Aug 26, 2022

Hi @alxs

The WasmEdge and node template subtrees are both in sync with the official repos.

The substrate subtree contains an additional executor/wasmedge directory. Most of our changes to Substrate are contained in that directory.

https://github.com/second-state/substrate-wasmedge/tree/main/substrate/client/executor/wasmedge

The reason for the monorepo is that we need to make changes to both the WasmEdge and substrate projects at the same time. It is easier to have everything together when we are experimenting on both sides. Most of the changes we made to WasmEdge have already been merged upstream.

@alxs alxs added the on hold label Aug 29, 2022
@alxs
Copy link
Contributor

alxs commented Aug 29, 2022

I see, thanks. Please note that this also means you can't license your entire repository as Apache 2.0, since parts of Substrate are GPLv3. I think the proper way of doing this would be to include both licenses in the project root as Substrate does.

Also, while being able to run the node template is already great, I wanted to see if the tests would pass too with cargo test --release -- --wasm-execution=compiledWasmedge and got the following error:

error[E0004]: non-exhaustive patterns: `CompiledWasmedge` not covered
   --> client/cli/src/arg_enums.rs:122:8
    |
122 |     match execution_method {
    |           ^^^^^^^^^^^^^^^^ pattern `CompiledWasmedge` not covered
    |
note: `arg_enums::WasmExecutionMethod` defined here
   --> client/cli/src/arg_enums.rs:61:2
    |
55  | pub enum WasmExecutionMethod {
    |          -------------------
...
61  |     CompiledWasmedge,
    |     ^^^^^^^^^^^^^^^^ not covered
    = note: the matched value is of type `arg_enums::WasmExecutionMethod`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
    |
144 ~         ),
145 ~         #[cfg(feature = "wasmtime")]
146 ~         WasmExecutionMethod::Compiled => sc_service::config::WasmExecutionMethod::Compiled {
147 ~             instantiation_strategy: match _instantiation_strategy {
148 ~                 WasmtimeInstantiationStrategy::PoolingCopyOnWrite =>
149 ~                     sc_service::config::WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
150 ~                 WasmtimeInstantiationStrategy::RecreateInstanceCopyOnWrite =>
151 ~                     sc_service::config::WasmtimeInstantiationStrategy::RecreateInstanceCopyOnWrite,
152 ~                 WasmtimeInstantiationStrategy::Pooling =>
153 ~                     sc_service::config::WasmtimeInstantiationStrategy::Pooling,
154 ~                 WasmtimeInstantiationStrategy::RecreateInstance =>
155 ~                     sc_service::config::WasmtimeInstantiationStrategy::RecreateInstance,
156 ~                 WasmtimeInstantiationStrategy::LegacyInstanceReuse =>
157 ~                     sc_service::config::WasmtimeInstantiationStrategy::LegacyInstanceReuse,
158 ~             },
159 ~         },
160 ~         #[cfg(feature = "wasmedge")]
161 ~         WasmExecutionMethod::CompiledWasmedge => sc_service::config::WasmExecutionMethod::CompiledWasmedge,
162 ~         #[cfg(not(feature = "wasmtime"))]
163 ~         CompiledWasmedge => todo!(),
    |

For more information about this error, try `rustc --explain E0004`.
error: could not compile `sc-cli` due to previous error

Could you please look into this?

@juntao
Copy link
Contributor Author

juntao commented Sep 3, 2022

@alxs Please try again. It should work now. My apologies for the confusion. We have just released WasmEdge 0.11 and its corresponding Rust binding SDK. The new release contains some changes we needed for Substrate support. We have updated the substrate-wasmedge repo to incorporate those updates.

@juntao
Copy link
Contributor Author

juntao commented Sep 5, 2022

I also fixed the license issue. Thanks.

@alxs
Copy link
Contributor

alxs commented Sep 5, 2022

@juntao that's great, thank you. Could you let me know what command you used to run the tests with WasmEdge? I'm not sure I was doing it correctly, as the command I shared earlier doesn't seem to actually run them. Feel free to add the instructions to the repo.

@juntao
Copy link
Contributor Author

juntao commented Sep 5, 2022

Hi @alxs

I use the following command to run the tests. Let me know if it works for you. Thanks.

cd substrate/client/executor
cargo t --features wasmedge

@alxs
Copy link
Contributor

alxs commented Sep 5, 2022

Thanks a lot. Many of these actually failed for me. I reinstalled WasmEdge and ran the tests as you described. Here's the output - please let me know if you need anything else.

@EmisonLu
Copy link

EmisonLu commented Sep 6, 2022

Hi @alxs ! Try the following command. Thanks!

export MAX_HOST_FUNC_LENGTH=1800

cd substrate/client/executor
cargo t --features=wasmedge

I have updated the code. Running tests based on the latest code does not require setting export MAX_HOST_FUNC_LENGTH=1800. Sorry for any confusion this may have caused!

@alxs
Copy link
Contributor

alxs commented Sep 6, 2022

No worries and thanks a lot. The tests seem to pass, but I see several "instruction unreachable" errors in the output. Can you reproduce this?

running 104 tests
test integration_tests::memory_is_cleared_between_invocations_compiled_wasmedge ... ok
test integration_tests::memory_is_cleared_between_invocations_interpreted ... ok
[2022-09-06 10:30:12.966] [error] execution failed: unreachable, Code: 0x89
[2022-09-06 10:30:12.966] [error]     In instruction: unreachable (0x00) , Bytecode offset: 0x00017741
test integration_tests::abort_on_panic_compiled_wasmedge ... ok
test integration_tests::offchain_index_interpreted ... ok
test integration_tests::offchain_http_should_work_interpreted ... ok
test integration_tests::return_i8_interpreted ... ok
test integration_tests::clear_prefix_should_work_compiled_wasmedge ... ok
test integration_tests::offchain_index_compiled_wasmedge ... ok
test integration_tests::abort_on_panic_interpreted ... ok
test integration_tests::offchain_local_storage_should_work_interpreted ... ok
test integration_tests::heap_is_reset_between_calls_interpreted ... ok
test integration_tests::call_not_existing_function_interpreted ... ok
test integration_tests::clear_prefix_should_work_interpreted ... ok
test integration_tests::ordered_trie_root_should_work_interpreted ... ok
test integration_tests::call_yet_another_not_existing_function_interpreted ... ok
[2022-09-06 10:30:13.085] [error] user defined failed: user defined error code, Code: 0x01
test integration_tests::call_yet_another_not_existing_function_compiled_wasmedge ... ok
test integration_tests::ordered_trie_root_should_work_compiled_wasmedge ... ok
[2022-09-06 10:30:13.119] [error] user defined failed: user defined error code, Code: 0x01
test integration_tests::call_not_existing_function_compiled_wasmedge ... ok
test integration_tests::offchain_local_storage_should_work_compiled_wasmedge ... ok
test integration_tests::offchain_http_should_work_compiled_wasmedge ... ok
test integration_tests::restoration_of_globals_interpreted ... ok
test integration_tests::ed25519_verify_should_work_interpreted ... ok
test integration_tests::parallel_execution_interpreted ... ok
[2022-09-06 10:30:13.145] [error] execution failed: unreachable, Code: 0x89
[2022-09-06 10:30:13.145] [error]     In instruction: unreachable (0x00) , Bytecode offset: 0x00026ac4
test integration_tests::return_i8_compiled_wasmedge ... ok
[2022-09-06 10:30:13.193] [error] execution failed: unreachable, Code: 0x89
[2022-09-06 10:30:13.193] [error]     In instruction: unreachable (0x00) , Bytecode offset: 0x00026ac3
test integration_tests::parallel_execution_compiled_wasmedge ... ok
test integration_tests::ed25519_verify_should_work_compiled_wasmedge ... ok
test integration_tests::blake2_128_should_work_interpreted ... ok
test integration_tests::returning_should_work_interpreted ... ok
test integration_tests::returning_should_work_compiled_wasmedge ... ok
test integration_tests::returns_mutable_static_compiled_wasmedge ... ok
test integration_tests::sandbox::get_global_val_works_interpreted_embedded_executor ... ok
test integration_tests::sandbox::return_val_interpreted_embedded_executor ... ok
test integration_tests::sandbox::get_global_val_works_interpreted_host_executor ... ok
test integration_tests::blake2_256_should_work_interpreted ... ok
test integration_tests::sandbox::corrupted_module_wasmedge_host_executor ... ok
test integration_tests::returns_mutable_static_interpreted ... ok
test integration_tests::returns_mutable_static_bss_interpreted ... ok
test integration_tests::panicking_should_work_interpreted ... ok
test integration_tests::sandbox::invoke_args_wasmedge_host_executor ... ok
test integration_tests::sandbox::corrupted_module_interpreted_embedded_executor ... ok
test integration_tests::sandbox::return_val_interpreted_host_executor ... ok
test integration_tests::sandbox::corrupted_module_wasmedge_embedded_executor ... ok
test integration_tests::sandbox::invoke_args_interpreted_embedded_executor ... ok
test integration_tests::sandbox::get_global_val_works_wasmedge_embedded_executor ... ok
test integration_tests::sandbox::invoke_args_interpreted_host_executor ... ok
test integration_tests::sandbox::corrupted_module_interpreted_host_executor ... ok
test integration_tests::blake2_128_should_work_compiled_wasmedge ... ok
test integration_tests::sandbox::get_global_val_works_wasmedge_host_executor ... ok
test integration_tests::blake2_256_should_work_compiled_wasmedge ... ok
test integration_tests::returns_mutable_static_bss_compiled_wasmedge ... ok
test integration_tests::restoration_of_globals_compiled_wasmedge ... ok
test integration_tests::sandbox::return_val_wasmedge_host_executor ... ok
test integration_tests::sandbox::start_called_wasmedge_host_executor ... ok
test integration_tests::sandbox::sandbox_should_work_interpreted_embedded_executor ... ok
test integration_tests::sandbox::return_val_wasmedge_embedded_executor ... ok
test integration_tests::sandbox::sandbox_should_work_interpreted_host_executor ... ok
test integration_tests::sandbox::invoke_args_wasmedge_embedded_executor ... ok
[2022-09-06 10:30:13.557] [error] execution failed: unreachable, Code: 0x89
[2022-09-06 10:30:13.557] [error]     In instruction: unreachable (0x00) , Bytecode offset: 0x00026ac4
test integration_tests::panicking_should_work_compiled_wasmedge ... ok
[2022-09-06 10:30:13.565] [error] user defined failed: user defined error code, Code: 0x02
test integration_tests::sandbox::sandbox_should_work_wasmedge_embedded_executor ... ok
test integration_tests::should_trap_when_heap_exhausted_compiled_wasmedge ... ok
test integration_tests::sandbox::sandbox_should_work_wasmedge_host_executor ... ok
test integration_tests::sandbox::sandbox_trap_interpreted_embedded_executor ... ok
test integration_tests::storage_should_work_compiled_wasmedge ... ok
test integration_tests::take_i8_compiled_wasmedge ... ok
test integration_tests::sandbox::start_called_interpreted_host_executor ... ok
test integration_tests::sandbox::start_fn_traps_interpreted_host_executor ... ok
test native_executor::tests::native_executor_registers_custom_interface ... ok
test integration_tests::sandbox::sandbox_trap_interpreted_host_executor ... ok
test integration_tests::sandbox::start_fn_ok_interpreted_embedded_executor ... ok
test wasm_runtime::tests::host_functions_are_equal ... ok
test wasm_runtime::tests::new_runtime_version_decodes ... ok
test wasm_runtime::tests::old_runtime_version_decodes ... ok
test wasm_runtime::tests::old_runtime_version_decodes_fails_with_version_3 ... ok
test integration_tests::sandbox::sandbox_trap_wasmedge_embedded_executor ... ok
test integration_tests::sandbox::start_fn_traps_interpreted_embedded_executor ... ok
test integration_tests::sandbox::start_fn_ok_interpreted_host_executor ... ok
test integration_tests::sandbox::sandbox_trap_wasmedge_host_executor ... ok
test integration_tests::sandbox::start_called_interpreted_embedded_executor ... ok
test integration_tests::sandbox::unlinkable_module_interpreted_host_executor ... ok
test integration_tests::sandbox::start_fn_ok_wasmedge_host_executor ... ok
test integration_tests::sandbox::unlinkable_module_interpreted_embedded_executor ... ok
test integration_tests::sandbox::start_fn_ok_wasmedge_embedded_executor ... ok
test integration_tests::sandbox::start_fn_traps_wasmedge_host_executor ... ok
test integration_tests::should_trap_when_heap_exhausted_interpreted ... ok
test integration_tests::sandbox::unlinkable_module_wasmedge_embedded_executor ... ok
test integration_tests::sandbox::unlinkable_module_wasmedge_host_executor ... ok
test integration_tests::storage_should_work_interpreted ... ok
test integration_tests::take_i8_interpreted ... ok
test integration_tests::sr25519_verify_should_work_interpreted ... ok
test integration_tests::sandbox::start_fn_traps_wasmedge_embedded_executor ... ok
[2022-09-06 10:30:13.764] [error] execution failed: unreachable, Code: 0x89
[2022-09-06 10:30:13.764] [error]     In instruction: unreachable (0x00) , Bytecode offset: 0x00017746
test integration_tests::unreachable_intrinsic_compiled_wasmedge ... ok
test integration_tests::sandbox::start_called_wasmedge_embedded_executor ... ok
test tests::call_in_interpreted_wasm_works ... ok
test integration_tests::unreachable_intrinsic_interpreted ... ok
test integration_tests::sha2_256_should_work_compiled_wasmedge ... ok
test integration_tests::twox_256_should_work_interpreted ... ok
test integration_tests::sr25519_verify_should_work_compiled_wasmedge ... ok
test integration_tests::sha2_256_should_work_interpreted ... ok
test integration_tests::twox_128_should_work_compiled_wasmedge ... ok
test wasm_runtime::tests::embed_runtime_version_works ... ok
test integration_tests::twox_128_should_work_interpreted ... ok
test integration_tests::twox_256_should_work_compiled_wasmedge ... ok
test integration_tests::wasm_tracing_should_work_compiled_wasmedge ... ok
test integration_tests::wasm_tracing_should_work_interpreted ... ok

test result: ok. 104 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.34s

@EmisonLu
Copy link

EmisonLu commented Sep 6, 2022

These error messages are logs printed by the WasmEdge runtime core (written in C). Some tests are used to verify error handling, so it is fine to see error logs printed by the runtime core during the test.

@alxs alxs removed the on hold label Sep 19, 2022
@alxs
Copy link
Contributor

alxs commented Sep 19, 2022

Hi @EmisonLu. Apologies for the delay. Your amendment has now been approved, so I'm happy to confirm that the delivery is accepted. You can find my evaluation notes here and here.

I'll notify the finance team to pay out your invoice. Please allow for up to 2 weeks of processing time.

@alxs alxs merged commit 81b6960 into w3f:master Sep 19, 2022
@github-actions
Copy link

Congratulations on completing the first milestone of this grant! As part of the Grants Program, we want to help grant recipients acknowledge their grants publicly. To that end, we’ve created a badge for projects that successfully deliver their first milestone. Note that it must only be used within the context of the delivered work, so please do not display it on your team or project's homepage unless accompanied by a short description of the grant.

Furthermore, you're now welcome to announce the grant publicly. Please remember to observe the foundation’s guidelines in doing so. In case you haven't done so yet, you may also reach out to grantsPR@web3.foundation for feedback on your announcement and cross-promotion.

Thank you for your contribution and good luck with the remaining milestones, if any! As usual, please let us know if you run into any delays by leaving a comment on the application PR, or directly submitting an amendment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants