mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 00:31:02 +00:00
* Companion for #6726 * Spaces * 'Update substrate' Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user