Skip to content

Commit

Permalink
wasm-executor: Support growing the memory (paritytech#12520)
Browse files Browse the repository at this point in the history
* As always, start with something :P

* Add support for max_heap_pages

* Add support for wasmtime

* Make it compile

* Fix compilation

* Copy wrongly merged code

* Fix compilation

* Some fixes

* Fix

* Get stuff working

* More work

* More fixes

* ...

* More

* FIXEs

* Switch wasmi to use `RuntimeBlob` like wasmtime

* Removed unused stuff

* Cleanup

* More cleanups

* Introduce `CallContext`

* Fixes

* More fixes

* Add builder for creating the `WasmExecutor`

* Adds some docs

* FMT

* First round of feedback.

* Review feedback round 2

* More fixes

* Fix try-runtime

* Update client/executor/wasmtime/src/instance_wrapper.rs

Co-authored-by: Koute <koute@users.noreply.github.com>

* Update client/executor/common/src/wasm_runtime.rs

Co-authored-by: Koute <koute@users.noreply.github.com>

* Update client/executor/common/src/runtime_blob/runtime_blob.rs

Co-authored-by: Koute <koute@users.noreply.github.com>

* Update client/executor/common/src/wasm_runtime.rs

Co-authored-by: Koute <koute@users.noreply.github.com>

* Update client/allocator/src/freeing_bump.rs

Co-authored-by: Koute <koute@users.noreply.github.com>

* Update client/allocator/src/freeing_bump.rs

Co-authored-by: Koute <koute@users.noreply.github.com>

* Feedback round 3

* FMT

* Review comments

---------

Co-authored-by: Koute <koute@users.noreply.github.com>
  • Loading branch information
2 people authored and ark0f committed Feb 27, 2023
1 parent 18ac78e commit 4ff2829
Show file tree
Hide file tree
Showing 37 changed files with 1,092 additions and 667 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 26 additions & 4 deletions bin/node/executor/benches/bench.rs
Expand Up @@ -31,7 +31,7 @@ use sc_executor::{
};
use sp_core::{
storage::well_known_keys,
traits::{CodeExecutor, RuntimeCode},
traits::{CallContext, CodeExecutor, RuntimeCode},
};
use sp_runtime::traits::BlakeTwo256;
use sp_state_machine::TestExternalities as CoreTestExternalities;
Expand Down Expand Up @@ -112,20 +112,41 @@ fn construct_block<E: Externalities>(

// execute the block to get the real header.
executor
.call(ext, &runtime_code, "Core_initialize_block", &header.encode(), true)
.call(
ext,
&runtime_code,
"Core_initialize_block",
&header.encode(),
true,
CallContext::Offchain,
)
.0
.unwrap();

for i in extrinsics.iter() {
executor
.call(ext, &runtime_code, "BlockBuilder_apply_extrinsic", &i.encode(), true)
.call(
ext,
&runtime_code,
"BlockBuilder_apply_extrinsic",
&i.encode(),
true,
CallContext::Offchain,
)
.0
.unwrap();
}

let header = Header::decode(
&mut &executor
.call(ext, &runtime_code, "BlockBuilder_finalize_block", &[0u8; 0], true)
.call(
ext,
&runtime_code,
"BlockBuilder_finalize_block",
&[0u8; 0],
true,
CallContext::Offchain,
)
.0
.unwrap()[..],
)
Expand Down Expand Up @@ -201,6 +222,7 @@ fn bench_execute_block(c: &mut Criterion) {
"Core_execute_block",
&block.0,
use_native,
CallContext::Offchain,
)
.0
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions bin/node/executor/tests/common.rs
Expand Up @@ -26,7 +26,7 @@ use sp_consensus_babe::{
use sp_core::{
crypto::KeyTypeId,
sr25519::Signature,
traits::{CodeExecutor, RuntimeCode},
traits::{CallContext, CodeExecutor, RuntimeCode},
};
use sp_runtime::{
traits::{BlakeTwo256, Header as HeaderT},
Expand Down Expand Up @@ -114,7 +114,7 @@ pub fn executor_call(
heap_pages: heap_pages.and_then(|hp| Decode::decode(&mut &hp[..]).ok()),
};
sp_tracing::try_init_simple();
executor().call(&mut t, &runtime_code, method, data, use_native)
executor().call(&mut t, &runtime_code, method, data, use_native, CallContext::Onchain)
}

pub fn new_test_ext(code: &[u8]) -> TestExternalities<BlakeTwo256> {
Expand Down
2 changes: 1 addition & 1 deletion client/allocator/src/error.rs
Expand Up @@ -16,7 +16,7 @@
// limitations under the License.

/// The error type used by the allocators.
#[derive(thiserror::Error, Debug)]
#[derive(thiserror::Error, Debug, PartialEq)]
pub enum Error {
/// Someone tried to allocate more memory than the allowed maximum per allocation.
#[error("Requested allocation size is too large")]
Expand Down

0 comments on commit 4ff2829

Please sign in to comment.