diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 2e3dc3238a128d1b46448eb58db7d8deb916d32b..b2fca77787b12aa8e978c3f8de71031557563faa 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -1490,8 +1490,6 @@ version = "0.1.0" dependencies = [ "ed25519 0.1.0", "environmental 0.1.0", - "pwasm-alloc 0.1.0", - "pwasm-libc 0.1.0", "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-primitives 0.1.0", @@ -1504,6 +1502,8 @@ dependencies = [ name = "substrate-runtime-std" version = "0.1.0" dependencies = [ + "pwasm-alloc 0.1.0", + "pwasm-libc 0.1.0", "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/substrate/executor/src/wasm_executor.rs b/substrate/executor/src/wasm_executor.rs index beefb55ec120ea8011700cddcffb28c7d1cb70ec..7ba1dd5d2fab0fef8087850c135274ad61cdb7c3 100644 --- a/substrate/executor/src/wasm_executor.rs +++ b/substrate/executor/src/wasm_executor.rs @@ -37,7 +37,7 @@ struct Heap { impl Heap { fn new() -> Self { Heap { - end: 32768, + end: 262144, } } fn allocate(&mut self, size: u32) -> u32 { @@ -53,6 +53,7 @@ struct FunctionExecutor<'e, E: Externalities + 'e> { heap: Heap, memory: Arc<MemoryInstance>, ext: &'e mut E, + hash_lookup: HashMap<Vec<u8>, Vec<u8>>, } impl<'e, E: Externalities> FunctionExecutor<'e, E> { @@ -61,6 +62,7 @@ impl<'e, E: Externalities> FunctionExecutor<'e, E> { heap: Heap::new(), memory: Arc::clone(m), ext: e, + hash_lookup: HashMap::new(), } } } @@ -89,21 +91,39 @@ impl ReadPrimitive<u32> for MemoryInstance { } } +fn ascii_format(asciish: &[u8]) -> String { + let mut r = String::new(); + let mut latch = false; + for c in asciish { + match (latch, *c) { + (false, 32...127) => r.push(*c as char), + _ => { + if !latch { + r.push('#'); + latch = true; + } + r.push_str(&format!("{:02x}", *c)); + } + } + } + r +} + impl_function_executor!(this: FunctionExecutor<'e, E>, ext_print_utf8(utf8_data: *const u8, utf8_len: u32) => { if let Ok(utf8) = this.memory.get(utf8_data, utf8_len as usize) { if let Ok(message) = String::from_utf8(utf8) { - info!(target: "runtime", "{}", message); + println!("{}", message); } } }, ext_print_hex(data: *const u8, len: u32) => { if let Ok(hex) = this.memory.get(data, len as usize) { - info!(target: "runtime", "{}", HexDisplay::from(&hex)); + println!("{}", HexDisplay::from(&hex)); } }, ext_print_num(number: u64) => { - info!(target: "runtime", "{}", number); + println!("{}", number); }, ext_memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 => { let sl1 = this.memory.get(s1, n as usize).map_err(|_| DummyUserError)?; @@ -144,13 +164,23 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, ext_set_storage(key_data: *const u8, key_len: u32, value_data: *const u8, value_len: u32) => { let key = this.memory.get(key_data, key_len as usize).map_err(|_| DummyUserError)?; let value = this.memory.get(value_data, value_len as usize).map_err(|_| DummyUserError)?; - info!(target: "runtime", "Setting storage: {} -> {}", HexDisplay::from(&key), HexDisplay::from(&value)); + if let Some(preimage) = this.hash_lookup.get(&key) { + println!("*** Setting storage: %{} -> {} [k={}]", ascii_format(&preimage), HexDisplay::from(&value), HexDisplay::from(&key)); + } else { + println!("*** Setting storage: {} -> {} [k={}]", ascii_format(&key), HexDisplay::from(&value), HexDisplay::from(&key)); + } this.ext.set_storage(key, value); }, ext_get_allocated_storage(key_data: *const u8, key_len: u32, written_out: *mut u32) -> *mut u8 => { let key = this.memory.get(key_data, key_len as usize).map_err(|_| DummyUserError)?; let value = this.ext.storage(&key).map_err(|_| DummyUserError)?; + if let Some(preimage) = this.hash_lookup.get(&key) { + println!(" Getting storage: %{} == {} [k={}]", ascii_format(&preimage), HexDisplay::from(&value), HexDisplay::from(&key)); + } else { + println!(" Getting storage: {} == {} [k={}]", ascii_format(&key), HexDisplay::from(&value), HexDisplay::from(&key)); + } + let offset = this.heap.allocate(value.len() as u32) as u32; this.memory.set(offset, &value).map_err(|_| DummyUserError)?; @@ -160,7 +190,11 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, ext_get_storage_into(key_data: *const u8, key_len: u32, value_data: *mut u8, value_len: u32, value_offset: u32) -> u32 => { let key = this.memory.get(key_data, key_len as usize).map_err(|_| DummyUserError)?; let value = this.ext.storage(&key).map_err(|_| DummyUserError)?; - info!(target: "runtime", "Getting storage: {} ( -> {})", HexDisplay::from(&key), HexDisplay::from(&value)); + if let Some(preimage) = this.hash_lookup.get(&key) { + println!(" Getting storage: %{} == {} [k={}]", ascii_format(&preimage), HexDisplay::from(&value), HexDisplay::from(&key)); + } else { + println!(" Getting storage: {} == {} [k={}]", ascii_format(&key), HexDisplay::from(&value), HexDisplay::from(&key)); + } let value = &value[value_offset as usize..]; let written = ::std::cmp::min(value_len as usize, value.len()); this.memory.set(value_data, &value[..written]).map_err(|_| DummyUserError)?; @@ -189,18 +223,22 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, }, ext_twox_128(data: *const u8, len: u32, out: *mut u8) => { let result = if len == 0 { - info!(target: "runtime", "XXhash: ''"); - twox_128(&[0u8; 0]) + let hashed = twox_128(&[0u8; 0]); + //println!("XXhash: '' -> {}", HexDisplay::from(&hashed)); + this.hash_lookup.insert(hashed.to_vec(), vec![]); + hashed } else { let key = this.memory.get(data, len as usize).map_err(|_| DummyUserError)?; let hashed_key = twox_128(&key); if let Ok(skey) = ::std::str::from_utf8(&key) { - info!(target: "runtime", "XXhash: {} -> {}", skey, HexDisplay::from(&hashed_key)); + //println!("XXhash: {} -> {}", skey, HexDisplay::from(&hashed_key)); } else { - info!(target: "runtime", "XXhash: {} -> {}", HexDisplay::from(&key), HexDisplay::from(&hashed_key)); + //println!("XXhash: {} -> {}", HexDisplay::from(&key), HexDisplay::from(&hashed_key)); } + this.hash_lookup.insert(hashed_key.to_vec(), key); hashed_key }; + this.memory.set(out, &result).map_err(|_| DummyUserError)?; }, ext_twox_256(data: *const u8, len: u32, out: *mut u8) => { @@ -252,6 +290,7 @@ impl CodeExecutor for WasmExecutor { data: &[u8], ) -> Result<Vec<u8>> { // TODO: handle all expects as errors to be returned. + println!(/*target: "wasm-executor",*/ "Wasm-Calling {}({})", method, HexDisplay::from(&data)); let program = ProgramInstance::new().expect("this really shouldn't be able to fail; qed"); @@ -276,8 +315,11 @@ impl CodeExecutor for WasmExecutor { })?; if let Some(I64(r)) = returned { - memory.get(r as u32, (r >> 32) as u32 as usize) + let offset = r as u32; + let length = (r >> 32) as u32 as usize; + memory.get(offset, length) .map_err(|_| ErrorKind::Runtime.into()) + .map(|v| { println!(/*target: "wasm-executor",*/ "Returned {}", HexDisplay::from(&v)); v }) } else { Err(ErrorKind::InvalidReturn.into()) } diff --git a/substrate/executor/wasm/Cargo.lock b/substrate/executor/wasm/Cargo.lock index bed624c5446ea6990376d682bda22fd21d1cbd34..5b062eb2d91d50d1fcb0cc5b8c95f2e62e40f183 100644 --- a/substrate/executor/wasm/Cargo.lock +++ b/substrate/executor/wasm/Cargo.lock @@ -88,8 +88,6 @@ dependencies = [ name = "substrate-runtime-io" version = "0.1.0" dependencies = [ - "pwasm-alloc 0.1.0", - "pwasm-libc 0.1.0", "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-primitives 0.1.0", @@ -100,6 +98,8 @@ dependencies = [ name = "substrate-runtime-std" version = "0.1.0" dependencies = [ + "pwasm-alloc 0.1.0", + "pwasm-libc 0.1.0", "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/substrate/polkadot-executor/src/lib.rs b/substrate/polkadot-executor/src/lib.rs index 8ed3deed718575668854529cf354997103a7665e..0c6c0fb37ee31bf80d582b49f68a6abb6142a361 100644 --- a/substrate/polkadot-executor/src/lib.rs +++ b/substrate/polkadot-executor/src/lib.rs @@ -26,6 +26,7 @@ extern crate substrate_primitives as primitives; extern crate polkadot_primitives as polkadot_primitives; extern crate ed25519; extern crate triehash; +#[cfg(test)] #[macro_use] extern crate hex_literal; @@ -39,7 +40,7 @@ impl NativeExecutionDispatch for LocalNativeExecutionDispatch { fn native_equivalent() -> &'static [u8] { // WARNING!!! This assumes that the runtime was built *before* the main project. Until we // get a proper build script, this must be strictly adhered to or things will go wrong. - include_bytes!("../../polkadot-runtime/wasm/target/wasm32-unknown-unknown/release/runtime_polkadot.compact.wasm") + include_bytes!("../../polkadot-runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm") } fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> { @@ -66,8 +67,8 @@ mod tests { UncheckedTransaction, Function, AccountId}; use ed25519::Pair; - const BLOATY_CODE: &[u8] = include_bytes!("../../polkadot-runtime/wasm/target/wasm32-unknown-unknown/release/runtime_polkadot.wasm"); - const COMPACT_CODE: &[u8] = include_bytes!("../../polkadot-runtime/wasm/target/wasm32-unknown-unknown/release/runtime_polkadot.compact.wasm"); + const BLOATY_CODE: &[u8] = include_bytes!("../../polkadot-runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm"); + const COMPACT_CODE: &[u8] = include_bytes!("../../polkadot-runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm"); // TODO: move into own crate. macro_rules! map { @@ -288,7 +289,7 @@ mod tests { twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0] ], }; - let foreign_code = include_bytes!("../../polkadot-runtime/wasm/target/wasm32-unknown-unknown/release/runtime_polkadot.wasm"); + let foreign_code = include_bytes!("../../polkadot-runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm"); let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &vec![].join(&Header::from_block_number(1u64)).join(&tx())); assert!(r.is_err()); } @@ -302,7 +303,7 @@ mod tests { twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0] ], }; - let foreign_code = include_bytes!("../../polkadot-runtime/wasm/target/wasm32-unknown-unknown/release/runtime_polkadot.compact.wasm"); + let foreign_code = include_bytes!("../../polkadot-runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm"); let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &vec![].join(&Header::from_block_number(1u64)).join(&tx())); assert!(r.is_ok()); diff --git a/substrate/polkadot-runtime/src/genesismap.rs b/substrate/polkadot-runtime/src/genesismap.rs index df7fe04711dcdda4163218ba0f38d9be7deefee8..a12086cc47d7b1ec073f8ea6d05de784a187e683 100644 --- a/substrate/polkadot-runtime/src/genesismap.rs +++ b/substrate/polkadot-runtime/src/genesismap.rs @@ -50,7 +50,7 @@ impl GenesisConfig { } pub fn genesis_map(&self) -> HashMap<Vec<u8>, Vec<u8>> { - let wasm_runtime = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_polkadot.compact.wasm").to_vec(); + let wasm_runtime = include_bytes!("../wasm/genesis.wasm").to_vec(); vec![ (&b"gov:apr"[..], vec![].join(&self.approval_ratio)), (&b"ses:len"[..], vec![].join(&self.session_length)), diff --git a/substrate/polkadot-runtime/src/runtime/parachains.rs b/substrate/polkadot-runtime/src/runtime/parachains.rs index 222448467aa47f9d86a0832d9a9a4a08901784d2..d0c4f5c845247a61c685cda7ba5a4a1f3a8fd8c2 100644 --- a/substrate/polkadot-runtime/src/runtime/parachains.rs +++ b/substrate/polkadot-runtime/src/runtime/parachains.rs @@ -17,7 +17,7 @@ //! Main parachains logic. For now this is just the determination of which validators do what. use rstd::prelude::*; -use runtime_io::mem; +use rstd::mem; use codec::{Slicable, Joiner}; use support::{Hashable, with_env, storage}; use runtime::session; diff --git a/substrate/polkadot-runtime/src/runtime/staking.rs b/substrate/polkadot-runtime/src/runtime/staking.rs index d6d4065dc999b7ccf99c6e303fa919baf4544a35..210c518146b37a7126751c56a22496184a21efaa 100644 --- a/substrate/polkadot-runtime/src/runtime/staking.rs +++ b/substrate/polkadot-runtime/src/runtime/staking.rs @@ -17,7 +17,7 @@ //! Staking manager: Handles balances and periodically determines the best set of validators. use rstd::prelude::*; -use runtime_io::cell::RefCell; +use rstd::cell::RefCell; use runtime_io::print; use codec::KeyedVec; use support::{storage, StorageVec}; diff --git a/substrate/polkadot-runtime/src/runtime/system.rs b/substrate/polkadot-runtime/src/runtime/system.rs index 6eb622947032b8ae8695c82ba401bef1ce267269..a82d911ea92c57164812f63a2874f86d16074c19 100644 --- a/substrate/polkadot-runtime/src/runtime/system.rs +++ b/substrate/polkadot-runtime/src/runtime/system.rs @@ -18,7 +18,8 @@ //! and depositing logs. use rstd::prelude::*; -use runtime_io::{mem, storage_root, enumerated_trie_root}; +use rstd::mem; +use runtime_io::{print, storage_root, enumerated_trie_root}; use codec::{KeyedVec, Slicable}; use support::{Hashable, storage, with_env}; use polkadot_primitives::{AccountId, Hash, TxOrder, BlockNumber, Block, Header, @@ -71,6 +72,7 @@ pub mod internal { // execute transactions block.transactions.iter().cloned().for_each(super::execute_transaction); + // post-transactional book-keeping. staking::internal::check_new_era(); session::internal::check_rotate_session(); @@ -103,6 +105,13 @@ pub mod internal { /// Finalise the block - it is up the caller to ensure that all header fields are valid /// except state-root. pub fn finalise_block(mut header: Header) -> Header { + // populate environment from header. + with_env(|e| { + e.block_number = header.number; + e.parent_hash = header.parent_hash; + mem::swap(&mut header.digest, &mut e.digest); + }); + staking::internal::check_new_era(); session::internal::check_rotate_session(); @@ -211,7 +220,13 @@ fn info_expect_equal_hash(given: &Hash, expected: &Hash) { } #[cfg(not(feature = "std"))] -fn info_expect_equal_hash(_given: &Hash, _expected: &Hash) {} +fn info_expect_equal_hash(given: &Hash, expected: &Hash) { + if given != expected { + print("Hash not equal"); + print(&given.0[..]); + print(&expected.0[..]); + } +} #[cfg(test)] mod tests { diff --git a/substrate/polkadot-runtime/src/support/environment.rs b/substrate/polkadot-runtime/src/support/environment.rs index 63ab4277d1be7514963bc89ae6b2c8f5dffb5cc2..d7651c575aa36a8a23469eb8389ddb01bf2e2577 100644 --- a/substrate/polkadot-runtime/src/support/environment.rs +++ b/substrate/polkadot-runtime/src/support/environment.rs @@ -16,10 +16,10 @@ //! Environment API: Allows certain information to be accessed throughout the runtime. -use runtime_io::boxed::Box; -use runtime_io::mem; -use runtime_io::cell::RefCell; -use runtime_io::rc::Rc; +use rstd::boxed::Box; +use rstd::mem; +use rstd::cell::RefCell; +use rstd::rc::Rc; use polkadot_primitives::{BlockNumber, Digest, Hash}; diff --git a/substrate/polkadot-runtime/wasm/Cargo.lock b/substrate/polkadot-runtime/wasm/Cargo.lock index 7656a5a670c9985fd5e2e2e7310dc0162ed69441..506b138461be0b7441a449a15169f581ab3f8bb7 100644 --- a/substrate/polkadot-runtime/wasm/Cargo.lock +++ b/substrate/polkadot-runtime/wasm/Cargo.lock @@ -386,6 +386,17 @@ dependencies = [ "substrate-runtime-std 0.1.0", ] +[[package]] +name = "polkadot-runtime" +version = "0.1.0" +dependencies = [ + "polkadot-primitives 0.1.0", + "substrate-codec 0.1.0", + "substrate-primitives 0.1.0", + "substrate-runtime-io 0.1.0", + "substrate-runtime-std 0.1.0", +] + [[package]] name = "proc-macro-hack" version = "0.4.0" @@ -510,17 +521,6 @@ dependencies = [ "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "runtime-polkadot" -version = "0.1.0" -dependencies = [ - "polkadot-primitives 0.1.0", - "substrate-codec 0.1.0", - "substrate-primitives 0.1.0", - "substrate-runtime-io 0.1.0", - "substrate-runtime-std 0.1.0", -] - [[package]] name = "rustc-hex" version = "1.0.0" @@ -621,8 +621,6 @@ version = "0.1.0" dependencies = [ "ed25519 0.1.0", "environmental 0.1.0", - "pwasm-alloc 0.1.0", - "pwasm-libc 0.1.0", "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-primitives 0.1.0", @@ -635,6 +633,8 @@ dependencies = [ name = "substrate-runtime-std" version = "0.1.0" dependencies = [ + "pwasm-alloc 0.1.0", + "pwasm-libc 0.1.0", "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/substrate/polkadot-runtime/wasm/Cargo.toml b/substrate/polkadot-runtime/wasm/Cargo.toml index 96084ddbde727fb42a8581a3970c18cdf6298577..b606dd6d83b2c0efa56fc93b8f41a43382f2d2fb 100644 --- a/substrate/polkadot-runtime/wasm/Cargo.toml +++ b/substrate/polkadot-runtime/wasm/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "runtime-polkadot" +name = "polkadot-runtime" version = "0.1.0" authors = ["Parity Technologies <admin@parity.io>"] diff --git a/substrate/polkadot-runtime/wasm/build.sh b/substrate/polkadot-runtime/wasm/build.sh index 2cc63b077577948fa28866a1f19ceb6a77254ea2..d48d10a062d38b4b308eda02240508da793846a3 100755 --- a/substrate/polkadot-runtime/wasm/build.sh +++ b/substrate/polkadot-runtime/wasm/build.sh @@ -2,7 +2,7 @@ set -e cargo +nightly build --target=wasm32-unknown-unknown --release -for i in polkadot +for i in polkadot_runtime do - wasm-gc target/wasm32-unknown-unknown/release/runtime_$i.wasm target/wasm32-unknown-unknown/release/runtime_$i.compact.wasm + wasm-gc target/wasm32-unknown-unknown/release/$i.wasm target/wasm32-unknown-unknown/release/$i.compact.wasm done diff --git a/substrate/polkadot-runtime/wasm/genesis.wasm b/substrate/polkadot-runtime/wasm/genesis.wasm new file mode 100644 index 0000000000000000000000000000000000000000..91c7b475743cb7b9cbb48c6dcc162501fe9e43c0 Binary files /dev/null and b/substrate/polkadot-runtime/wasm/genesis.wasm differ diff --git a/substrate/runtime-io/Cargo.toml b/substrate/runtime-io/Cargo.toml index 522e42af82c04f60de54e19664d8c700e2a1bb75..ef82206aad98168fe10ec67d3b9203b0c6506c1b 100644 --- a/substrate/runtime-io/Cargo.toml +++ b/substrate/runtime-io/Cargo.toml @@ -8,8 +8,6 @@ build = "build.rs" rustc_version = "0.2" [dependencies] -pwasm-alloc = { path = "../pwasm-alloc" } -pwasm-libc = { path = "../pwasm-libc" } substrate-runtime-std = { path = "../runtime-std", default_features = false } environmental = { path = "../environmental", optional = true } substrate-state-machine = { path = "../state-machine", optional = true } diff --git a/substrate/runtime-io/with_std.rs b/substrate/runtime-io/with_std.rs index 04ecda169088ce8be40e6f7a958c2b349afbe78d..40c1fe754d8d191061f6d18310378951a9885974 100644 --- a/substrate/runtime-io/with_std.rs +++ b/substrate/runtime-io/with_std.rs @@ -22,13 +22,6 @@ extern crate substrate_primitives as primitives; extern crate triehash; extern crate ed25519; -pub use std::vec; -pub use std::rc; -pub use std::cell; -pub use std::boxed; -pub use std::slice; -pub use std::mem; - // re-export hashing functions. pub use primitives::{blake2_256, twox_128, twox_256}; diff --git a/substrate/runtime-io/without_std.rs b/substrate/runtime-io/without_std.rs index 472b135beb8dc151f21c378579ee6678a7e84670..e5db2c7753ccbdbf41ca24f304dc216c946c95f8 100644 --- a/substrate/runtime-io/without_std.rs +++ b/substrate/runtime-io/without_std.rs @@ -14,24 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see <http://www.gnu.org/licenses/>. -#[cfg(feature = "nightly")] -extern crate alloc; - -#[cfg(feature = "nightly")] -extern crate pwasm_libc; -#[cfg(feature = "nightly")] -extern crate pwasm_alloc; - +extern crate substrate_runtime_std as rstd; extern crate substrate_primitives as primitives; -pub use alloc::vec; -pub use alloc::boxed; -pub use alloc::rc; -pub use core::mem; -pub use core::slice; -pub use core::cell; - -use alloc::vec::Vec; +use rstd::intrinsics; +use rstd::vec::Vec; +pub use rstd::{mem, slice}; #[lang = "panic_fmt"] #[no_mangle] @@ -40,7 +28,7 @@ pub extern fn panic_fmt(_fmt: ::core::fmt::Arguments, _file: &'static str, _line ext_print_utf8(_file.as_ptr() as *const u8, _file.len() as u32); ext_print_num(_line as u64); ext_print_num(_col as u64); - ::core::intrinsics::abort() + intrinsics::abort() } } @@ -83,7 +71,11 @@ pub fn set_storage(key: &[u8], value: &[u8]) { /// the number of bytes that the key in storage was. pub fn read_storage(key: &[u8], value_out: &mut [u8], value_offset: usize) -> usize { unsafe { - ext_get_storage_into(key.as_ptr(), key.len() as u32, value_out.as_mut_ptr(), value_out.len() as u32, value_offset as u32) as usize + ext_get_storage_into( + key.as_ptr(), key.len() as u32, + value_out.as_mut_ptr(), value_out.len() as u32, + value_offset as u32 + ) as usize } } @@ -200,7 +192,9 @@ macro_rules! impl_stubs { }; let output = super::$name(input); - output.as_ptr() as u64 + ((output.len() as u64) << 32) + let r = output.as_ptr() as u64 + ((output.len() as u64) << 32); + $crate::mem::forget(output); + r } )* } diff --git a/substrate/runtime-std/Cargo.toml b/substrate/runtime-std/Cargo.toml index e619a9b5d4775b641e6fbf1e6d6c86913b562c15..42745a0152a1007e7cd3872415da35776b640aeb 100644 --- a/substrate/runtime-std/Cargo.toml +++ b/substrate/runtime-std/Cargo.toml @@ -8,6 +8,8 @@ build = "build.rs" rustc_version = "0.2" [dependencies] +pwasm-alloc = { path = "../pwasm-alloc" } +pwasm-libc = { path = "../pwasm-libc" } [features] default = ["std"] diff --git a/substrate/runtime-std/without_std.rs b/substrate/runtime-std/without_std.rs index ea0f278d37e26259c4cdef793d14864b93603d47..4aff3153ca20eec3ce8e248e31e9c77bcae5b120 100644 --- a/substrate/runtime-std/without_std.rs +++ b/substrate/runtime-std/without_std.rs @@ -16,6 +16,10 @@ #[cfg(feature = "nightly")] extern crate alloc; +#[cfg(feature = "nightly")] +extern crate pwasm_libc; +#[cfg(feature = "nightly")] +extern crate pwasm_alloc; pub use alloc::vec; pub use alloc::boxed; @@ -26,3 +30,4 @@ pub use core::cell; pub use core::ops; pub use core::iter; pub use core::ptr; +pub use core::intrinsics;