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

Commit f25628a

Browse files
authored
Companion for #6726 (#1469)
* Companion for #6726 * Spaces * 'Update substrate' Co-authored-by: parity-processbot <>
1 parent c206b36 commit f25628a

File tree

24 files changed

+278
-204
lines changed

24 files changed

+278
-204
lines changed

Cargo.lock

+168-138
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

network/src/protocol/tests.rs

+3-16
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,12 @@ use av_store::{Store as AvailabilityStore, ErasureNetworking};
3030
use sc_network_gossip::TopicNotification;
3131
use sp_api::{ApiRef, ProvideRuntimeApi};
3232
use sp_runtime::traits::Block as BlockT;
33-
use sp_core::{crypto::Pair, traits::SpawnNamed};
33+
use sp_core::{crypto::Pair, testing::TaskExecutor};
3434
use sp_keyring::Sr25519Keyring;
3535

36-
use futures::executor::{LocalPool, LocalSpawner};
36+
use futures::executor::LocalPool;
3737
use futures::task::{LocalSpawnExt, SpawnExt};
3838

39-
#[derive(Clone)]
40-
struct Executor(LocalSpawner);
41-
42-
impl SpawnNamed for Executor {
43-
fn spawn(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
44-
self.0.spawn_local(future).unwrap();
45-
}
46-
47-
fn spawn_blocking(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>) {
48-
self.spawn(name, future);
49-
}
50-
}
51-
5239
#[derive(Default)]
5340
pub struct MockNetworkOps {
5441
recorded: Mutex<Recorded>,
@@ -256,7 +243,7 @@ fn test_setup(config: Config) -> (
256243
mock_gossip.clone(),
257244
api.clone(),
258245
worker_rx,
259-
Executor(pool.spawner()),
246+
TaskExecutor::new(),
260247
);
261248

262249
let service = Service {

network/test/src/block_import.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn import_single_good_block_without_header_fails() {
8888

8989
#[test]
9090
fn async_import_queue_drops() {
91-
let executor = sp_core::testing::SpawnBlockingExecutor::new();
91+
let executor = sp_core::testing::TaskExecutor::new();
9292
// Perform this test multiple times since it exhibits non-deterministic behavior.
9393
for _ in 0..100 {
9494
let verifier = PassThroughVerifier::new(true);

network/test/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ pub trait TestNetFactory: Sized {
573573
Box::new(block_import.clone()),
574574
justification_import,
575575
finality_proof_import,
576-
&sp_core::testing::SpawnBlockingExecutor::new(),
576+
&sp_core::testing::TaskExecutor::new(),
577577
None,
578578
));
579579

@@ -650,7 +650,7 @@ pub trait TestNetFactory: Sized {
650650
Box::new(block_import.clone()),
651651
justification_import,
652652
finality_proof_import,
653-
&sp_core::testing::SpawnBlockingExecutor::new(),
653+
&sp_core::testing::TaskExecutor::new(),
654654
None,
655655
));
656656

node/core/backing/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ mod tests {
903903
}
904904

905905
fn test_harness<T: Future<Output=()>>(keystore: KeyStorePtr, test: impl FnOnce(TestHarness) -> T) {
906-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
906+
let pool = sp_core::testing::TaskExecutor::new();
907907

908908
let (context, virtual_overseer) = polkadot_subsystem::test_helpers::make_subsystem_context(pool.clone());
909909

node/network/bitfield-distribution/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ mod test {
706706
signed_availability: signed.clone(),
707707
};
708708

709-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
709+
let pool = sp_core::testing::TaskExecutor::new();
710710
let (mut ctx, mut handle) =
711711
make_subsystem_context::<BitfieldDistributionMessage, _>(pool);
712712

@@ -766,7 +766,7 @@ mod test {
766766
signed_availability: signed.clone(),
767767
};
768768

769-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
769+
let pool = sp_core::testing::TaskExecutor::new();
770770
let (mut ctx, mut handle) =
771771
make_subsystem_context::<BitfieldDistributionMessage, _>(pool);
772772

@@ -818,7 +818,7 @@ mod test {
818818
signed_availability: signed_bitfield.clone(),
819819
};
820820

821-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
821+
let pool = sp_core::testing::TaskExecutor::new();
822822
let (mut ctx, mut handle) =
823823
make_subsystem_context::<BitfieldDistributionMessage, _>(pool);
824824

@@ -915,7 +915,7 @@ mod test {
915915
signed_availability: signed_bitfield.clone(),
916916
};
917917

918-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
918+
let pool = sp_core::testing::TaskExecutor::new();
919919
let (mut ctx, mut handle) =
920920
make_subsystem_context::<BitfieldDistributionMessage, _>(pool);
921921

@@ -1052,7 +1052,7 @@ mod test {
10521052
// validator 0 key pair
10531053
let (mut state, _signing_context, _validator_pair) = state_with_view(view![], hash_a.clone());
10541054

1055-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
1055+
let pool = sp_core::testing::TaskExecutor::new();
10561056
let (mut ctx, mut handle) =
10571057
make_subsystem_context::<BitfieldDistributionMessage, _>(pool);
10581058

node/network/bridge/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ mod tests {
635635
}
636636

637637
fn test_harness<T: Future<Output=()>>(test: impl FnOnce(TestHarness) -> T) {
638-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
638+
let pool = sp_core::testing::TaskExecutor::new();
639639
let (network, network_handle) = new_test_network();
640640
let (context, virtual_overseer) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
641641

node/network/pov-distribution/src/lib.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ mod tests {
619619
our_view: View(vec![hash_a, hash_b]),
620620
};
621621

622-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
622+
let pool = sp_core::testing::TaskExecutor::new();
623623
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
624624
let mut descriptor = CandidateDescriptor::default();
625625
descriptor.pov_hash = pov_hash;
@@ -699,7 +699,7 @@ mod tests {
699699
our_view: View(vec![hash_a]),
700700
};
701701

702-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
702+
let pool = sp_core::testing::TaskExecutor::new();
703703
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
704704
let mut descriptor = CandidateDescriptor::default();
705705
descriptor.pov_hash = pov_hash;
@@ -777,7 +777,7 @@ mod tests {
777777
our_view: View(vec![hash_a]),
778778
};
779779

780-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
780+
let pool = sp_core::testing::TaskExecutor::new();
781781
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
782782

783783
executor::block_on(async move {
@@ -849,7 +849,7 @@ mod tests {
849849
our_view: View(vec![hash_a]),
850850
};
851851

852-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
852+
let pool = sp_core::testing::TaskExecutor::new();
853853
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
854854

855855
executor::block_on(async move {
@@ -937,7 +937,7 @@ mod tests {
937937
our_view: View(vec![hash_a]),
938938
};
939939

940-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
940+
let pool = sp_core::testing::TaskExecutor::new();
941941
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
942942

943943
executor::block_on(async move {
@@ -1000,7 +1000,7 @@ mod tests {
10001000
our_view: View(vec![hash_a]),
10011001
};
10021002

1003-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
1003+
let pool = sp_core::testing::TaskExecutor::new();
10041004
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
10051005

10061006
executor::block_on(async move {
@@ -1061,7 +1061,7 @@ mod tests {
10611061
our_view: View(vec![hash_a]),
10621062
};
10631063

1064-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
1064+
let pool = sp_core::testing::TaskExecutor::new();
10651065
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
10661066

10671067
executor::block_on(async move {
@@ -1119,7 +1119,7 @@ mod tests {
11191119
our_view: View(vec![hash_a]),
11201120
};
11211121

1122-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
1122+
let pool = sp_core::testing::TaskExecutor::new();
11231123
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
11241124

11251125
executor::block_on(async move {
@@ -1204,7 +1204,7 @@ mod tests {
12041204
our_view: View(vec![hash_a, hash_b]),
12051205
};
12061206

1207-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
1207+
let pool = sp_core::testing::TaskExecutor::new();
12081208
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
12091209

12101210
executor::block_on(async move {
@@ -1266,7 +1266,7 @@ mod tests {
12661266
our_view: View(vec![hash_a]),
12671267
};
12681268

1269-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
1269+
let pool = sp_core::testing::TaskExecutor::new();
12701270
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
12711271

12721272
executor::block_on(async move {
@@ -1343,7 +1343,7 @@ mod tests {
13431343
our_view: View(vec![hash_a]),
13441344
};
13451345

1346-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
1346+
let pool = sp_core::testing::TaskExecutor::new();
13471347
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
13481348

13491349
executor::block_on(async move {
@@ -1426,7 +1426,7 @@ mod tests {
14261426
our_view: View(vec![hash_a]),
14271427
};
14281428

1429-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
1429+
let pool = sp_core::testing::TaskExecutor::new();
14301430
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
14311431

14321432
executor::block_on(async move {

node/network/statement-distribution/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ mod tests {
12121212
},
12131213
};
12141214

1215-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
1215+
let pool = sp_core::testing::TaskExecutor::new();
12161216
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
12171217
let peer = PeerId::random();
12181218

@@ -1304,7 +1304,7 @@ mod tests {
13041304
(peer_c.clone(), peer_data_from_view(peer_c_view)),
13051305
].into_iter().collect();
13061306

1307-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
1307+
let pool = sp_core::testing::TaskExecutor::new();
13081308
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
13091309

13101310
executor::block_on(async move {

node/overseer/examples/minimal-example.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<C> Subsystem<C> for Subsystem2
135135

136136
fn main() {
137137
femme::with_level(femme::LevelFilter::Trace);
138-
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
138+
let spawner = sp_core::testing::TaskExecutor::new();
139139
futures::executor::block_on(async {
140140
let timer_stream = stream::repeat(()).then(|_| async {
141141
Delay::new(Duration::from_secs(1)).await;

node/overseer/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ where
485485
/// }
486486
///
487487
/// # fn main() { executor::block_on(async move {
488-
/// let spawner = sp_core::testing::SpawnBlockingExecutor::new();
488+
/// let spawner = sp_core::testing::TaskExecutor::new();
489489
/// let all_subsystems = AllSubsystems {
490490
/// candidate_validation: ValidationSubsystem,
491491
/// candidate_backing: DummySubsystem,
@@ -1058,7 +1058,7 @@ mod tests {
10581058
// Checks that a minimal configuration of two jobs can run and exchange messages.
10591059
#[test]
10601060
fn overseer_works() {
1061-
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
1061+
let spawner = sp_core::testing::TaskExecutor::new();
10621062

10631063
executor::block_on(async move {
10641064
let (s1_tx, mut s1_rx) = mpsc::channel(64);
@@ -1123,7 +1123,7 @@ mod tests {
11231123
// Should immediately conclude the overseer itself with an error.
11241124
#[test]
11251125
fn overseer_panics_on_subsystem_exit() {
1126-
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
1126+
let spawner = sp_core::testing::TaskExecutor::new();
11271127

11281128
executor::block_on(async move {
11291129
let (s1_tx, _) = mpsc::channel(64);
@@ -1218,7 +1218,7 @@ mod tests {
12181218
// notifications on imported blocks triggers expected `StartWork` and `StopWork` heartbeats.
12191219
#[test]
12201220
fn overseer_start_stop_works() {
1221-
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
1221+
let spawner = sp_core::testing::TaskExecutor::new();
12221222

12231223
executor::block_on(async move {
12241224
let first_block_hash = [1; 32].into();
@@ -1314,7 +1314,7 @@ mod tests {
13141314
// notifications on imported blocks triggers expected `StartWork` and `StopWork` heartbeats.
13151315
#[test]
13161316
fn overseer_finalize_works() {
1317-
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
1317+
let spawner = sp_core::testing::TaskExecutor::new();
13181318

13191319
executor::block_on(async move {
13201320
let first_block_hash = [1; 32].into();

node/subsystem/src/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ mod tests {
891891
type OverseerHandle = test_helpers::TestSubsystemContextHandle<CandidateSelectionMessage>;
892892

893893
fn test_harness<T: Future<Output=()>>(run_args: HashMap<Hash, Vec<FromJob>>, test: impl FnOnce(OverseerHandle, mpsc::Receiver<(Option<Hash>, JobsError<Error>)>) -> T) {
894-
let pool = sp_core::testing::SpawnBlockingExecutor::new();
894+
let pool = sp_core::testing::TaskExecutor::new();
895895
let (context, overseer_handle) = make_subsystem_context(pool.clone());
896896
let (err_tx, err_rx) = mpsc::channel(16);
897897

parachain/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ sc-executor = { git = "https://github.com/paritytech/substrate", branch = "maste
2323
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
2424
parking_lot = { version = "0.10.0", optional = true }
2525
log = { version = "0.4.8", optional = true }
26+
futures = { version = "0.3.4", optional = true }
2627

2728
[target.'cfg(not(any(target_os = "android", target_os = "unknown")))'.dependencies]
2829
shared_memory = { version = "0.10.0", optional = true }
@@ -43,4 +44,5 @@ std = [
4344
"sc-executor",
4445
"sp-io",
4546
"polkadot-core-primitives/std",
47+
"futures",
4648
]

parachain/src/wasm_executor/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
use std::any::{TypeId, Any};
2424
use crate::primitives::{ValidationParams, ValidationResult};
2525
use codec::{Decode, Encode};
26-
use sp_core::storage::ChildInfo;
27-
use sp_core::traits::CallInWasm;
26+
use sp_core::{storage::ChildInfo, traits::{CallInWasm, SpawnNamed}};
2827
use sp_externalities::Extensions;
2928
use sp_wasm_interface::HostFunctions as _;
3029

@@ -119,10 +118,11 @@ pub fn validate_candidate(
119118
validation_code: &[u8],
120119
params: ValidationParams,
121120
options: ExecutionMode<'_>,
121+
spawner: impl SpawnNamed + 'static,
122122
) -> Result<ValidationResult, Error> {
123123
match options {
124124
ExecutionMode::Local => {
125-
validate_candidate_internal(validation_code, &params.encode())
125+
validate_candidate_internal(validation_code, &params.encode(), spawner)
126126
},
127127
#[cfg(not(any(target_os = "android", target_os = "unknown")))]
128128
ExecutionMode::Remote(pool) => {
@@ -154,9 +154,10 @@ type HostFunctions = sp_io::SubstrateHostFunctions;
154154
pub fn validate_candidate_internal(
155155
validation_code: &[u8],
156156
encoded_call_data: &[u8],
157+
spawner: impl SpawnNamed + 'static,
157158
) -> Result<ValidationResult, Error> {
158159
let mut extensions = Extensions::new();
159-
extensions.register(sp_core::traits::TaskExecutorExt(sp_core::tasks::executor()));
160+
extensions.register(sp_core::traits::TaskExecutorExt::new(spawner));
160161

161162
let mut ext = ValidationExternalities(extensions);
162163

0 commit comments

Comments
 (0)