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

Introduce first groundwork for Wasm executor #27

Merged
merged 51 commits into from
Jan 8, 2018
Merged
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
4f5c5b6
Introduce first groundwork for Wasm executor.
gavofyork Dec 5, 2017
6237848
Remove old Rust-runtime code.
gavofyork Dec 6, 2017
293cf5d
Avoid commiting compled files.
gavofyork Dec 6, 2017
66b636e
Add runtime precompile.
gavofyork Dec 6, 2017
c7e7456
Rename so module makes more sense.
gavofyork Dec 6, 2017
0cfd67e
Further renaming.
gavofyork Dec 6, 2017
3011edf
Ensure tests work.
gavofyork Dec 6, 2017
a74b4fa
Allow bringing in of externalities.
gavofyork Dec 7, 2017
6dac275
Nice macros for imports.
gavofyork Dec 9, 2017
08f7b26
Allow passing in of data through allocators.
gavofyork Dec 11, 2017
1ace6b2
Can now pass in bytes to WasmExecutor.
gavofyork Dec 11, 2017
27e5fed
Additional cleanup.
gavofyork Dec 11, 2017
13dcd89
Switch usages of `OutData` to `u64`
gavofyork Dec 11, 2017
84b9f84
convert to safe but extremely verbose type conversion.
gavofyork Dec 11, 2017
7f31899
Remove StaticExternalities distinction.
gavofyork Dec 11, 2017
edf061e
Remove another unused use.
gavofyork Dec 11, 2017
edb6bea
Refactor wasm utils out
gavofyork Dec 11, 2017
9f59f48
Remove extraneous copies that weren't really testing anything.
gavofyork Dec 11, 2017
287b29d
Try to use wasm 0.15
gavofyork Dec 31, 2017
1bd55fe
Make it work!
gavofyork Dec 31, 2017
36e254a
Call-time externalities working.
gavofyork Jan 1, 2018
cd651a3
Add basic externalities.
gavofyork Jan 1, 2018
a8f9cca
Merge branch 'with-wasm-0.15' into with-wasm
gavofyork Jan 1, 2018
4404846
Fix grumbles and note unwraps to be sorted.
gavofyork Jan 1, 2018
b1d963a
Test storage externality.
gavofyork Jan 3, 2018
319d9c0
Fix nits.
gavofyork Jan 3, 2018
7ec9221
Merge branch 'master' into with-wasm
gavofyork Jan 3, 2018
2934d94
Compile collation logic.
gavofyork Jan 3, 2018
5998aa1
Move back to refs. Yey.
gavofyork Jan 3, 2018
3f4085a
Remove "object" id for storage access.
gavofyork Jan 4, 2018
4be0537
Fix test.
gavofyork Jan 4, 2018
01d7019
Fix up rest of tests.
gavofyork Jan 4, 2018
db1adee
remove unwrap.
gavofyork Jan 4, 2018
87c54f7
Expose set/get code in externalities
gavofyork Jan 5, 2018
471ea1e
Add validator set.
gavofyork Jan 5, 2018
fa35993
Introduce validator set into externalities and test.
gavofyork Jan 5, 2018
a0f64df
Add another external function.
gavofyork Jan 6, 2018
e736d46
Remove code and validators; use storage for everything.
gavofyork Jan 6, 2018
234297c
Introduce validators function.
gavofyork Jan 6, 2018
3f8a96d
Tests (and a fix) for the validators getter.
gavofyork Jan 6, 2018
6636520
Allow calls into runtime to return data.
gavofyork Jan 7, 2018
964659e
Remove unneeded trace.
gavofyork Jan 7, 2018
8ca1b7b
Make runtime printing a bit nicer.
gavofyork Jan 7, 2018
74156a2
Create separate runtimes for testing and polkadot.
gavofyork Jan 8, 2018
611a7ac
Remove commented code.
gavofyork Jan 8, 2018
c3afecc
Use new path.
gavofyork Jan 8, 2018
ea4d6c5
Refactor into shared support module.
gavofyork Jan 8, 2018
709693d
Fix warning.
gavofyork Jan 8, 2018
ec1e6b6
Remove unwraps.
gavofyork Jan 8, 2018
5c0ec3d
Make macro a little less unhygenic.
gavofyork Jan 8, 2018
79ab46f
Add wasm files.
gavofyork Jan 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Switch usages of OutData to u64
No need to be able to return bytes anymore.
  • Loading branch information
gavofyork committed Dec 11, 2017
commit 13dcd891d2f411d8e9cd827257ef360170b83926
4 changes: 2 additions & 2 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ extern crate error_chain;
pub mod error;

use primitives::{block, Address, H256};
use primitives::contract::{CallData, OutData, StorageKey, StorageData};
use primitives::contract::{CallData, StorageKey, StorageData};
use state_machine::backend::Backend;

use self::error::ResultExt;
@@ -80,7 +80,7 @@ impl<B, E> Client<B, E> where
}

