Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
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
Create separate runtimes for testing and polkadot.
  • Loading branch information
gavofyork committed Jan 8, 2018
commit 74156a2dca94cbd56b56ef01dd4343dfb875b62b
2 changes: 1 addition & 1 deletion executor/src/wasm_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ mod tests {
let offset = fec.heap.allocate(size);
memory.set(offset, data).unwrap();

let returned = module.execute_export("exec_test_data_in",
let returned = module.execute_export("test_data_in",
program.params_with_external("env", &mut fec)
.add_argument(I32(offset as i32))
.add_argument(I32(size as i32))
Expand Down
10 changes: 9 additions & 1 deletion runtime/Cargo.lock

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

16 changes: 5 additions & 11 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
[package]
name = "runtime"
version = "0.1.0"
authors = ["Parity Technologies <[email protected]>"]

[lib]
crate-type = ["cdylib"]

[dependencies]
pwasm-libc = { path = "./pwasm-libc", version = "0.1" }
pwasm-alloc = { path = "./pwasm-alloc", version = "0.1" }
[workspace]
members = [
"test",
"polkadot",
]

[profile.release]
panic = "abort"
9 changes: 8 additions & 1 deletion runtime/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/bin/sh

cargo +nightly build --target=wasm32-unknown-unknown --release
wasm-gc target/wasm32-unknown-unknown/release/runtime.wasm target/wasm32-unknown-unknown/release/runtime.compact.wasm
dirs=`find * -maxdepth 0 -type d | grep -v pwasm-`
for i in $dirs
do
if [[ -e $i/Cargo.toml ]]
then
wasm-gc target/wasm32-unknown-unknown/release/runtime_$i.wasm target/wasm32-unknown-unknown/release/runtime_$i.compact.wasm
fi
done
11 changes: 11 additions & 0 deletions runtime/polkadot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "runtime-polkadot"
version = "0.1.0"
authors = ["Parity Technologies <[email protected]>"]

[lib]
crate-type = ["cdylib"]

[dependencies]
pwasm-libc = { path = "../pwasm-libc", version = "0.1" }
pwasm-alloc = { path = "../pwasm-alloc", version = "0.1" }
24 changes: 15 additions & 9 deletions runtime/src/lib.rs → runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,23 @@ fn print<T: Printable + Sized>(value: T) {
value.print();
}

/// Test passing of data.
#[no_mangle]
pub fn exec_test_data_in(input_data: *mut u8, input_len: usize) -> u64 {
let input = unsafe {
Vec::from_raw_parts(input_data, input_len, input_len)
};

let output = test_data_in(input);
&output[0] as *const u8 as u64 + ((output.len() as u64) << 32)
macro_rules! impl_stub {
($name:ident) => {
pub mod _internal {
#[no_mangle]
pub fn $name(input_data: *mut u8, input_len: usize) -> u64 {
let input = unsafe {
super::alloc::vec::Vec::from_raw_parts(input_data, input_len, input_len)
};

let output = super::$name(input);
&output[0] as *const u8 as u64 + ((output.len() as u64) << 32)
}
}
}
}

impl_stub!(test_data_in);
fn test_data_in(input: Vec<u8>) -> Vec<u8> {
print(b"set_storage" as &[u8]);
state::set_storage(b"input", &input);
Expand Down
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions runtime/test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "runtime-test"
version = "0.1.0"
authors = ["Parity Technologies <[email protected]>"]

[lib]
crate-type = ["cdylib"]

[dependencies]
pwasm-libc = { path = "../pwasm-libc", version = "0.1" }
pwasm-alloc = { path = "../pwasm-alloc", version = "0.1" }
152 changes: 152 additions & 0 deletions runtime/test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#![no_std]
#![feature(lang_items)]
#![cfg_attr(feature = "strict", deny(warnings))]

#![feature(alloc)]

extern crate alloc;
use alloc::vec::Vec;

extern crate pwasm_libc;
extern crate pwasm_alloc;

#[lang = "panic_fmt"]
#[no_mangle]
pub fn panic_fmt() -> ! {
loop {}
}

extern "C" {
fn ext_print(utf8_data: *const u8, utf8_len: i32);
fn ext_print_num(value: u64);
fn set_storage(key_data: *const u8, key_len: i32, value_data: *const u8, value_len: i32);
fn get_allocated_storage(key_data: *const u8, key_len: i32, written_out: *mut i32) -> *mut u8;
}

pub mod state {
use alloc::vec::Vec;
use super::{get_allocated_storage, set_storage as super_set_storage};

pub fn storage(key: &[u8]) -> Vec<u8> {
let mut length: i32 = 0;
unsafe {
let ptr = get_allocated_storage(&key[0], key.len() as i32, &mut length);
Vec::from_raw_parts(ptr, length as usize, length as usize)
}
}

pub fn set_storage(key: &[u8], value: &[u8]) {
unsafe {
super_set_storage(
&key[0] as *const u8, key.len() as i32,
&value[0] as *const u8, value.len() as i32
);
}
}

pub fn code() -> Vec<u8> {
storage(b"\0code")
}

pub fn set_code(new: &[u8]) {
set_storage(b"\0code", new)
}

fn value_vec(mut value: usize, initial: Vec<u8>) -> Vec<u8> {
let mut acc = initial;
while value > 0 {
acc.push(value as u8);
value /= 256;
}
acc
}

pub fn set_validator(index: usize, validator: &[u8]) {
set_storage(&value_vec(index, b"\0validator".to_vec()), validator);
}

pub fn validator(index: usize) -> Vec<u8> {
storage(&value_vec(index, b"\0validator".to_vec()))
}

pub fn set_validator_count(count: usize) {
(count..validator_count()).for_each(|i| set_validator(i, &[]));
set_storage(b"\0validator_count", &value_vec(count, Vec::new()));
}

pub fn validator_count() -> usize {
storage(b"\0validator_count").into_iter().rev().fold(0, |acc, i| (acc << 8) + (i as usize))
}

pub fn validators() -> Vec<Vec<u8>> {
(0..validator_count()).into_iter().map(validator).collect()
}

pub fn set_validators(validators: &[&[u8]]) {
set_validator_count(validators.len());
validators.iter().enumerate().for_each(|(v, i)| set_validator(v, i));
}
}

trait Printable {
fn print(self);
}

impl<'a> Printable for &'a [u8] {
fn print(self) {
unsafe {
ext_print(&self[0] as *const u8, self.len() as i32);
}
}
}

impl Printable for u64 {
fn print(self) {
unsafe { ext_print_num(self); }
}
}

fn print<T: Printable + Sized>(value: T) {
value.print();
}

macro_rules! impl_stub {
($name:ident) => {
pub mod _internal {
#[no_mangle]
pub fn $name(input_data: *mut u8, input_len: usize) -> u64 {
let input = unsafe {
super::alloc::vec::Vec::from_raw_parts(input_data, input_len, input_len)
};

let output = super::$name(input);
&output[0] as *const u8 as u64 + ((output.len() as u64) << 32)
}
}
}
}

impl_stub!(test_data_in);
fn test_data_in(input: Vec<u8>) -> Vec<u8> {
print(b"set_storage" as &[u8]);
state::set_storage(b"input", &input);

print(b"code" as &[u8]);
state::set_storage(b"code", &state::code());

print(b"set_code" as &[u8]);
state::set_code(&input);

print(b"storage" as &[u8]);
let copy = state::storage(b"input");

print(b"validators" as &[u8]);
let mut v = state::validators();
v.push(copy);

print(b"set_validators" as &[u8]);
state::set_validators(&v.iter().map(Vec::as_slice).collect::<Vec<_>>());

print(b"finished!" as &[u8]);
b"all ok!".to_vec()
}