mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
* Companion for #6726 * Spaces * 'Update substrate' Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -23,6 +23,7 @@ sc-executor = { git = "https://github.com/paritytech/substrate", branch = "maste
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
|
||||
parking_lot = { version = "0.10.0", optional = true }
|
||||
log = { version = "0.4.8", optional = true }
|
||||
futures = { version = "0.3.4", optional = true }
|
||||
|
||||
[target.'cfg(not(any(target_os = "android", target_os = "unknown")))'.dependencies]
|
||||
shared_memory = { version = "0.10.0", optional = true }
|
||||
@@ -43,4 +44,5 @@ std = [
|
||||
"sc-executor",
|
||||
"sp-io",
|
||||
"polkadot-core-primitives/std",
|
||||
"futures",
|
||||
]
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
use std::any::{TypeId, Any};
|
||||
use crate::primitives::{ValidationParams, ValidationResult};
|
||||
use codec::{Decode, Encode};
|
||||
use sp_core::storage::ChildInfo;
|
||||
use sp_core::traits::CallInWasm;
|
||||
use sp_core::{storage::ChildInfo, traits::{CallInWasm, SpawnNamed}};
|
||||
use sp_externalities::Extensions;
|
||||
use sp_wasm_interface::HostFunctions as _;
|
||||
|
||||
@@ -119,10 +118,11 @@ pub fn validate_candidate(
|
||||
validation_code: &[u8],
|
||||
params: ValidationParams,
|
||||
options: ExecutionMode<'_>,
|
||||
spawner: impl SpawnNamed + 'static,
|
||||
) -> Result<ValidationResult, Error> {
|
||||
match options {
|
||||
ExecutionMode::Local => {
|
||||
validate_candidate_internal(validation_code, ¶ms.encode())
|
||||
validate_candidate_internal(validation_code, ¶ms.encode(), spawner)
|
||||
},
|
||||
#[cfg(not(any(target_os = "android", target_os = "unknown")))]
|
||||
ExecutionMode::Remote(pool) => {
|
||||
@@ -154,9 +154,10 @@ type HostFunctions = sp_io::SubstrateHostFunctions;
|
||||
pub fn validate_candidate_internal(
|
||||
validation_code: &[u8],
|
||||
encoded_call_data: &[u8],
|
||||
spawner: impl SpawnNamed + 'static,
|
||||
) -> Result<ValidationResult, Error> {
|
||||
let mut extensions = Extensions::new();
|
||||
extensions.register(sp_core::traits::TaskExecutorExt(sp_core::tasks::executor()));
|
||||
extensions.register(sp_core::traits::TaskExecutorExt::new(spawner));
|
||||
|
||||
let mut ext = ValidationExternalities(extensions);
|
||||
|
||||
|
||||
@@ -19,11 +19,12 @@
|
||||
use std::{process, env, sync::Arc, sync::atomic};
|
||||
use codec::{Decode, Encode};
|
||||
use crate::primitives::{ValidationParams, ValidationResult};
|
||||
use super::{validate_candidate_internal, Error};
|
||||
use super::{MAX_CODE_MEM, MAX_RUNTIME_MEM};
|
||||
use super::{validate_candidate_internal, Error, MAX_CODE_MEM, MAX_RUNTIME_MEM};
|
||||
use shared_memory::{SharedMem, SharedMemConf, EventState, WriteLockable, EventWait, EventSet};
|
||||
use parking_lot::Mutex;
|
||||
use log::{debug, trace};
|
||||
use futures::executor::ThreadPool;
|
||||
use sp_core::traits::SpawnNamed;
|
||||
|
||||
const WORKER_ARGS_TEST: &[&'static str] = &["--nocapture", "validation_worker"];
|
||||
/// CLI Argument to start in validation worker mode.
|
||||
@@ -43,6 +44,25 @@ enum Event {
|
||||
WorkerReady = 2,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct TaskExecutor(ThreadPool);
|
||||
|
||||
impl TaskExecutor {
|
||||
fn new() -> Result<Self, String> {
|
||||
ThreadPool::new().map_err(|e| e.to_string()).map(Self)
|
||||
}
|
||||
}
|
||||
|
||||
impl SpawnNamed for TaskExecutor {
|
||||
fn spawn_blocking(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
|
||||
self.0.spawn_ok(future);
|
||||
}
|
||||
|
||||
fn spawn(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
|
||||
self.0.spawn_ok(future);
|
||||
}
|
||||
}
|
||||
|
||||
/// A pool of hosts.
|
||||
#[derive(Clone)]
|
||||
pub struct ValidationPool {
|
||||
@@ -92,6 +112,7 @@ pub fn run_worker(mem_id: &str) -> Result<(), String> {
|
||||
};
|
||||
|
||||
let exit = Arc::new(atomic::AtomicBool::new(false));
|
||||
let task_executor = TaskExecutor::new()?;
|
||||
// spawn parent monitor thread
|
||||
let watch_exit = exit.clone();
|
||||
std::thread::spawn(move || {
|
||||
@@ -139,7 +160,7 @@ pub fn run_worker(mem_id: &str) -> Result<(), String> {
|
||||
let (call_data, _) = rest.split_at_mut(MAX_RUNTIME_MEM);
|
||||
let (call_data, _) = call_data.split_at_mut(header.params_size as usize);
|
||||
|
||||
let result = validate_candidate_internal(code, call_data);
|
||||
let result = validate_candidate_internal(code, call_data, task_executor.clone());
|
||||
debug!("{} Candidate validated: {:?}", process::id(), result);
|
||||
|
||||
match result {
|
||||
|
||||
@@ -14,6 +14,9 @@ adder = { package = "test-parachain-adder", path = "adder" }
|
||||
halt = { package = "test-parachain-halt", path = "halt" }
|
||||
code-upgrader = { package = "test-parachain-code-upgrader", path = "code-upgrader" }
|
||||
|
||||
[dev-dependencies]
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
[features]
|
||||
default = [ "std" ]
|
||||
std = [
|
||||
|
||||
@@ -78,6 +78,7 @@ pub fn execute_good_on_parent() {
|
||||
code_upgrade_allowed: None,
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
).unwrap();
|
||||
|
||||
let new_head = HeadData::decode(&mut &ret.head_data.0[..]).unwrap();
|
||||
@@ -117,6 +118,7 @@ fn execute_good_chain_on_parent() {
|
||||
code_upgrade_allowed: None,
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
).unwrap();
|
||||
|
||||
let new_head = HeadData::decode(&mut &ret.head_data.0[..]).unwrap();
|
||||
@@ -157,5 +159,6 @@ fn execute_bad_on_parent() {
|
||||
code_upgrade_allowed: None,
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
).unwrap_err();
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ pub fn execute_good_no_upgrade() {
|
||||
code_upgrade_allowed: None,
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
).unwrap();
|
||||
|
||||
let new_head = HeadData::decode(&mut &ret.head_data.0[..]).unwrap();
|
||||
@@ -86,6 +87,7 @@ pub fn execute_good_with_upgrade() {
|
||||
code_upgrade_allowed: Some(20),
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
).unwrap();
|
||||
|
||||
let new_head = HeadData::decode(&mut &ret.head_data.0[..]).unwrap();
|
||||
@@ -129,6 +131,7 @@ pub fn code_upgrade_not_allowed() {
|
||||
code_upgrade_allowed: None,
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
@@ -159,6 +162,7 @@ pub fn applies_code_upgrade_after_delay() {
|
||||
code_upgrade_allowed: Some(2),
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
).unwrap();
|
||||
|
||||
let new_head = HeadData::decode(&mut &ret.head_data.0[..]).unwrap();
|
||||
@@ -194,6 +198,7 @@ pub fn applies_code_upgrade_after_delay() {
|
||||
code_upgrade_allowed: None,
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
).unwrap();
|
||||
|
||||
let new_head = HeadData::decode(&mut &ret.head_data.0[..]).unwrap();
|
||||
|
||||
@@ -37,6 +37,7 @@ fn terminates_on_timeout() {
|
||||
code_upgrade_allowed: None,
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
);
|
||||
match result {
|
||||
Err(parachain::wasm_executor::Error::Timeout) => {},
|
||||
@@ -66,6 +67,7 @@ fn parallel_execution() {
|
||||
code_upgrade_allowed: None,
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool2),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
).ok());
|
||||
let _ = parachain::wasm_executor::validate_candidate(
|
||||
halt::wasm_binary_unwrap(),
|
||||
@@ -78,6 +80,7 @@ fn parallel_execution() {
|
||||
code_upgrade_allowed: None,
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
);
|
||||
thread.join().unwrap();
|
||||
// total time should be < 2 x EXECUTION_TIMEOUT_SEC
|
||||
|
||||
Reference in New Issue
Block a user