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

Companion for #6726 #1469

Merged
3 commits merged into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 3 additions & 16 deletions network/src/protocol/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,12 @@ use av_store::{Store as AvailabilityStore, ErasureNetworking};
use sc_network_gossip::TopicNotification;
use sp_api::{ApiRef, ProvideRuntimeApi};
use sp_runtime::traits::Block as BlockT;
use sp_core::{crypto::Pair, traits::SpawnNamed};
use sp_core::{crypto::Pair, testing::TaskExecutor};
use sp_keyring::Sr25519Keyring;

use futures::executor::{LocalPool, LocalSpawner};
use futures::executor::LocalPool;
use futures::task::{LocalSpawnExt, SpawnExt};

#[derive(Clone)]
struct Executor(LocalSpawner);

impl SpawnNamed for Executor {
fn spawn(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
self.0.spawn_local(future).unwrap();
}

fn spawn_blocking(&self, name: &'static str, future: futures::future::BoxFuture<'static, ()>) {
self.spawn(name, future);
}
}

#[derive(Default)]
pub struct MockNetworkOps {
recorded: Mutex<Recorded>,
Expand Down Expand Up @@ -256,7 +243,7 @@ fn test_setup(config: Config) -> (
mock_gossip.clone(),
api.clone(),
worker_rx,
Executor(pool.spawner()),
TaskExecutor::new(),
);

let service = Service {
Expand Down
2 changes: 1 addition & 1 deletion network/test/src/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn import_single_good_block_without_header_fails() {

#[test]
fn async_import_queue_drops() {
let executor = sp_core::testing::SpawnBlockingExecutor::new();
let executor = sp_core::testing::TaskExecutor::new();
// Perform this test multiple times since it exhibits non-deterministic behavior.
for _ in 0..100 {
let verifier = PassThroughVerifier::new(true);
Expand Down
4 changes: 2 additions & 2 deletions network/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ pub trait TestNetFactory: Sized {
Box::new(block_import.clone()),
justification_import,
finality_proof_import,
&sp_core::testing::SpawnBlockingExecutor::new(),
&sp_core::testing::TaskExecutor::new(),
None,
));

Expand Down Expand Up @@ -650,7 +650,7 @@ pub trait TestNetFactory: Sized {
Box::new(block_import.clone()),
justification_import,
finality_proof_import,
&sp_core::testing::SpawnBlockingExecutor::new(),
&sp_core::testing::TaskExecutor::new(),
None,
));

Expand Down
2 changes: 1 addition & 1 deletion node/core/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ mod tests {
}

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

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

Expand Down
10 changes: 5 additions & 5 deletions node/network/bitfield-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ mod test {
signed_availability: signed.clone(),
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) =
make_subsystem_context::<BitfieldDistributionMessage, _>(pool);

Expand Down Expand Up @@ -766,7 +766,7 @@ mod test {
signed_availability: signed.clone(),
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) =
make_subsystem_context::<BitfieldDistributionMessage, _>(pool);

Expand Down Expand Up @@ -818,7 +818,7 @@ mod test {
signed_availability: signed_bitfield.clone(),
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) =
make_subsystem_context::<BitfieldDistributionMessage, _>(pool);

Expand Down Expand Up @@ -915,7 +915,7 @@ mod test {
signed_availability: signed_bitfield.clone(),
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) =
make_subsystem_context::<BitfieldDistributionMessage, _>(pool);

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

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) =
make_subsystem_context::<BitfieldDistributionMessage, _>(pool);

Expand Down
2 changes: 1 addition & 1 deletion node/network/bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ mod tests {
}

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

Expand Down
24 changes: 12 additions & 12 deletions node/network/pov-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ mod tests {
our_view: View(vec![hash_a, hash_b]),
};

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

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

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
Expand Down Expand Up @@ -849,7 +849,7 @@ mod tests {
our_view: View(vec![hash_a]),
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
Expand Down Expand Up @@ -937,7 +937,7 @@ mod tests {
our_view: View(vec![hash_a]),
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
Expand Down Expand Up @@ -1000,7 +1000,7 @@ mod tests {
our_view: View(vec![hash_a]),
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
Expand Down Expand Up @@ -1061,7 +1061,7 @@ mod tests {
our_view: View(vec![hash_a]),
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
Expand Down Expand Up @@ -1119,7 +1119,7 @@ mod tests {
our_view: View(vec![hash_a]),
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
Expand Down Expand Up @@ -1204,7 +1204,7 @@ mod tests {
our_view: View(vec![hash_a, hash_b]),
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
Expand Down Expand Up @@ -1266,7 +1266,7 @@ mod tests {
our_view: View(vec![hash_a]),
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
Expand Down Expand Up @@ -1343,7 +1343,7 @@ mod tests {
our_view: View(vec![hash_a]),
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
Expand Down Expand Up @@ -1426,7 +1426,7 @@ mod tests {
our_view: View(vec![hash_a]),
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
Expand Down
4 changes: 2 additions & 2 deletions node/network/statement-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ mod tests {
},
};

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);
let peer = PeerId::random();

Expand Down Expand Up @@ -1304,7 +1304,7 @@ mod tests {
(peer_c.clone(), peer_data_from_view(peer_c_view)),
].into_iter().collect();

let pool = sp_core::testing::SpawnBlockingExecutor::new();
let pool = sp_core::testing::TaskExecutor::new();
let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool);

executor::block_on(async move {
Expand Down
2 changes: 1 addition & 1 deletion node/overseer/examples/minimal-example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl<C> Subsystem<C> for Subsystem2

fn main() {
femme::with_level(femme::LevelFilter::Trace);
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
let spawner = sp_core::testing::TaskExecutor::new();
futures::executor::block_on(async {
let timer_stream = stream::repeat(()).then(|_| async {
Delay::new(Duration::from_secs(1)).await;
Expand Down
10 changes: 5 additions & 5 deletions node/overseer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ where
/// }
///
/// # fn main() { executor::block_on(async move {
/// let spawner = sp_core::testing::SpawnBlockingExecutor::new();
/// let spawner = sp_core::testing::TaskExecutor::new();
/// let all_subsystems = AllSubsystems {
/// candidate_validation: ValidationSubsystem,
/// candidate_backing: DummySubsystem,
Expand Down Expand Up @@ -1058,7 +1058,7 @@ mod tests {
// Checks that a minimal configuration of two jobs can run and exchange messages.
#[test]
fn overseer_works() {
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
let spawner = sp_core::testing::TaskExecutor::new();

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

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

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

executor::block_on(async move {
let first_block_hash = [1; 32].into();
Expand Down
2 changes: 1 addition & 1 deletion node/subsystem/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ mod tests {
type OverseerHandle = test_helpers::TestSubsystemContextHandle<CandidateSelectionMessage>;

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

Expand Down
2 changes: 2 additions & 0 deletions parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -43,4 +44,5 @@ std = [
"sc-executor",
"sp-io",
"polkadot-core-primitives/std",
"futures",
]
9 changes: 5 additions & 4 deletions parachain/src/wasm_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _;

Expand Down Expand Up @@ -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, &params.encode())
validate_candidate_internal(validation_code, &params.encode(), spawner)
},
#[cfg(not(any(target_os = "android", target_os = "unknown")))]
ExecutionMode::Remote(pool) => {
Expand Down Expand Up @@ -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);

Expand Down
Loading