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
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
1 change: 1 addition & 0 deletions demo/runtime/wasm/Cargo.lock

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

Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions polkadot/runtime/wasm/Cargo.lock

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

Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion substrate/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ assert_matches = "1.1"
wabt = "0.4"

[features]
default = []
default = ["wasm-extern-trace"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why this is turned on by default?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

gah

wasm-extern-trace = []
18 changes: 9 additions & 9 deletions substrate/executor/src/wasm_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use state_machine::{Externalities, CodeExecutor};
use error::{Error, ErrorKind, Result};
use wasm_utils::UserError;
use primitives::{blake2_256, twox_128, twox_256};
use primitives::hexdisplay::{HexDisplay, ascii_format};
use primitives::hexdisplay::{self, HexDisplay};
use primitives::sandbox as sandbox_primitives;
use triehash::ordered_trie_root;
use sandbox;
Expand Down Expand Up @@ -200,9 +200,9 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
let key = this.memory.get(key_data, key_len as usize).map_err(|_| UserError("Invalid attempt to determine key in ext_set_storage"))?;
let value = this.memory.get(value_data, value_len as usize).map_err(|_| UserError("Invalid attempt to determine value in ext_set_storage"))?;
if let Some(_preimage) = this.hash_lookup.get(&key) {
debug_trace!(target: "wasm-trace", "*** Setting storage: %{} -> {} [k={}]", ascii_format(&_preimage), HexDisplay::from(&value), HexDisplay::from(&key));
debug_trace!(target: "wasm-trace", "*** Setting storage: %{} -> {} [k={}]", hexdisplay::ascii_format(&_preimage), HexDisplay::from(&value), HexDisplay::from(&key));
} else {
debug_trace!(target: "wasm-trace", "*** Setting storage: {} -> {} [k={}]", ascii_format(&key), HexDisplay::from(&value), HexDisplay::from(&key));
debug_trace!(target: "wasm-trace", "*** Setting storage: {} -> {} [k={}]", hexdisplay::ascii_format(&key), HexDisplay::from(&value), HexDisplay::from(&key));
}
this.ext.set_storage(key, value);
Ok(())
Expand All @@ -211,9 +211,9 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
let key = this.memory.get(key_data, key_len as usize).map_err(|_| UserError("Invalid attempt to determine key in ext_clear_storage"))?;
debug_trace!(target: "wasm-trace", "*** Clearing storage: {} [k={}]",
if let Some(_preimage) = this.hash_lookup.get(&key) {
format!("%{}", ascii_format(&_preimage))
format!("%{}", hexdisplay::ascii_format(&_preimage))
} else {
format!(" {}", ascii_format(&key))
format!(" {}", hexdisplay::ascii_format(&key))
}, HexDisplay::from(&key));
this.ext.clear_storage(&key);
Ok(())
Expand All @@ -234,9 +234,9 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,

debug_trace!(target: "wasm-trace", "*** Getting storage: {} == {} [k={}]",
if let Some(_preimage) = this.hash_lookup.get(&key) {
format!("%{}", ascii_format(&_preimage))
format!("%{}", hexdisplay::ascii_format(&_preimage))
} else {
format!(" {}", ascii_format(&key))
format!(" {}", hexdisplay::ascii_format(&key))
},
if let Some(ref b) = maybe_value {
format!("{}", HexDisplay::from(b))
Expand Down Expand Up @@ -264,9 +264,9 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
let maybe_value = this.ext.storage(&key);
debug_trace!(target: "wasm-trace", "*** Getting storage: {} == {} [k={}]",
if let Some(_preimage) = this.hash_lookup.get(&key) {
format!("%{}", ascii_format(&_preimage))
format!("%{}", hexdisplay::ascii_format(&_preimage))
} else {
format!(" {}", ascii_format(&key))
format!(" {}", hexdisplay::ascii_format(&key))
},
if let Some(ref b) = maybe_value {
format!("{}", HexDisplay::from(b))
Expand Down
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions substrate/runtime-io/with_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ pub fn clear_storage(key: &[u8]) {
);
}

/// Clear the storage of some particular key.
pub fn exists_storage(key: &[u8]) {
/// Check whether a given `key` exists in storage.
pub fn exists_storage(key: &[u8]) -> bool {
ext::with(|ext|
ext.exists_storage(key)
);
).unwrap_or(false)
}

/// Clear the storage entries key of which starts with the given prefix.
Expand Down
6 changes: 3 additions & 3 deletions substrate/runtime-io/without_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ pub fn clear_storage(key: &[u8]) {
}
}

/// Clear the storage of some particular key.
pub fn exists_storage(key: &[u8]) {
/// Determine whether a particular key exists in storage.
pub fn exists_storage(key: &[u8]) -> bool {
unsafe {
ext_exists_storage(
key.as_ptr(), key.len() as u32
) != 0;
) != 0
}
}

Expand Down
21 changes: 18 additions & 3 deletions substrate/runtime-support/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ impl<'a> Input for IncrementalInput<'a> {
}
}

// TODO: only introduce this wrapper for types where it makes sense, ideally have it within the module declaration.

struct AppendZeroes<'a> {
input: &'a mut Input,
}

impl<'a> Input for AppendZeroes<'a> {
fn read(&mut self, into: &mut [u8]) -> usize {
let r = self.input.read(into);
for z in &mut into[r..] {
Copy link
Copy Markdown
Contributor

@rphmeier rphmeier Jul 17, 2018

Choose a reason for hiding this comment

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

will panic if the slice was completely filled, won't it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should just return an empty slice

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

interesting artifact of the slicing syntax... that &[][0] would panic but &[][0..] wouldn't.

*z = 0;
};
into.len()
}
}

/// Return the value of the item in storage under `key`, or `None` if there is no explicit entry.
pub fn get<T: Codec + Sized>(key: &[u8]) -> Option<T> {
let key = twox_128(key);
Expand All @@ -47,7 +63,7 @@ pub fn get<T: Codec + Sized>(key: &[u8]) -> Option<T> {
key: &key[..],
pos: 0,
};
Decode::decode(&mut input).expect("storage is not null, therefore must be a valid type")
Decode::decode(&mut AppendZeroes { input: &mut input } ).expect("storage is not null, therefore must be a valid type")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Virtual dispatch here is really unnecessary and it might have a significant cost if it occurs on every call to storage::get

})
}

Expand Down Expand Up @@ -103,8 +119,7 @@ pub fn take_or_else<T: Codec + Sized, F: FnOnce() -> T>(key: &[u8], default_valu

/// Check to see if `key` has an explicit entry in storage.
pub fn exists(key: &[u8]) -> bool {
let mut x = [0u8; 0];
runtime_io::read_storage(&twox_128(key)[..], &mut x[..], 0).is_some()
runtime_io::exists_storage(&twox_128(key)[..])
}

/// Ensure `key` has no explicit entry in storage.
Expand Down
1 change: 1 addition & 0 deletions substrate/test-runtime/wasm/Cargo.lock

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

Binary file not shown.
Binary file not shown.