mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
Make ValidationPool accepts execution mode to run custom command or in process validation (#1622)
* Initial commit Forked at:cc19f13468Parent branch: origin/master * Propagate test mode all the way down to ValidationPool * Update validation/src/validation_service/mod.rs * Fix test * WIP Forked at:cc19f13468Parent branch: origin/master * Update service/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Adapt code to review suggestions * Run validation inside the same process * Add test * CLEANUP Forked at:cc19f13468Parent branch: origin/master Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -16,11 +16,16 @@
|
||||
|
||||
//! Basic parachain that adds a number as part of its state.
|
||||
|
||||
use parachain::primitives::{
|
||||
RelayChainBlockNumber,
|
||||
BlockData as GenericBlockData,
|
||||
HeadData as GenericHeadData,
|
||||
ValidationParams,
|
||||
const WORKER_ARGS_TEST: &[&'static str] = &["--nocapture", "validation_worker"];
|
||||
|
||||
use parachain::{
|
||||
primitives::{
|
||||
RelayChainBlockNumber,
|
||||
BlockData as GenericBlockData,
|
||||
HeadData as GenericHeadData,
|
||||
ValidationParams,
|
||||
},
|
||||
wasm_executor::{ValidationPool, ValidationExecutionMode}
|
||||
};
|
||||
use codec::{Decode, Encode};
|
||||
|
||||
@@ -52,8 +57,28 @@ fn hash_head(head: &HeadData) -> [u8; 32] {
|
||||
tiny_keccak::keccak256(head.encode().as_slice())
|
||||
}
|
||||
|
||||
fn validation_pool() -> ValidationPool {
|
||||
let execution_mode = ValidationExecutionMode::ExternalProcessCustomHost {
|
||||
binary: std::env::current_exe().unwrap(),
|
||||
args: WORKER_ARGS_TEST.iter().map(|x| x.to_string()).collect(),
|
||||
};
|
||||
|
||||
ValidationPool::new(execution_mode)
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn execute_good_on_parent() {
|
||||
fn execute_good_on_parent_with_inprocess_validation() {
|
||||
let pool = ValidationPool::new(ValidationExecutionMode::InProcess);
|
||||
execute_good_on_parent(pool);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn execute_good_on_parent_with_external_process_validation() {
|
||||
let pool = validation_pool();
|
||||
execute_good_on_parent(pool);
|
||||
}
|
||||
|
||||
fn execute_good_on_parent(pool: ValidationPool) {
|
||||
let parent_head = HeadData {
|
||||
number: 0,
|
||||
parent_hash: [0; 32],
|
||||
@@ -65,7 +90,6 @@ pub fn execute_good_on_parent() {
|
||||
add: 512,
|
||||
};
|
||||
|
||||
let pool = parachain::wasm_executor::ValidationPool::new();
|
||||
|
||||
let ret = parachain::wasm_executor::validate_candidate(
|
||||
adder::wasm_binary_unwrap(),
|
||||
@@ -75,7 +99,7 @@ pub fn execute_good_on_parent() {
|
||||
relay_chain_height: 1,
|
||||
hrmp_mqc_heads: Vec::new(),
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
|
||||
parachain::wasm_executor::ExecutionMode::Remote(&pool),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
).unwrap();
|
||||
|
||||
@@ -91,7 +115,7 @@ fn execute_good_chain_on_parent() {
|
||||
let mut number = 0;
|
||||
let mut parent_hash = [0; 32];
|
||||
let mut last_state = 0;
|
||||
let pool = parachain::wasm_executor::ValidationPool::new();
|
||||
let pool = validation_pool();
|
||||
|
||||
for add in 0..10 {
|
||||
let parent_head = HeadData {
|
||||
@@ -113,7 +137,7 @@ fn execute_good_chain_on_parent() {
|
||||
relay_chain_height: number as RelayChainBlockNumber + 1,
|
||||
hrmp_mqc_heads: Vec::new(),
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
|
||||
parachain::wasm_executor::ExecutionMode::Remote(&pool),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
).unwrap();
|
||||
|
||||
@@ -131,7 +155,7 @@ fn execute_good_chain_on_parent() {
|
||||
|
||||
#[test]
|
||||
fn execute_bad_on_parent() {
|
||||
let pool = parachain::wasm_executor::ValidationPool::new();
|
||||
let pool = validation_pool();
|
||||
|
||||
let parent_head = HeadData {
|
||||
number: 0,
|
||||
@@ -152,7 +176,7 @@ fn execute_bad_on_parent() {
|
||||
relay_chain_height: 1,
|
||||
hrmp_mqc_heads: Vec::new(),
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
|
||||
parachain::wasm_executor::ExecutionMode::Remote(&pool),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
).unwrap_err();
|
||||
}
|
||||
|
||||
@@ -16,15 +16,26 @@
|
||||
|
||||
//! Basic parachain that adds a number as part of its state.
|
||||
|
||||
const WORKER_ARGS_TEST: &[&'static str] = &["--nocapture", "validation_worker"];
|
||||
|
||||
use crate::adder;
|
||||
use parachain::{
|
||||
primitives::{BlockData, ValidationParams},
|
||||
wasm_executor::{ValidationError, InvalidCandidate, EXECUTION_TIMEOUT_SEC},
|
||||
wasm_executor::{ValidationError, InvalidCandidate, EXECUTION_TIMEOUT_SEC, ValidationExecutionMode, ValidationPool},
|
||||
};
|
||||
|
||||
fn validation_pool() -> ValidationPool {
|
||||
let execution_mode = ValidationExecutionMode::ExternalProcessCustomHost {
|
||||
binary: std::env::current_exe().unwrap(),
|
||||
args: WORKER_ARGS_TEST.iter().map(|x| x.to_string()).collect(),
|
||||
};
|
||||
|
||||
ValidationPool::new(execution_mode)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn terminates_on_timeout() {
|
||||
let pool = parachain::wasm_executor::ValidationPool::new();
|
||||
let pool = validation_pool();
|
||||
|
||||
let result = parachain::wasm_executor::validate_candidate(
|
||||
halt::wasm_binary_unwrap(),
|
||||
@@ -34,7 +45,7 @@ fn terminates_on_timeout() {
|
||||
relay_chain_height: 1,
|
||||
hrmp_mqc_heads: Vec::new(),
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
|
||||
parachain::wasm_executor::ExecutionMode::Remote(&pool),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
);
|
||||
match result {
|
||||
@@ -43,12 +54,12 @@ fn terminates_on_timeout() {
|
||||
}
|
||||
|
||||
// check that another parachain can validate normaly
|
||||
adder::execute_good_on_parent();
|
||||
adder::execute_good_on_parent_with_external_process_validation();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parallel_execution() {
|
||||
let pool = parachain::wasm_executor::ValidationPool::new();
|
||||
let pool = validation_pool();
|
||||
|
||||
let start = std::time::Instant::now();
|
||||
|
||||
@@ -62,7 +73,7 @@ fn parallel_execution() {
|
||||
relay_chain_height: 1,
|
||||
hrmp_mqc_heads: Vec::new(),
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool2),
|
||||
parachain::wasm_executor::ExecutionMode::Remote(&pool2),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
).ok());
|
||||
let _ = parachain::wasm_executor::validate_candidate(
|
||||
@@ -73,7 +84,7 @@ fn parallel_execution() {
|
||||
relay_chain_height: 1,
|
||||
hrmp_mqc_heads: Vec::new(),
|
||||
},
|
||||
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
|
||||
parachain::wasm_executor::ExecutionMode::Remote(&pool),
|
||||
sp_core::testing::TaskExecutor::new(),
|
||||
);
|
||||
thread.join().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user