Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Refactor and rename sandboxing implementation #10297

Closed
1 of 4 tasks
athei opened this issue Nov 17, 2021 · 12 comments
Closed
1 of 4 tasks

Refactor and rename sandboxing implementation #10297

athei opened this issue Nov 17, 2021 · 12 comments
Labels
I7-refactor Code needs refactoring. J1-meta A specific issue for grouping tasks or bugs of a specific category. U3-nice_to_have Issue is worth doing eventually. Z4-involved Can be fixed by an expert coder with good knowledge of the codebase.

Comments

@athei
Copy link
Member

athei commented Nov 17, 2021

The sandboxing code inside the client which is responsible for running the contracts of pallet-contracts needs a refactor. Currently, the different execution engines for contracts are crammed into sc-executor-common. Neither should different execution engines be in the same crate nor should runtime execution and sandbox execution be intertwined in this way. For that reason we want to refactor that code in order to have proper abstractions that allows us to move the sandboxing code to its own set of crates.

Rename

After a discussion with @pepyakin (see comments below) we agreed that we should also move away from the term "sandboxing" for this whole thing. One proposal what I also back is to use the terminology "Wasm Virtualization".

TODO

  • Separate wasmi and wasmer sandbox implementations into their own modules #10563
  • Create a trait to abstract over sandboxing execution engines ("backends").
  • Use dynamic dispatch with that trait to make engine selection possible at runtime (command line argument).
  • Move sandboxing code into its own crate client/wasm-virt with one additional crate per execution engine (sc-wasm-virt-wasmi, sc-wasm-virt-wasmer). This should also move all wasm virtualization related traits that needs to be implement by the runtime executor to the new location.
@athei athei added I7-refactor Code needs refactoring. U1-asap No need to stop dead in your tracks, however issue should be addressed as soon as possible. Z4-involved Can be fixed by an expert coder with good knowledge of the codebase. labels Nov 17, 2021
@0x7CFE
Copy link
Contributor

0x7CFE commented Nov 17, 2021

Another open question is whether we need to expand the API to allow for chunked execution so that code merkelization can be implemented. However, current thinking is that we can and should get away without execution engine support. I think it is reasonable to go forward with a non chunked version risking that we might need to maintain two APIs. Otherwise this is blocked by paritytech/polkadot-sdk#122.

I think, by carefully designing the API we can future-proof it to support potential chunked execution similar to what we have done for wasmi during our experiment.

@athei
Copy link
Member Author

athei commented Nov 17, 2021

Maybe. It adds complexity, though. For example, we would need some kind of feature discovery then because not all execution engines will support this right off the bat. As a matter of fact none will support it as we only put it in for future proofing. Just creating a new version of the API when the need arises is better in my opinion. Future proofing APIs is worth nothing when users will depend on the implementation.

@pepyakin
Copy link
Contributor

Excerpt from our discussion about changing the terminology from sandoxing to a term based on virtualization, e.g. wasm virtualization API, hypervisor API, or whatever.

Specifically, I think it is just too general and does not represent what it actually does. What is usually understood by sandbox? Well, it's when some code is put into an environment where it cannot reach to anything except things that was explicitly designated to be used by that sandboxed code.

If we agree on that definition, then the "runtime" is exactly that. The thing that executes "runtime" (which would be called runtime by normal people) can be also called a sandbox.

However, virtualization is really more appropriate term here I feel. This is because it fits really an analogy. Virtualization is where you have some medium that provides virtualization facilities, some hypervisor/supervisor that virtualizes or multiplexes the underlying hardware, emulating other and providing services, and the guest which consumes those services, who uses the hardware through the hypervisor, and ultimately is controlled by the hypervisor

@athei athei changed the title Redesign Sandboxing API Redesign and Rename Sandboxing API Nov 17, 2021
@athei athei changed the title Redesign and Rename Sandboxing API Redesign and Rename Sandboxing Infrastructure Nov 23, 2021
@athei
Copy link
Member Author

athei commented Nov 23, 2021

Updated the top post with new information after a discussion I had with @0x7CFE, today.

@athei
Copy link
Member Author

athei commented Dec 2, 2021

Refined the top posting again after the picture got a bit clearer on how the final refactoring should look like.

@athei athei changed the title Redesign and Rename Sandboxing Infrastructure Refactor and rename sandboxing implementation Jan 21, 2022
@athei athei added the J1-meta A specific issue for grouping tasks or bugs of a specific category. label Jan 21, 2022
@athei
Copy link
Member Author

athei commented Jan 21, 2022

I narrowed down the scope in this issue and created a proper task list.

@atenjin
Copy link
Contributor

atenjin commented Mar 30, 2022

hope polkadot parachain could use this feature soon... for now, parachain in polkadot even can not use sandbox hostfunction...
I think even though polkadot integrate sandbox hostfunction so that the parachain can use host_sandbox, the polkadot will not open the wasmer-sandbox feature...
I do not know how long should we wait for this feature.

@athei
Copy link
Member Author

athei commented Apr 1, 2022

What exactly do you need it for?

@atenjin
Copy link
Contributor

atenjin commented Apr 10, 2022

run a piece of wasm in runtime

@athei
Copy link
Member Author

athei commented Apr 12, 2022

You can still do that: Use sp_sandbox::embedded_executor. It doesn't rely on this interface but includes a wasmi into the runtime.

@athei athei unassigned 0x7CFE Jul 4, 2022
@athei
Copy link
Member Author

athei commented Jul 4, 2022

No one is working on this anymore.

@athei athei added U2-some_time_soon Issue is worth doing soon. U3-nice_to_have Issue is worth doing eventually. and removed U1-asap No need to stop dead in your tracks, however issue should be addressed as soon as possible. U2-some_time_soon Issue is worth doing soon. labels Jul 4, 2022
@athei
Copy link
Member Author

athei commented Jul 28, 2022

Since we decided to go with wasmi for now and we don't really have the resources to work on that we will close it.

@athei athei closed this as completed Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
I7-refactor Code needs refactoring. J1-meta A specific issue for grouping tasks or bugs of a specific category. U3-nice_to_have Issue is worth doing eventually. Z4-involved Can be fixed by an expert coder with good knowledge of the codebase.
Projects
Status: Done
Development

No branches or pull requests

4 participants