diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock index 10b016a8dc..6a4606dc70 100644 --- a/polkadot/Cargo.lock +++ b/polkadot/Cargo.lock @@ -4342,6 +4342,7 @@ dependencies = [ "polkadot-network-bridge", "polkadot-node-primitives", "polkadot-node-subsystem", + "polkadot-node-subsystem-test-helpers", "polkadot-primitives", "sc-network", "smol 0.2.0", @@ -4494,6 +4495,7 @@ dependencies = [ "parking_lot 0.10.2", "polkadot-node-primitives", "polkadot-node-subsystem", + "polkadot-node-subsystem-test-helpers", "polkadot-primitives", "sc-network", "sp-core", @@ -4536,6 +4538,7 @@ dependencies = [ "parity-scale-codec", "polkadot-erasure-coding", "polkadot-node-subsystem", + "polkadot-node-subsystem-test-helpers", "polkadot-overseer", "polkadot-primitives", "sp-core", @@ -4553,6 +4556,8 @@ dependencies = [ "polkadot-erasure-coding", "polkadot-node-primitives", "polkadot-node-subsystem", + "polkadot-node-subsystem-test-helpers", + "polkadot-node-subsystem-util", "polkadot-primitives", "polkadot-statement-table", "sc-client-api", @@ -4572,6 +4577,7 @@ dependencies = [ "futures 0.3.5", "log 0.4.8", "polkadot-node-subsystem", + "polkadot-node-subsystem-util", "polkadot-primitives", "sc-keystore", "wasm-timer", @@ -4588,6 +4594,7 @@ dependencies = [ "parity-scale-codec", "polkadot-node-primitives", "polkadot-node-subsystem", + "polkadot-node-subsystem-test-helpers", "polkadot-parachain", "polkadot-primitives", "sp-blockchain", @@ -4602,6 +4609,7 @@ dependencies = [ "futures 0.3.5", "maplit", "polkadot-node-subsystem", + "polkadot-node-subsystem-test-helpers", "polkadot-primitives", "sp-blockchain", "sp-core", @@ -4643,6 +4651,7 @@ dependencies = [ "lazy_static", "log 0.4.8", "polkadot-node-subsystem", + "polkadot-node-subsystem-util", "polkadot-primitives", "sp-core", "tokio 0.2.21", @@ -4655,6 +4664,7 @@ dependencies = [ "futures 0.3.5", "polkadot-node-primitives", "polkadot-node-subsystem", + "polkadot-node-subsystem-test-helpers", "polkadot-primitives", "sp-api", "sp-blockchain", @@ -4665,7 +4675,6 @@ dependencies = [ name = "polkadot-node-primitives" version = "0.1.0" dependencies = [ - "async-trait", "parity-scale-codec", "polkadot-primitives", "polkadot-statement-table", @@ -4687,6 +4696,51 @@ dependencies = [ "parking_lot 0.10.2", "pin-project", "polkadot-node-primitives", + "polkadot-node-subsystem-test-helpers", + "polkadot-primitives", + "polkadot-statement-table", + "sc-network", + "smallvec 1.4.1", + "sp-core", +] + +[[package]] +name = "polkadot-node-subsystem-test-helpers" +version = "0.1.0" +dependencies = [ + "async-trait", + "derive_more 0.99.9", + "futures 0.3.5", + "futures-timer 3.0.2", + "log 0.4.8", + "parity-scale-codec", + "parking_lot 0.10.2", + "pin-project", + "polkadot-node-primitives", + "polkadot-node-subsystem", + "polkadot-primitives", + "polkadot-statement-table", + "sc-network", + "smallvec 1.4.1", + "sp-core", +] + +[[package]] +name = "polkadot-node-subsystem-util" +version = "0.1.0" +dependencies = [ + "assert_matches", + "async-trait", + "derive_more 0.99.9", + "futures 0.3.5", + "futures-timer 3.0.2", + "log 0.4.8", + "parity-scale-codec", + "parking_lot 0.10.2", + "pin-project", + "polkadot-node-primitives", + "polkadot-node-subsystem", + "polkadot-node-subsystem-test-helpers", "polkadot-primitives", "polkadot-statement-table", "sc-keystore", @@ -4746,6 +4800,7 @@ dependencies = [ "parking_lot 0.10.2", "polkadot-node-primitives", "polkadot-node-subsystem", + "polkadot-node-subsystem-test-helpers", "polkadot-primitives", "sc-network", "sp-core", @@ -5102,6 +5157,7 @@ dependencies = [ "parking_lot 0.10.2", "polkadot-node-primitives", "polkadot-node-subsystem", + "polkadot-node-subsystem-test-helpers", "polkadot-primitives", "sp-core", "sp-keyring", diff --git a/polkadot/Cargo.toml b/polkadot/Cargo.toml index a56de658b3..60d2f5671d 100644 --- a/polkadot/Cargo.toml +++ b/polkadot/Cargo.toml @@ -61,6 +61,8 @@ members = [ "node/primitives", "node/service", "node/subsystem", + "node/subsystem-test-helpers", + "node/subsystem-util", "node/test-service", "parachain/test-parachains", diff --git a/polkadot/node/core/av-store/Cargo.toml b/polkadot/node/core/av-store/Cargo.toml index e89ef7a6ec..68137b6ae7 100644 --- a/polkadot/node/core/av-store/Cargo.toml +++ b/polkadot/node/core/av-store/Cargo.toml @@ -19,6 +19,6 @@ derive_more = "0.99.9" [dev-dependencies] sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } futures = { version = "0.3.5", features = ["thread-pool"] } -polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem", features = [ "test-helpers" ] } +polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" } kvdb-memorydb = "0.7.0" assert_matches = "1.3.0" diff --git a/polkadot/node/core/av-store/src/lib.rs b/polkadot/node/core/av-store/src/lib.rs index 14f027dc86..9c33052afc 100644 --- a/polkadot/node/core/av-store/src/lib.rs +++ b/polkadot/node/core/av-store/src/lib.rs @@ -316,7 +316,7 @@ mod tests { AvailableData, BlockData, HeadData, GlobalValidationData, LocalValidationData, PoV, OmittedValidationData, }; - use polkadot_subsystem::test_helpers; + use polkadot_node_subsystem_test_helpers as test_helpers; struct TestHarness { virtual_overseer: test_helpers::TestSubsystemContextHandle, diff --git a/polkadot/node/core/backing/Cargo.toml b/polkadot/node/core/backing/Cargo.toml index 22f8dcc734..9401290f2b 100644 --- a/polkadot/node/core/backing/Cargo.toml +++ b/polkadot/node/core/backing/Cargo.toml @@ -13,6 +13,7 @@ keystore = { package = "sc-keystore", git = "https://github.com/paritytech/subst polkadot-primitives = { path = "../../../primitives" } polkadot-node-primitives = { path = "../../primitives" } polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem" } +polkadot-node-subsystem-util = { path = "../../subsystem-util" } erasure-coding = { package = "polkadot-erasure-coding", path = "../../../erasure-coding" } statement-table = { package = "polkadot-statement-table", path = "../../../statement-table" } derive_more = "0.99.9" @@ -24,4 +25,4 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" } futures = { version = "0.3.5", features = ["thread-pool"] } assert_matches = "1.3.0" -polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem", features = [ "test-helpers" ] } +polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" } diff --git a/polkadot/node/core/backing/src/lib.rs b/polkadot/node/core/backing/src/lib.rs index f7608f0d0f..a77d98cd23 100644 --- a/polkadot/node/core/backing/src/lib.rs +++ b/polkadot/node/core/backing/src/lib.rs @@ -45,14 +45,14 @@ use polkadot_subsystem::{ ProvisionerMessage, RuntimeApiMessage, StatementDistributionMessage, ValidationFailed, RuntimeApiRequest, }, - util::{ - self, - request_session_index_for_child, - request_validator_groups, - request_validators, - request_from_runtime, - Validator, - }, +}; +use polkadot_node_subsystem_util::{ + self as util, + request_session_index_for_child, + request_validator_groups, + request_validators, + request_from_runtime, + Validator, delegated_subsystem, }; use statement_table::{ @@ -896,13 +896,13 @@ mod tests { } struct TestHarness { - virtual_overseer: polkadot_subsystem::test_helpers::TestSubsystemContextHandle, + virtual_overseer: polkadot_node_subsystem_test_helpers::TestSubsystemContextHandle, } fn test_harness>(keystore: KeyStorePtr, test: impl FnOnce(TestHarness) -> T) { let pool = sp_core::testing::TaskExecutor::new(); - let (context, virtual_overseer) = polkadot_subsystem::test_helpers::make_subsystem_context(pool.clone()); + let (context, virtual_overseer) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool.clone()); let subsystem = CandidateBackingSubsystem::run(context, keystore, pool.clone()); @@ -960,7 +960,7 @@ mod tests { // Tests that the subsystem performs actions that are requied on startup. async fn test_startup( - virtual_overseer: &mut polkadot_subsystem::test_helpers::TestSubsystemContextHandle, + virtual_overseer: &mut polkadot_node_subsystem_test_helpers::TestSubsystemContextHandle, test_state: &TestState, ) { // Start work on some new parent. diff --git a/polkadot/node/core/bitfield-signing/Cargo.toml b/polkadot/node/core/bitfield-signing/Cargo.toml index b8a6cedcc5..11bfef713c 100644 --- a/polkadot/node/core/bitfield-signing/Cargo.toml +++ b/polkadot/node/core/bitfield-signing/Cargo.toml @@ -11,5 +11,6 @@ futures = "0.3.5" log = "0.4.8" polkadot-primitives = { path = "../../../primitives" } polkadot-node-subsystem = { path = "../../subsystem" } +polkadot-node-subsystem-util = { path = "../../subsystem-util" } keystore = { package = "sc-keystore", git = "https://github.com/paritytech/substrate", branch = "master" } wasm-timer = "0.2.4" diff --git a/polkadot/node/core/bitfield-signing/src/lib.rs b/polkadot/node/core/bitfield-signing/src/lib.rs index 4e409a2576..feca8f0c8f 100644 --- a/polkadot/node/core/bitfield-signing/src/lib.rs +++ b/polkadot/node/core/bitfield-signing/src/lib.rs @@ -29,7 +29,9 @@ use polkadot_node_subsystem::{ BitfieldSigningMessage, CandidateBackingMessage, RuntimeApiMessage, }, errors::RuntimeApiError, - util::{self, JobManager, JobTrait, ToJobTrait, Validator}, +}; +use polkadot_node_subsystem_util::{ + self as util, JobManager, JobTrait, ToJobTrait, Validator }; use polkadot_primitives::v1::{AvailabilityBitfield, CoreState, Hash, ValidatorIndex}; use std::{convert::TryFrom, pin::Pin, time::Duration}; diff --git a/polkadot/node/core/candidate-validation/Cargo.toml b/polkadot/node/core/candidate-validation/Cargo.toml index 3c36b16758..8f1b7a0fa0 100644 --- a/polkadot/node/core/candidate-validation/Cargo.toml +++ b/polkadot/node/core/candidate-validation/Cargo.toml @@ -21,4 +21,4 @@ log = "0.4.8" sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" } futures = { version = "0.3.5", features = ["thread-pool"] } assert_matches = "1.3.0" -polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem", features = ["test-helpers"] } +polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" } diff --git a/polkadot/node/core/candidate-validation/src/lib.rs b/polkadot/node/core/candidate-validation/src/lib.rs index 8dcc0a574b..f12f6b1b9d 100644 --- a/polkadot/node/core/candidate-validation/src/lib.rs +++ b/polkadot/node/core/candidate-validation/src/lib.rs @@ -470,7 +470,7 @@ fn validate_candidate_exhaustive( #[cfg(test)] mod tests { use super::*; - use polkadot_subsystem::test_helpers; + use polkadot_node_subsystem_test_helpers as test_helpers; use polkadot_primitives::v1::{HeadData, BlockData}; use sp_core::testing::TaskExecutor; use futures::executor; diff --git a/polkadot/node/core/chain-api/Cargo.toml b/polkadot/node/core/chain-api/Cargo.toml index 61ca313e33..d626a0d932 100644 --- a/polkadot/node/core/chain-api/Cargo.toml +++ b/polkadot/node/core/chain-api/Cargo.toml @@ -13,5 +13,5 @@ polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsys [dev-dependencies] futures = { version = "0.3.5", features = ["thread-pool"] } maplit = "1.0.2" -polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem", features = ["test-helpers"] } +polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/polkadot/node/core/chain-api/src/lib.rs b/polkadot/node/core/chain-api/src/lib.rs index a9e93ca9dd..20213e3c08 100644 --- a/polkadot/node/core/chain-api/src/lib.rs +++ b/polkadot/node/core/chain-api/src/lib.rs @@ -121,7 +121,7 @@ mod tests { use futures::{future::BoxFuture, channel::oneshot}; use polkadot_primitives::v1::{Hash, BlockNumber, BlockId, Header}; - use polkadot_subsystem::test_helpers::{make_subsystem_context, TestSubsystemContextHandle}; + use polkadot_node_subsystem_test_helpers::{make_subsystem_context, TestSubsystemContextHandle}; use sp_blockchain::Info as BlockInfo; use sp_core::testing::TaskExecutor; diff --git a/polkadot/node/core/provisioner/Cargo.toml b/polkadot/node/core/provisioner/Cargo.toml index 6c6477c904..c391f8e45a 100644 --- a/polkadot/node/core/provisioner/Cargo.toml +++ b/polkadot/node/core/provisioner/Cargo.toml @@ -11,6 +11,7 @@ futures = "0.3.5" log = "0.4.8" polkadot-primitives = { path = "../../../primitives" } polkadot-node-subsystem = { path = "../../subsystem" } +polkadot-node-subsystem-util = { path = "../../subsystem-util" } [dev-dependencies] lazy_static = "1.4" diff --git a/polkadot/node/core/provisioner/src/lib.rs b/polkadot/node/core/provisioner/src/lib.rs index 712c1a834f..9a92858a9e 100644 --- a/polkadot/node/core/provisioner/src/lib.rs +++ b/polkadot/node/core/provisioner/src/lib.rs @@ -25,16 +25,17 @@ use futures::{ prelude::*, }; use polkadot_node_subsystem::{ - delegated_subsystem, errors::{ChainApiError, RuntimeApiError}, messages::{ AllMessages, ChainApiMessage, ProvisionableData, ProvisionerInherentData, ProvisionerMessage, RuntimeApiMessage, }, - util::{ - self, request_availability_cores, request_global_validation_data, - request_local_validation_data, JobTrait, ToJobTrait, - }, +}; +use polkadot_node_subsystem_util::{ + self as util, + delegated_subsystem, + request_availability_cores, request_global_validation_data, + request_local_validation_data, JobTrait, ToJobTrait, }; use polkadot_primitives::v1::{ validation_data_hash, BackedCandidate, BlockNumber, CoreState, Hash, OccupiedCoreAssumption, diff --git a/polkadot/node/core/runtime-api/Cargo.toml b/polkadot/node/core/runtime-api/Cargo.toml index 7dfde63947..229366627a 100644 --- a/polkadot/node/core/runtime-api/Cargo.toml +++ b/polkadot/node/core/runtime-api/Cargo.toml @@ -16,4 +16,4 @@ polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsys [dev-dependencies] sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } futures = { version = "0.3.5", features = ["thread-pool"] } -polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem", features = ["test-helpers"] } +polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" } diff --git a/polkadot/node/core/runtime-api/src/lib.rs b/polkadot/node/core/runtime-api/src/lib.rs index 34d73f91ec..9b93bb914b 100644 --- a/polkadot/node/core/runtime-api/src/lib.rs +++ b/polkadot/node/core/runtime-api/src/lib.rs @@ -123,7 +123,7 @@ mod tests { Id as ParaId, OccupiedCoreAssumption, LocalValidationData, SessionIndex, ValidationCode, CommittedCandidateReceipt, CandidateEvent, }; - use polkadot_subsystem::test_helpers; + use polkadot_node_subsystem_test_helpers as test_helpers; use sp_core::testing::TaskExecutor; use std::collections::HashMap; diff --git a/polkadot/node/network/bitfield-distribution/Cargo.toml b/polkadot/node/network/bitfield-distribution/Cargo.toml index 2addbbfd3f..bf7d23a900 100644 --- a/polkadot/node/network/bitfield-distribution/Cargo.toml +++ b/polkadot/node/network/bitfield-distribution/Cargo.toml @@ -18,7 +18,7 @@ polkadot-network = { path = "../../../network" } sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" } [dev-dependencies] -polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem", features = [ "test-helpers" ] } +polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" } bitvec = { version = "0.17.4", default-features = false, features = ["alloc"] } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } parking_lot = "0.10.0" diff --git a/polkadot/node/network/bitfield-distribution/src/lib.rs b/polkadot/node/network/bitfield-distribution/src/lib.rs index 66f9ca9509..d67b5e353f 100644 --- a/polkadot/node/network/bitfield-distribution/src/lib.rs +++ b/polkadot/node/network/bitfield-distribution/src/lib.rs @@ -607,7 +607,7 @@ mod test { use futures::executor; use maplit::hashmap; use polkadot_primitives::v1::{Signed, ValidatorPair, AvailabilityBitfield}; - use polkadot_subsystem::test_helpers::make_subsystem_context; + use polkadot_node_subsystem_test_helpers::make_subsystem_context; use smol_timeout::TimeoutExt; use sp_core::crypto::Pair; use std::time::Duration; diff --git a/polkadot/node/network/bridge/Cargo.toml b/polkadot/node/network/bridge/Cargo.toml index 3e405d3d75..ef8b605bb1 100644 --- a/polkadot/node/network/bridge/Cargo.toml +++ b/polkadot/node/network/bridge/Cargo.toml @@ -19,5 +19,5 @@ polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsys [dev-dependencies] assert_matches = "1.3.0" parking_lot = "0.10.0" -polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem", features = [ "test-helpers" ] } +polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/polkadot/node/network/bridge/src/lib.rs b/polkadot/node/network/bridge/src/lib.rs index 56117732f9..85063b2b0c 100644 --- a/polkadot/node/network/bridge/src/lib.rs +++ b/polkadot/node/network/bridge/src/lib.rs @@ -521,7 +521,7 @@ mod tests { use assert_matches::assert_matches; use polkadot_subsystem::messages::{StatementDistributionMessage, BitfieldDistributionMessage}; - use polkadot_subsystem::test_helpers::{SingleItemSink, SingleItemStream}; + use polkadot_node_subsystem_test_helpers::{SingleItemSink, SingleItemStream}; // The subsystem's view of the network - only supports a single call to `event_stream`. struct TestNetwork { @@ -540,7 +540,7 @@ mod tests { TestNetwork, TestNetworkHandle, ) { - let (net_tx, net_rx) = polkadot_subsystem::test_helpers::single_item_sink(); + let (net_tx, net_rx) = polkadot_node_subsystem_test_helpers::single_item_sink(); let (action_tx, action_rx) = mpsc::unbounded(); ( @@ -621,13 +621,13 @@ mod tests { struct TestHarness { network_handle: TestNetworkHandle, - virtual_overseer: polkadot_subsystem::test_helpers::TestSubsystemContextHandle, + virtual_overseer: polkadot_node_subsystem_test_helpers::TestSubsystemContextHandle, } fn test_harness>(test: impl FnOnce(TestHarness) -> T) { 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); + let (context, virtual_overseer) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool); let network_bridge = run_network( network, diff --git a/polkadot/node/network/pov-distribution/Cargo.toml b/polkadot/node/network/pov-distribution/Cargo.toml index c6bfd4b14c..74a566f35d 100644 --- a/polkadot/node/network/pov-distribution/Cargo.toml +++ b/polkadot/node/network/pov-distribution/Cargo.toml @@ -20,4 +20,4 @@ polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsys parking_lot = "0.10.0" assert_matches = "1.3.0" sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } -polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem", features = [ "test-helpers" ] } +polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" } diff --git a/polkadot/node/network/pov-distribution/src/lib.rs b/polkadot/node/network/pov-distribution/src/lib.rs index 4409d7f1ea..9589e2fad9 100644 --- a/polkadot/node/network/pov-distribution/src/lib.rs +++ b/polkadot/node/network/pov-distribution/src/lib.rs @@ -639,7 +639,7 @@ mod tests { }; let pool = sp_core::testing::TaskExecutor::new(); - let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool); + let (mut ctx, mut handle) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool); let mut descriptor = CandidateDescriptor::default(); descriptor.pov_hash = pov_hash; @@ -719,7 +719,7 @@ mod tests { }; let pool = sp_core::testing::TaskExecutor::new(); - let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool); + let (mut ctx, mut handle) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool); let mut descriptor = CandidateDescriptor::default(); descriptor.pov_hash = pov_hash; @@ -797,7 +797,7 @@ mod tests { }; let pool = sp_core::testing::TaskExecutor::new(); - let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool); + let (mut ctx, mut handle) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool); executor::block_on(async move { handle_network_update( @@ -869,7 +869,7 @@ mod tests { }; let pool = sp_core::testing::TaskExecutor::new(); - let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool); + let (mut ctx, mut handle) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool); executor::block_on(async move { // Peer A answers our request before peer B. @@ -957,7 +957,7 @@ mod tests { }; let pool = sp_core::testing::TaskExecutor::new(); - let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool); + let (mut ctx, mut handle) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool); executor::block_on(async move { // Peer A answers our request: right relay parent, awaited hash, wrong PoV. @@ -1020,7 +1020,7 @@ mod tests { }; let pool = sp_core::testing::TaskExecutor::new(); - let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool); + let (mut ctx, mut handle) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool); executor::block_on(async move { // Peer A answers our request: right relay parent, awaited hash, wrong PoV. @@ -1081,7 +1081,7 @@ mod tests { }; let pool = sp_core::testing::TaskExecutor::new(); - let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool); + let (mut ctx, mut handle) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool); executor::block_on(async move { // Peer A answers our request: right relay parent, awaited hash, wrong PoV. @@ -1139,7 +1139,7 @@ mod tests { }; let pool = sp_core::testing::TaskExecutor::new(); - let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool); + let (mut ctx, mut handle) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool); executor::block_on(async move { let max_plausibly_awaited = n_validators * 2; @@ -1224,7 +1224,7 @@ mod tests { }; let pool = sp_core::testing::TaskExecutor::new(); - let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool); + let (mut ctx, mut handle) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool); executor::block_on(async move { let pov_hash = make_pov(vec![1, 2, 3]).hash(); @@ -1286,7 +1286,7 @@ mod tests { }; let pool = sp_core::testing::TaskExecutor::new(); - let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool); + let (mut ctx, mut handle) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool); executor::block_on(async move { let pov_hash = make_pov(vec![1, 2, 3]).hash(); @@ -1363,7 +1363,7 @@ mod tests { }; let pool = sp_core::testing::TaskExecutor::new(); - let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool); + let (mut ctx, mut handle) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool); executor::block_on(async move { handle_network_update( @@ -1446,7 +1446,7 @@ mod tests { }; let pool = sp_core::testing::TaskExecutor::new(); - let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool); + let (mut ctx, mut handle) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool); executor::block_on(async move { handle_network_update( diff --git a/polkadot/node/network/statement-distribution/Cargo.toml b/polkadot/node/network/statement-distribution/Cargo.toml index 04e6def40e..6dfaee78bb 100644 --- a/polkadot/node/network/statement-distribution/Cargo.toml +++ b/polkadot/node/network/statement-distribution/Cargo.toml @@ -21,7 +21,7 @@ indexmap = "1.4.0" [dev-dependencies] parking_lot = "0.10.0" -polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem", features = ["test-helpers"] } +polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" } assert_matches = "1.3.0" sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/polkadot/node/network/statement-distribution/src/lib.rs b/polkadot/node/network/statement-distribution/src/lib.rs index 5cc67cfea0..f58e6da4d4 100644 --- a/polkadot/node/network/statement-distribution/src/lib.rs +++ b/polkadot/node/network/statement-distribution/src/lib.rs @@ -1235,7 +1235,7 @@ mod tests { }; let pool = sp_core::testing::TaskExecutor::new(); - let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool); + let (mut ctx, mut handle) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool); let peer = PeerId::random(); executor::block_on(async move { @@ -1327,7 +1327,7 @@ mod tests { ].into_iter().collect(); let pool = sp_core::testing::TaskExecutor::new(); - let (mut ctx, mut handle) = polkadot_subsystem::test_helpers::make_subsystem_context(pool); + let (mut ctx, mut handle) = polkadot_node_subsystem_test_helpers::make_subsystem_context(pool); executor::block_on(async move { let statement = { diff --git a/polkadot/node/primitives/Cargo.toml b/polkadot/node/primitives/Cargo.toml index df288438a8..b38e7e542e 100644 --- a/polkadot/node/primitives/Cargo.toml +++ b/polkadot/node/primitives/Cargo.toml @@ -10,5 +10,4 @@ polkadot-primitives = { path = "../../primitives" } polkadot-statement-table = { path = "../../statement-table" } parity-scale-codec = { version = "1.3.4", default-features = false, features = ["derive"] } runtime_primitives = { package = "sp-runtime", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -async-trait = "0.1" sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/polkadot/node/subsystem-test-helpers/Cargo.toml b/polkadot/node/subsystem-test-helpers/Cargo.toml new file mode 100644 index 0000000000..105e6b5816 --- /dev/null +++ b/polkadot/node/subsystem-test-helpers/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "polkadot-node-subsystem-test-helpers" +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2018" +description = "Subsystem traits and message definitions" + +[dependencies] +async-trait = "0.1" +derive_more = "0.99.9" +futures = "0.3.5" +futures-timer = "3.0.2" +log = "0.4.8" +parity-scale-codec = "1.3.4" +parking_lot = "0.10.0" +pin-project = "0.4.22" +polkadot-node-primitives = { path = "../primitives" } +polkadot-node-subsystem = { path = "../subsystem" } +polkadot-primitives = { path = "../../primitives" } +polkadot-statement-table = { path = "../../statement-table" } +sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" } +smallvec = "1.4.1" +sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/polkadot/node/subsystem/src/test_helpers.rs b/polkadot/node/subsystem-test-helpers/src/lib.rs similarity index 97% rename from polkadot/node/subsystem/src/test_helpers.rs rename to polkadot/node/subsystem-test-helpers/src/lib.rs index 256a928b43..a4070c028c 100644 --- a/polkadot/node/subsystem/src/test_helpers.rs +++ b/polkadot/node/subsystem-test-helpers/src/lib.rs @@ -16,8 +16,8 @@ //! Utilities for testing subsystems. -use crate::{SubsystemContext, FromOverseer, SubsystemResult, SubsystemError}; -use crate::messages::AllMessages; +use polkadot_node_subsystem::{SubsystemContext, FromOverseer, SubsystemResult, SubsystemError}; +use polkadot_node_subsystem::messages::AllMessages; use futures::prelude::*; use futures::channel::mpsc; diff --git a/polkadot/node/subsystem-util/Cargo.toml b/polkadot/node/subsystem-util/Cargo.toml new file mode 100644 index 0000000000..6ed2999213 --- /dev/null +++ b/polkadot/node/subsystem-util/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "polkadot-node-subsystem-util" +version = "0.1.0" +authors = ["Parity Technologies "] +edition = "2018" +description = "Subsystem traits and message definitions" + +[dependencies] +async-trait = "0.1" +derive_more = "0.99.9" +futures = "0.3.5" +futures-timer = "3.0.2" +keystore = { package = "sc-keystore", git = "https://github.com/paritytech/substrate", branch = "master" } +log = "0.4.8" +parity-scale-codec = "1.3.4" +parking_lot = { version = "0.10.0", optional = true } +pin-project = "0.4.22" +polkadot-node-primitives = { path = "../primitives" } +polkadot-node-subsystem = { path = "../subsystem" } +polkadot-primitives = { path = "../../primitives" } +polkadot-statement-table = { path = "../../statement-table" } +sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" } +smallvec = "1.4.1" +sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } +streamunordered = "0.5.1" + +[dev-dependencies] +assert_matches = "1.3.0" +async-trait = "0.1" +futures = { version = "0.3.5", features = ["thread-pool"] } +parking_lot = "0.10.0" +polkadot-node-subsystem-test-helpers = { path = "../subsystem-test-helpers" } diff --git a/polkadot/node/subsystem/src/util.rs b/polkadot/node/subsystem-util/src/lib.rs similarity index 94% rename from polkadot/node/subsystem/src/util.rs rename to polkadot/node/subsystem-util/src/lib.rs index 7472ebeb8a..cc8cbd239d 100644 --- a/polkadot/node/subsystem/src/util.rs +++ b/polkadot/node/subsystem-util/src/lib.rs @@ -20,7 +20,7 @@ //! or determining what their validator ID is. These common interests are factored into //! this module. -use crate::{ +use polkadot_node_subsystem::{ errors::{ChainApiError, RuntimeApiError}, messages::{AllMessages, RuntimeApiMessage, RuntimeApiRequest, RuntimeApiSender}, FromOverseer, SpawnedSubsystem, Subsystem, SubsystemContext, SubsystemError, SubsystemResult, @@ -43,7 +43,7 @@ use polkadot_primitives::v1::{ SessionIndex, Signed, SigningContext, ValidationCode, ValidatorId, ValidatorIndex, ValidatorPair, }; -use sp_core::Pair; +use sp_core::{Pair, traits::SpawnNamed}; use std::{ collections::HashMap, convert::{TryFrom, TryInto}, @@ -53,10 +53,15 @@ use std::{ }; use streamunordered::{StreamUnordered, StreamYield}; -/// This reexport is required so that external crates can use the `delegated_subsystem` macro properly. -/// -/// Otherwise, downstream crates might have to modify their `Cargo.toml` to ensure `sp-core` appeared there. -pub use sp_core::traits::SpawnNamed; +/// These reexports are required so that external crates can use the `delegated_subsystem` macro properly. +pub mod reexports { + pub use sp_core::traits::SpawnNamed; + pub use polkadot_node_subsystem::{ + SpawnedSubsystem, + Subsystem, + SubsystemContext, + }; +} /// Duration a job will wait after sending a stop signal before hard-aborting. pub const JOB_GRACEFUL_STOP_DURATION: Duration = Duration::from_secs(1); @@ -655,9 +660,9 @@ where run_args: &Job::RunArgs, err_tx: &mut Option, JobsError)>>, ) -> bool { - use crate::ActiveLeavesUpdate; - use crate::FromOverseer::{Communication, Signal}; - use crate::OverseerSignal::{ActiveLeaves, BlockFinalized, Conclude}; + use polkadot_node_subsystem::ActiveLeavesUpdate; + use polkadot_node_subsystem::FromOverseer::{Communication, Signal}; + use polkadot_node_subsystem::OverseerSignal::{ActiveLeaves, BlockFinalized, Conclude}; match incoming { Ok(Signal(ActiveLeaves(ActiveLeavesUpdate { @@ -783,7 +788,7 @@ where /// It is possible to create a type which implements `Subsystem` by simply doing: /// /// ```ignore -/// pub type ExampleSubsystem = util::JobManager; +/// pub type ExampleSubsystem = JobManager; /// ``` /// /// However, doing this requires that job itself and all types which comprise it (i.e. `ToJob`, `FromJob`, `Error`, `RunArgs`) @@ -791,7 +796,7 @@ where /// can reduce the total number of public types exposed, i.e. /// /// ```ignore -/// type Manager = util::JobManager; +/// type Manager = JobManager; /// pub struct ExampleSubsystem { /// manager: Manager, /// } @@ -820,7 +825,7 @@ macro_rules! delegated_subsystem { ($job:ident($run_args:ty) <- $to_job:ty as $subsystem:ident; $subsystem_name:expr) => { #[doc = "Manager type for the "] #[doc = $subsystem_name] - type Manager = $crate::util::JobManager; + type Manager = $crate::JobManager; #[doc = "An implementation of the "] #[doc = $subsystem_name] @@ -830,15 +835,15 @@ macro_rules! delegated_subsystem { impl $subsystem where - Spawner: Clone + $crate::util::SpawnNamed + Send + Unpin, - Context: $crate::SubsystemContext, - ::Message: Into<$to_job>, + Spawner: Clone + $crate::reexports::SpawnNamed + Send + Unpin, + Context: $crate::reexports::SubsystemContext, + ::Message: Into<$to_job>, { #[doc = "Creates a new "] #[doc = $subsystem_name] pub fn new(spawner: Spawner, run_args: $run_args) -> Self { $subsystem { - manager: $crate::util::JobManager::new(spawner, run_args) + manager: $crate::JobManager::new(spawner, run_args) } } @@ -848,13 +853,13 @@ macro_rules! delegated_subsystem { } } - impl $crate::Subsystem for $subsystem + impl $crate::reexports::Subsystem for $subsystem where - Spawner: $crate::util::SpawnNamed + Send + Clone + Unpin + 'static, - Context: $crate::SubsystemContext, - ::Message: Into<$to_job>, + Spawner: $crate::reexports::SpawnNamed + Send + Clone + Unpin + 'static, + Context: $crate::reexports::SubsystemContext, + ::Message: Into<$to_job>, { - fn start(self, ctx: Context) -> $crate::SpawnedSubsystem { + fn start(self, ctx: Context) -> $crate::reexports::SpawnedSubsystem { self.manager.start(ctx) } } @@ -863,10 +868,9 @@ macro_rules! delegated_subsystem { #[cfg(test)] mod tests { - use crate::{ + use super::{Error as UtilError, JobManager, JobTrait, JobsError, ToJobTrait}; + use polkadot_node_subsystem::{ messages::{AllMessages, CandidateSelectionMessage}, - test_helpers::{self, make_subsystem_context}, - util::{self, JobManager, JobTrait, JobsError, ToJobTrait}, ActiveLeavesUpdate, FromOverseer, OverseerSignal, SpawnedSubsystem, Subsystem, }; use assert_matches::assert_matches; @@ -878,6 +882,7 @@ mod tests { }; use futures_timer::Delay; use polkadot_primitives::v1::Hash; + use polkadot_node_subsystem_test_helpers::{self as test_helpers, make_subsystem_context}; use std::{collections::HashMap, convert::TryFrom, pin::Pin, time::Duration}; // basic usage: in a nutshell, when you want to define a subsystem, just focus on what its jobs do; @@ -941,13 +946,13 @@ mod tests { // we include it in the RunArgs #[derive(Clone)] enum FromJob { - Test(String), + Test, } impl From for AllMessages { fn from(from_job: FromJob) -> AllMessages { match from_job { - FromJob::Test(s) => AllMessages::Test(s), + FromJob::Test => AllMessages::CandidateSelection(CandidateSelectionMessage::default()), } } } @@ -1054,10 +1059,9 @@ mod tests { fn starting_and_stopping_job_works() { let relay_parent: Hash = [0; 32].into(); let mut run_args = HashMap::new(); - let test_message = format!("greetings from {}", relay_parent); run_args.insert( relay_parent.clone(), - vec![FromJob::Test(test_message.clone())], + vec![FromJob::Test], ); test_harness(run_args, |mut overseer_handle, err_rx| async move { @@ -1068,7 +1072,7 @@ mod tests { .await; assert_matches!( overseer_handle.recv().await, - AllMessages::Test(msg) if msg == test_message + AllMessages::CandidateSelection(_) ); overseer_handle .send(FromOverseer::Signal(OverseerSignal::ActiveLeaves( @@ -1098,7 +1102,7 @@ mod tests { assert_eq!(errs[0].0, Some(relay_parent)); assert_matches!( errs[0].1, - JobsError::Utility(util::Error::JobNotFound(match_relay_parent)) if relay_parent == match_relay_parent + JobsError::Utility(UtilError::JobNotFound(match_relay_parent)) if relay_parent == match_relay_parent ); }); } diff --git a/polkadot/node/subsystem/Cargo.toml b/polkadot/node/subsystem/Cargo.toml index f924808182..3e676cb4f1 100644 --- a/polkadot/node/subsystem/Cargo.toml +++ b/polkadot/node/subsystem/Cargo.toml @@ -10,7 +10,6 @@ async-trait = "0.1" derive_more = "0.99.9" futures = "0.3.5" futures-timer = "3.0.2" -keystore = { package = "sc-keystore", git = "https://github.com/paritytech/substrate", branch = "master" } log = "0.4.8" parity-scale-codec = "1.3.4" parking_lot = { version = "0.10.0", optional = true } @@ -21,13 +20,10 @@ polkadot-statement-table = { path = "../../statement-table" } sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" } smallvec = "1.4.1" sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } -streamunordered = "0.5.1" [dev-dependencies] assert_matches = "1.3.0" async-trait = "0.1" futures = { version = "0.3.5", features = ["thread-pool"] } parking_lot = "0.10.0" - -[features] -test-helpers = [ "parking_lot" ] +polkadot-node-subsystem-test-helpers = { path = "../subsystem-test-helpers" } diff --git a/polkadot/node/subsystem/src/lib.rs b/polkadot/node/subsystem/src/lib.rs index 7e112f5439..3f72e2f269 100644 --- a/polkadot/node/subsystem/src/lib.rs +++ b/polkadot/node/subsystem/src/lib.rs @@ -36,9 +36,6 @@ use crate::messages::AllMessages; pub mod errors; pub mod messages; -pub mod util; -#[cfg(any(test, feature = "test-helpers"))] -pub mod test_helpers; /// How many slots are stack-reserved for active leaves updates /// diff --git a/polkadot/node/subsystem/src/messages.rs b/polkadot/node/subsystem/src/messages.rs index 29014c55a8..acc41a2e7f 100644 --- a/polkadot/node/subsystem/src/messages.rs +++ b/polkadot/node/subsystem/src/messages.rs @@ -61,6 +61,12 @@ impl CandidateSelectionMessage { } } +impl Default for CandidateSelectionMessage { + fn default() -> Self { + CandidateSelectionMessage::Invalid(Default::default(), Default::default()) + } +} + /// Messages received by the Candidate Backing subsystem. #[derive(Debug)] pub enum CandidateBackingMessage { @@ -509,10 +515,4 @@ pub enum AllMessages { NetworkBridge(NetworkBridgeMessage), /// Message for the Chain API subsystem ChainApi(ChainApiMessage), - /// Test message - /// - /// This variant is only valid while testing, but makes the process of testing the - /// subsystem job manager much simpler. - #[cfg(test)] - Test(String), }