Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 8c880f7

Browse files
committed
Propagate test mode all the way down to ValidationPool
1 parent d32b42a commit 8c880f7

File tree

7 files changed

+28
-29
lines changed

7 files changed

+28
-29
lines changed

node/core/candidate-validation/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async fn run(
128128
)
129129
-> SubsystemResult<()>
130130
{
131-
let pool = ValidationPool::new();
131+
let pool = ValidationPool::new(false);
132132

133133
loop {
134134
match ctx.recv().await? {

parachain/src/wasm_executor/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ pub enum ExecutionMode<'a> {
6666
Local,
6767
/// Remote execution in a spawned process.
6868
Remote(&'a ValidationPool),
69-
/// Remote execution in a spawned test runner.
70-
RemoteTest(&'a ValidationPool),
7169
}
7270

7371
#[derive(Debug, derive_more::Display, derive_more::From)]
@@ -143,11 +141,7 @@ pub fn validate_candidate(
143141
},
144142
#[cfg(not(any(target_os = "android", target_os = "unknown")))]
145143
ExecutionMode::Remote(pool) => {
146-
pool.validate_candidate(validation_code, params, false)
147-
},
148-
#[cfg(not(any(target_os = "android", target_os = "unknown")))]
149-
ExecutionMode::RemoteTest(pool) => {
150-
pool.validate_candidate(validation_code, params, true)
144+
pool.validate_candidate(validation_code, params)
151145
},
152146
#[cfg(any(target_os = "android", target_os = "unknown"))]
153147
ExecutionMode::Remote(_pool) =>

parachain/src/wasm_executor/validation_host.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,17 @@ impl SpawnNamed for TaskExecutor {
7070
#[derive(Clone)]
7171
pub struct ValidationPool {
7272
hosts: Arc<Vec<Mutex<ValidationHost>>>,
73+
test_mode: bool,
7374
}
7475

7576
const DEFAULT_NUM_HOSTS: usize = 8;
7677

7778
impl ValidationPool {
7879
/// Creates a validation pool with the default configuration.
79-
pub fn new() -> ValidationPool {
80+
pub fn new(test_mode: bool) -> ValidationPool {
8081
ValidationPool {
8182
hosts: Arc::new((0..DEFAULT_NUM_HOSTS).map(|_| Default::default()).collect()),
83+
test_mode,
8284
}
8385
}
8486

@@ -90,16 +92,15 @@ impl ValidationPool {
9092
&self,
9193
validation_code: &[u8],
9294
params: ValidationParams,
93-
test_mode: bool,
9495
) -> Result<ValidationResult, ValidationError> {
9596
for host in self.hosts.iter() {
9697
if let Some(mut host) = host.try_lock() {
97-
return host.validate_candidate(validation_code, params, test_mode);
98+
return host.validate_candidate(validation_code, params, self.test_mode);
9899
}
99100
}
100101

101102
// all workers are busy, just wait for the first one
102-
self.hosts[0].lock().validate_candidate(validation_code, params, test_mode)
103+
self.hosts[0].lock().validate_candidate(validation_code, params, self.test_mode)
103104
}
104105
}
105106

parachain/test-parachains/tests/adder/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn execute_good_on_parent() {
6565
add: 512,
6666
};
6767

68-
let pool = parachain::wasm_executor::ValidationPool::new();
68+
let pool = parachain::wasm_executor::ValidationPool::new(true);
6969

7070
let ret = parachain::wasm_executor::validate_candidate(
7171
adder::wasm_binary_unwrap(),
@@ -75,7 +75,7 @@ pub fn execute_good_on_parent() {
7575
relay_chain_height: 1,
7676
hrmp_mqc_heads: Vec::new(),
7777
},
78-
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
78+
parachain::wasm_executor::ExecutionMode::Remote(&pool),
7979
sp_core::testing::TaskExecutor::new(),
8080
).unwrap();
8181

@@ -91,7 +91,7 @@ fn execute_good_chain_on_parent() {
9191
let mut number = 0;
9292
let mut parent_hash = [0; 32];
9393
let mut last_state = 0;
94-
let pool = parachain::wasm_executor::ValidationPool::new();
94+
let pool = parachain::wasm_executor::ValidationPool::new(true);
9595

9696
for add in 0..10 {
9797
let parent_head = HeadData {
@@ -113,7 +113,7 @@ fn execute_good_chain_on_parent() {
113113
relay_chain_height: number as RelayChainBlockNumber + 1,
114114
hrmp_mqc_heads: Vec::new(),
115115
},
116-
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
116+
parachain::wasm_executor::ExecutionMode::Remote(&pool),
117117
sp_core::testing::TaskExecutor::new(),
118118
).unwrap();
119119

@@ -131,7 +131,7 @@ fn execute_good_chain_on_parent() {
131131

132132
#[test]
133133
fn execute_bad_on_parent() {
134-
let pool = parachain::wasm_executor::ValidationPool::new();
134+
let pool = parachain::wasm_executor::ValidationPool::new(true);
135135

136136
let parent_head = HeadData {
137137
number: 0,
@@ -152,7 +152,7 @@ fn execute_bad_on_parent() {
152152
relay_chain_height: 1,
153153
hrmp_mqc_heads: Vec::new(),
154154
},
155-
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
155+
parachain::wasm_executor::ExecutionMode::Remote(&pool),
156156
sp_core::testing::TaskExecutor::new(),
157157
).unwrap_err();
158158
}

parachain/test-parachains/tests/wasm_executor/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use parachain::{
2424

2525
#[test]
2626
fn terminates_on_timeout() {
27-
let pool = parachain::wasm_executor::ValidationPool::new();
27+
let pool = parachain::wasm_executor::ValidationPool::new(true);
2828

2929
let result = parachain::wasm_executor::validate_candidate(
3030
halt::wasm_binary_unwrap(),
@@ -34,7 +34,7 @@ fn terminates_on_timeout() {
3434
relay_chain_height: 1,
3535
hrmp_mqc_heads: Vec::new(),
3636
},
37-
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
37+
parachain::wasm_executor::ExecutionMode::Remote(&pool),
3838
sp_core::testing::TaskExecutor::new(),
3939
);
4040
match result {
@@ -48,7 +48,7 @@ fn terminates_on_timeout() {
4848

4949
#[test]
5050
fn parallel_execution() {
51-
let pool = parachain::wasm_executor::ValidationPool::new();
51+
let pool = parachain::wasm_executor::ValidationPool::new(true);
5252

5353
let start = std::time::Instant::now();
5454

@@ -62,7 +62,7 @@ fn parallel_execution() {
6262
relay_chain_height: 1,
6363
hrmp_mqc_heads: Vec::new(),
6464
},
65-
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool2),
65+
parachain::wasm_executor::ExecutionMode::Remote(&pool2),
6666
sp_core::testing::TaskExecutor::new(),
6767
).ok());
6868
let _ = parachain::wasm_executor::validate_candidate(
@@ -73,7 +73,7 @@ fn parallel_execution() {
7373
relay_chain_height: 1,
7474
hrmp_mqc_heads: Vec::new(),
7575
},
76-
parachain::wasm_executor::ExecutionMode::RemoteTest(&pool),
76+
parachain::wasm_executor::ExecutionMode::Remote(&pool),
7777
sp_core::testing::TaskExecutor::new(),
7878
);
7979
thread.join().unwrap();

service/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub type LightClient<RuntimeApi, Executor> =
117117
service::TLightClientWithBackend<Block, RuntimeApi, Executor, LightBackend>;
118118

119119
#[cfg(feature = "full-node")]
120-
pub fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, test: bool) -> Result<
120+
pub fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, test_mode: bool) -> Result<
121121
service::PartialComponents<
122122
FullClient<RuntimeApi, Executor>, FullBackend, FullSelectChain,
123123
consensus_common::DefaultImportQueue<Block, FullClient<RuntimeApi, Executor>>,
@@ -142,7 +142,7 @@ pub fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, test: bool)
142142
RuntimeApiCollection<StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
143143
Executor: NativeExecutionDispatch + 'static,
144144
{
145-
if !test {
145+
if !test_mode {
146146
// If we're using prometheus, use a registry with a prefix of `polkadot`.
147147
if let Some(PrometheusConfig { registry, .. }) = config.prometheus_config.as_mut() {
148148
*registry = Registry::new_custom(Some("polkadot".into()), None)?;
@@ -164,7 +164,7 @@ pub fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, test: bool)
164164
client.clone(),
165165
);
166166

167-
let grandpa_hard_forks = if config.chain_spec.is_kusama() && !test {
167+
let grandpa_hard_forks = if config.chain_spec.is_kusama() && !test_mode {
168168
crate::grandpa_support::kusama_hard_forks()
169169
} else {
170170
Vec::new()
@@ -253,7 +253,7 @@ pub fn new_full<RuntimeApi, Executor>(
253253
authority_discovery_enabled: bool,
254254
slot_duration: u64,
255255
grandpa_pause: Option<(u32, u32)>,
256-
test: bool,
256+
test_mode: bool,
257257
) -> Result<(
258258
TaskManager,
259259
Arc<FullClient<RuntimeApi, Executor>>,
@@ -286,7 +286,7 @@ pub fn new_full<RuntimeApi, Executor>(
286286
client, backend, mut task_manager, keystore, select_chain, import_queue, transaction_pool,
287287
inherent_data_providers,
288288
other: (rpc_extensions_builder, import_setup, rpc_setup)
289-
} = new_partial::<RuntimeApi, Executor>(&mut config, test)?;
289+
} = new_partial::<RuntimeApi, Executor>(&mut config, test_mode)?;
290290

291291
let prometheus_registry = config.prometheus_registry().cloned();
292292

@@ -400,6 +400,7 @@ pub fn new_full<RuntimeApi, Executor>(
400400
select_chain: select_chain.clone(),
401401
keystore: keystore.clone(),
402402
max_block_data_size,
403+
test_mode,
403404
}.build();
404405

405406
task_manager.spawn_essential_handle().spawn("validation-service", Box::pin(validation_service));

validation/src/validation_service/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ pub struct ServiceBuilder<C, N, P, SC, SP> {
132132
pub keystore: KeyStorePtr,
133133
/// The maximum block-data size in bytes.
134134
pub max_block_data_size: Option<u64>,
135+
/// The validation worker is called on the same process using the subcommand `--nocapture validation_worker` instead
136+
/// of `validation-worker`, suitable for test environment.
137+
pub test_mode: bool,
135138
}
136139

137140
impl<C, N, P, SC, SP> ServiceBuilder<C, N, P, SC, SP> where
@@ -163,7 +166,7 @@ impl<C, N, P, SC, SP> ServiceBuilder<C, N, P, SC, SP> where
163166
NotifyImport(sc_client_api::BlockImportNotification<Block>),
164167
}
165168

166-
let validation_pool = Some(ValidationPool::new());
169+
let validation_pool = Some(ValidationPool::new(self.test_mode));
167170
let mut parachain_validation = ParachainValidationInstances {
168171
client: self.client.clone(),
169172
network: self.network,

0 commit comments

Comments
 (0)