/// Execute a call to a contract on top of state in a block of given hash.
pub fn call(&self, hash: &block::HeaderHash, method: &str, call_data: &CallData) -> error::Result<OutData> {
pub fn call(&self, hash: &block::HeaderHash, method: &str, call_data: &CallData) -> error::Result<u64> {
let state = self.state_at(hash)?;
let mut changes = state_machine::OverlayedChanges::default();

6 changes: 6 additions & 0 deletions executor/src/error.rs
Original file line number Diff line number Diff line change
@@ -43,6 +43,12 @@ error_chain! {
display("Externalities error: {}", e),
}

/// Invalid return type.
InvalidReturn {
description("u64 was not returned"),
display("Invalid type returned (should be u64)"),
}

/// Runtime failed.
Runtime {
description("runtime failure"),
14 changes: 6 additions & 8 deletions executor/src/wasm_executor.rs
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@

use parity_wasm;

use primitives::contract::{CallData, OutData};
use primitives::contract::CallData;
//use serializer::{from_slice as de, to_vec as ser};
use state_machine::{Externalities, CodeExecutor};

@@ -202,7 +202,7 @@ impl CodeExecutor for WasmExecutor {
ext: &mut E,
method: &str,
data: &CallData,
) -> Result<OutData> {
) -> Result<u64> {
// TODO: avoid copying code by requiring code to remain immutable through execution,
// splitting it off from potentially mutable externalities.
let code = match ext.code() {
@@ -212,7 +212,7 @@ impl CodeExecutor for WasmExecutor {

use parity_wasm::ModuleInstanceInterface;
use parity_wasm::interpreter::UserDefinedElements;
use parity_wasm::RuntimeValue::I32;
use parity_wasm::RuntimeValue::{I32, I64};
use std::collections::HashMap;

let fe_context = Arc::new(Mutex::new(None));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lots of lock().unwrap(); parking_lot mutexes don't poison

@@ -232,11 +232,8 @@ impl CodeExecutor for WasmExecutor {
module.memory(parity_wasm::interpreter::ItemIndex::Internal(0)).unwrap().set(offset, &data.0).unwrap();

module.execute_export(method, vec![I32(offset as i32), I32(size as i32)].into())
.map(|o| {
// TODO: populate vec properly
OutData(vec![1; if let Some(I32(l)) = o { l as usize } else { 0 }])
})
.map_err(|_| ErrorKind::Runtime.into())
.and_then(|i| if let Some(I64(r)) = i { Ok(r as u64) } else { Err(ErrorKind::InvalidReturn.into()) })
}
}

@@ -274,7 +271,8 @@ mod tests {
use std::result;
use std::sync::{Arc, Mutex};
use std::mem::transmute;
use parity_wasm::{MemoryInstance, ModuleInstanceInterface, UserDefinedElements};
use parity_wasm::{ModuleInstanceInterface};
use parity_wasm::interpreter::{MemoryInstance, UserDefinedElements};
use parity_wasm::RuntimeValue::{I32, I64};

// user function executor
6 changes: 3 additions & 3 deletions rpc/src/state/mod.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ mod tests;

use client::{self, Client};
use primitives::{block};
use primitives::contract::{CallData, OutData, StorageKey, StorageData};
use primitives::contract::{CallData, StorageKey, StorageData};
use state_machine;

use self::error::Result;
@@ -37,7 +37,7 @@ build_rpc_trait! {

/// Call a contract.
#[rpc(name = "state_call")]
fn call(&self, String, CallData, block::HeaderHash) -> Result<OutData>;
fn call(&self, String, CallData, block::HeaderHash) -> Result<u64>;
}
}

@@ -49,7 +49,7 @@ impl<B, E> StateApi for Client<B, E> where
Ok(self.storage(&block, object, &key)?)
}

fn call(&self, method: String, data: CallData, block: block::HeaderHash) -> Result<OutData> {
fn call(&self, method: String, data: CallData, block: block::HeaderHash) -> Result<u64> {
Ok(self.call(&block, &method, &data)?)
}
}
6 changes: 3 additions & 3 deletions state_machine/src/lib.rs
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ extern crate triehash;
use std::collections::HashMap;
use std::fmt;

use primitives::contract::{CallData, OutData};
use primitives::contract::{CallData};

pub mod backend;
mod ext;
@@ -199,7 +199,7 @@ pub trait CodeExecutor: Sized {
ext: &mut E,
method: &str,
data: &CallData,
) -> Result<OutData, Self::Error>;
) -> Result<u64, Self::Error>;
}

/// Execute a call using the given state backend, overlayed changes, and call executor.
@@ -211,7 +211,7 @@ pub fn execute<B: backend::Backend, Exec: CodeExecutor>(
exec: &Exec,
method: &str,
call_data: &CallData,
) -> Result<OutData, Box<Error>> {
) -> Result<u64, Box<Error>> {

let result = {
let mut externalities = ext::Ext {