Rename and use --max-heap-pages parameter (#1666)

This commit is contained in:
Stanislav Tkach
2019-02-05 13:35:12 +02:00
committed by Gav Wood
parent 888e7bb76f
commit df685c9e53
10 changed files with 45 additions and 34 deletions
+3 -3
View File
@@ -263,9 +263,9 @@ pub struct ImportBlocksCmd {
)]
pub api_execution: ExecutionStrategy,
/// The maximum number of 64KB pages to ever allocate for Wasm execution. Don't alter this unless you know what you're doing.
#[structopt(long = "max-heap-pages", value_name = "COUNT")]
pub max_heap_pages: Option<u32>,
/// The default number of 64KB pages to allocate for Wasm execution. Don't alter this unless you know what you're doing.
#[structopt(long = "default-heap-pages", value_name = "COUNT")]
pub default_heap_pages: Option<u32>,
#[allow(missing_docs)]
#[structopt(flatten)]
+2 -2
View File
@@ -54,7 +54,7 @@ mod tests {
native_executor_instance!(Executor, test_client::runtime::api::dispatch, test_client::runtime::native_version, include_bytes!("../../test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm"));
fn executor() -> executor::NativeExecutor<Executor> {
NativeExecutionDispatch::new()
NativeExecutionDispatch::new(None)
}
fn construct_block(
@@ -207,7 +207,7 @@ mod tests {
&backend,
Some(&InMemoryChangesTrieStorage::new()),
&mut overlay,
&Executor::new(),
&Executor::new(None),
"Core_execute_block",
&b1data,
ExecutionStrategy::NativeWhenPossible,
@@ -450,7 +450,7 @@ mod tests {
).unwrap();
// check remote execution proof locally
let local_executor = test_client::LocalExecutor::new();
let local_executor = test_client::LocalExecutor::new(None);
let local_result = check_execution_proof(&local_executor, &RemoteCallRequest {
block: test_client::runtime::Hash::default(),
header: test_client::runtime::Header {
+7 -7
View File
@@ -456,7 +456,7 @@ pub mod tests {
None,
crate::backend::NewBlockState::Final,
).unwrap();
let local_executor = test_client::LocalExecutor::new();
let local_executor = test_client::LocalExecutor::new(None);
let local_checker = LightDataChecker::new(Arc::new(DummyBlockchain::new(DummyStorage::new())), local_executor);
(local_checker, remote_block_header, remote_read_proof, authorities_len)
}
@@ -482,7 +482,7 @@ pub mod tests {
if insert_cht {
local_storage.insert_cht_root(1, local_cht_root);
}
let local_executor = test_client::LocalExecutor::new();
let local_executor = test_client::LocalExecutor::new(None);
let local_checker = LightDataChecker::new(Arc::new(DummyBlockchain::new(DummyStorage::new())), local_executor);
(local_checker, local_cht_root, remote_block_header, remote_header_proof)
}
@@ -535,7 +535,7 @@ pub mod tests {
let (remote_client, local_roots, test_cases) = prepare_client_with_key_changes();
let local_checker = TestChecker::new(
Arc::new(DummyBlockchain::new(DummyStorage::new())),
test_client::LocalExecutor::new()
test_client::LocalExecutor::new(None)
);
let local_checker = &local_checker as &FetchChecker<Block>;
let max = remote_client.info().unwrap().chain.best_number;
@@ -603,7 +603,7 @@ pub mod tests {
local_storage.changes_tries_cht_roots.insert(0, local_cht_root);
let local_checker = TestChecker::new(
Arc::new(DummyBlockchain::new(local_storage)),
test_client::LocalExecutor::new()
test_client::LocalExecutor::new(None)
);
// check proof on local client
@@ -631,7 +631,7 @@ pub mod tests {
let (remote_client, local_roots, test_cases) = prepare_client_with_key_changes();
let local_checker = TestChecker::new(
Arc::new(DummyBlockchain::new(DummyStorage::new())),
test_client::LocalExecutor::new()
test_client::LocalExecutor::new(None)
);
let local_checker = &local_checker as &FetchChecker<Block>;
let max = remote_client.info().unwrap().chain.best_number;
@@ -712,7 +712,7 @@ pub mod tests {
// fails when changes trie CHT is missing from the local db
let local_checker = TestChecker::new(
Arc::new(DummyBlockchain::new(DummyStorage::new())),
test_client::LocalExecutor::new()
test_client::LocalExecutor::new(None)
);
assert!(local_checker.check_changes_tries_proof(4, &remote_proof.roots,
remote_proof.roots_proof.clone()).is_err());
@@ -722,7 +722,7 @@ pub mod tests {
local_storage.changes_tries_cht_roots.insert(0, local_cht_root);
let local_checker = TestChecker::new(
Arc::new(DummyBlockchain::new(local_storage)),
test_client::LocalExecutor::new()
test_client::LocalExecutor::new(None)
);
assert!(local_checker.check_changes_tries_proof(4, &remote_proof.roots, vec![]).is_err());
}
+19 -12
View File
@@ -51,6 +51,7 @@ fn fetch_cached_runtime_version<'a, E: Externalities<Blake2Hasher>>(
wasm_executor: &WasmExecutor,
cache: &'a mut RefMut<CacheType>,
ext: &mut E,
default_heap_pages: Option<u64>,
) -> Result<(&'a WasmModuleInstanceRef, &'a Option<RuntimeVersion>)> {
let code_hash = match ext.storage_hash(well_known_keys::CODE) {
@@ -63,10 +64,10 @@ fn fetch_cached_runtime_version<'a, E: Externalities<Blake2Hasher>>(
Some(code) => code,
None => return RuntimePreproc::InvalidCode,
};
let heap_pages = match ext.storage(well_known_keys::HEAP_PAGES) {
Some(pages) => u64::decode(&mut &pages[..]).unwrap_or(DEFAULT_HEAP_PAGES),
None => DEFAULT_HEAP_PAGES,
};
let heap_pages = ext.storage(well_known_keys::HEAP_PAGES)
.and_then(|pages| u64::decode(&mut &pages[..]))
.or(default_heap_pages)
.unwrap_or(DEFAULT_HEAP_PAGES);
match WasmModule::from_buffer(code)
.map_err(|_| ErrorKind::InvalidCode(vec![]).into())
.and_then(|module| wasm_executor.prepare_module(ext, heap_pages as usize, &module))
@@ -125,7 +126,7 @@ pub trait NativeExecutionDispatch: Send + Sync {
fn native_version() -> NativeVersion;
/// Construct corresponding `NativeExecutor`
fn new() -> NativeExecutor<Self> where Self: Sized;
fn new(default_heap_pages: Option<u64>) -> NativeExecutor<Self> where Self: Sized;
}
/// A generic `CodeExecutor` implementation that uses a delegate to determine wasm code equivalence
@@ -138,15 +139,18 @@ pub struct NativeExecutor<D: NativeExecutionDispatch> {
fallback: WasmExecutor,
/// Native runtime version info.
native_version: NativeVersion,
/// The default number of 64KB pages to allocate for Wasm execution.
default_heap_pages: Option<u64>,
}
impl<D: NativeExecutionDispatch> NativeExecutor<D> {
/// Create new instance.
pub fn new() -> Self {
pub fn new(default_heap_pages: Option<u64>) -> Self {
NativeExecutor {
_dummy: Default::default(),
fallback: WasmExecutor::new(),
native_version: D::native_version(),
default_heap_pages,
}
}
}
@@ -157,6 +161,7 @@ impl<D: NativeExecutionDispatch> Clone for NativeExecutor<D> {
_dummy: Default::default(),
fallback: self.fallback.clone(),
native_version: D::native_version(),
default_heap_pages: self.default_heap_pages,
}
}
}
@@ -171,7 +176,8 @@ impl<D: NativeExecutionDispatch> RuntimeInfo for NativeExecutor<D> {
ext: &mut E,
) -> Option<RuntimeVersion> {
RUNTIMES_CACHE.with(|c|
fetch_cached_runtime_version(&self.fallback, &mut c.borrow_mut(), ext).ok()?.1.clone()
fetch_cached_runtime_version(&self.fallback, &mut c.borrow_mut(), ext, self.default_heap_pages)
.ok()?.1.clone()
)
}
}
@@ -194,9 +200,10 @@ impl<D: NativeExecutionDispatch> CodeExecutor<Blake2Hasher> for NativeExecutor<D
) -> (Result<NativeOrEncoded<R>>, bool) {
RUNTIMES_CACHE.with(|c| {
let mut c = c.borrow_mut();
let (module, onchain_version) = match fetch_cached_runtime_version(&self.fallback, &mut c, ext) {
Ok((module, onchain_version)) => (module, onchain_version),
Err(e) => return (Err(e), false),
let (module, onchain_version) = match fetch_cached_runtime_version(
&self.fallback, &mut c, ext, self.default_heap_pages) {
Ok((module, onchain_version)) => (module, onchain_version),
Err(e) => return (Err(e), false),
};
match (
use_native,
@@ -281,8 +288,8 @@ macro_rules! native_executor_instance {
$version()
}
fn new() -> $crate::NativeExecutor<$name> {
$crate::NativeExecutor::new()
fn new(default_heap_pages: Option<u64>) -> $crate::NativeExecutor<$name> {
$crate::NativeExecutor::new(default_heap_pages)
}
}
}
+3
View File
@@ -67,6 +67,8 @@ pub struct Configuration<C, G: Serialize + DeserializeOwned + BuildStorage> {
pub rpc_ws: Option<SocketAddr>,
/// Telemetry service URL. `None` if disabled.
pub telemetry_url: Option<String>,
/// The default number of 64KB pages to allocate for Wasm execution
pub default_heap_pages: Option<u64>,
}
impl<C: Default, G: Serialize + DeserializeOwned + BuildStorage> Configuration<C, G> {
@@ -92,6 +94,7 @@ impl<C: Default, G: Serialize + DeserializeOwned + BuildStorage> Configuration<C
rpc_http: None,
rpc_ws: None,
telemetry_url: None,
default_heap_pages: None,
};
configuration.network.boot_nodes = configuration.chain_spec.boot_nodes().to_vec();
configuration.telemetry_url = configuration.chain_spec.telemetry_url().map(str::to_owned);
+2 -2
View File
@@ -113,7 +113,7 @@ pub struct Service<Components: components::Components> {
pub fn new_client<Factory: components::ServiceFactory>(config: &FactoryFullConfiguration<Factory>)
-> Result<Arc<ComponentClient<components::FullComponents<Factory>>>, error::Error>
{
let executor = NativeExecutor::new();
let executor = NativeExecutor::new(config.default_heap_pages);
let (client, _) = components::FullComponents::<Factory>::build_client(
config,
executor,
@@ -132,7 +132,7 @@ impl<Components: components::Components> Service<Components> {
let (signal, exit) = ::exit_future::signal();
// Create client
let executor = NativeExecutor::new();
let executor = NativeExecutor::new(config.default_heap_pages);
let mut keystore = Keystore::open(config.keystore_path.as_str().into())?;
+1
View File
@@ -135,6 +135,7 @@ fn node_config<F: ServiceFactory> (
rpc_http: None,
rpc_ws: None,
telemetry_url: None,
default_heap_pages: None,
}
}
+3 -3
View File
@@ -76,7 +76,7 @@ pub fn new_with_api_execution_strat(
api_execution_strategy: ExecutionStrategy
) -> client::Client<Backend, Executor, runtime::Block, runtime::RuntimeApi> {
let backend = Arc::new(Backend::new());
let executor = NativeExecutor::new();
let executor = NativeExecutor::new(None);
let executor = LocalCallExecutor::new(backend.clone(), executor);
client::Client::new(
@@ -95,7 +95,7 @@ pub fn new_with_changes_trie()
new_with_backend(Arc::new(Backend::new()), true)
}
/// Creates new client instance used for tests with an explicitely provided backend.
/// Creates new client instance used for tests with an explicitly provided backend.
/// This is useful for testing backend implementations.
pub fn new_with_backend<B>(
backend: Arc<B>,
@@ -107,7 +107,7 @@ pub fn new_with_backend<B>(
runtime::RuntimeApi
> where B: backend::LocalBackend<runtime::Block, Blake2Hasher>
{
let executor = NativeExecutor::new();
let executor = NativeExecutor::new(None);
client::new_with_backend(backend, executor, genesis_storage(support_changes_trie)).unwrap()
}
+4 -4
View File
@@ -101,7 +101,7 @@ mod tests {
}
fn executor() -> ::substrate_executor::NativeExecutor<Executor> {
::substrate_executor::NativeExecutor::new()
::substrate_executor::NativeExecutor::new(None)
}
#[test]
@@ -729,7 +729,7 @@ mod tests {
fn native_big_block_import_succeeds() {
let mut t = new_test_ext(COMPACT_CODE, false);
Executor::new().call::<_, NeverNativeValue, fn() -> _>(
Executor::new(None).call::<_, NeverNativeValue, fn() -> _>(
&mut t,
"Core_execute_block",
&block1big().0,
@@ -743,7 +743,7 @@ mod tests {
let mut t = new_test_ext(COMPACT_CODE, false);
assert!(
Executor::new().call::<_, NeverNativeValue, fn() -> _>(
Executor::new(None).call::<_, NeverNativeValue, fn() -> _>(
&mut t,
"Core_execute_block",
&block1big().0,
@@ -805,7 +805,7 @@ mod tests {
#[test]
fn full_native_block_import_works_with_changes_trie() {
let mut t = new_test_ext(COMPACT_CODE, true);
Executor::new().call::<_, NeverNativeValue, fn() -> _>(
Executor::new(None).call::<_, NeverNativeValue, fn() -> _>(
&mut t,
"Core_execute_block",
&block1(true).0,