Use SpawnNamed instead of Spawn in Overseer (#1430)

* Use SpawnNamed instead of Spawn in Overseer

* reexport SpawnNamed and fix doc tests

* Fix deps
This commit is contained in:
Fedor Sakharov
2020-07-17 20:04:02 +03:00
committed by GitHub
parent 04f9c6ece8
commit 5624bd8bf4
19 changed files with 245 additions and 172 deletions
+7
View File
@@ -4457,6 +4457,7 @@ dependencies = [
"polkadot-primitives", "polkadot-primitives",
"polkadot-subsystem-test-helpers", "polkadot-subsystem-test-helpers",
"sc-network", "sc-network",
"sp-core",
"sp-runtime", "sp-runtime",
"streamunordered", "streamunordered",
] ]
@@ -4538,6 +4539,7 @@ dependencies = [
"parity-scale-codec", "parity-scale-codec",
"polkadot-primitives", "polkadot-primitives",
"polkadot-statement-table", "polkadot-statement-table",
"sp-core",
"sp-runtime", "sp-runtime",
] ]
@@ -4571,9 +4573,11 @@ dependencies = [
"futures-timer 3.0.2", "futures-timer 3.0.2",
"kv-log-macro", "kv-log-macro",
"log 0.4.8", "log 0.4.8",
"polkadot-node-primitives",
"polkadot-node-subsystem", "polkadot-node-subsystem",
"polkadot-primitives", "polkadot-primitives",
"sc-client-api", "sc-client-api",
"sp-core",
"streamunordered", "streamunordered",
] ]
@@ -4611,6 +4615,7 @@ dependencies = [
"polkadot-primitives", "polkadot-primitives",
"polkadot-subsystem-test-helpers", "polkadot-subsystem-test-helpers",
"sc-network", "sc-network",
"sp-core",
"sp-runtime", "sp-runtime",
"streamunordered", "streamunordered",
] ]
@@ -4963,6 +4968,7 @@ dependencies = [
"polkadot-node-subsystem", "polkadot-node-subsystem",
"polkadot-primitives", "polkadot-primitives",
"polkadot-subsystem-test-helpers", "polkadot-subsystem-test-helpers",
"sp-core",
"sp-keyring", "sp-keyring",
"sp-runtime", "sp-runtime",
"sp-staking", "sp-staking",
@@ -4986,6 +4992,7 @@ dependencies = [
"futures 0.3.5", "futures 0.3.5",
"parking_lot 0.10.2", "parking_lot 0.10.2",
"polkadot-node-subsystem", "polkadot-node-subsystem",
"sp-core",
] ]
[[package]] [[package]]
+1 -1
View File
@@ -10,7 +10,6 @@ sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
keystore = { package = "sc-keystore", git = "https://github.com/paritytech/substrate", branch = "master" } keystore = { package = "sc-keystore", git = "https://github.com/paritytech/substrate", branch = "master" }
primitives = { package = "sp-core", git = "https://github.com/paritytech/substrate", branch = "master" }
polkadot-primitives = { path = "../../../primitives" } polkadot-primitives = { path = "../../../primitives" }
polkadot-node-primitives = { path = "../../primitives" } polkadot-node-primitives = { path = "../../primitives" }
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem" } polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem" }
@@ -20,6 +19,7 @@ derive_more = "0.99.9"
bitvec = { version = "0.17.4", default-features = false, features = ["alloc"] } bitvec = { version = "0.17.4", default-features = false, features = ["alloc"] }
[dev-dependencies] [dev-dependencies]
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-keyring = { 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"] } futures = { version = "0.3.5", features = ["thread-pool"] }
subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" } subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" }
+5 -11
View File
@@ -24,7 +24,6 @@ use std::sync::Arc;
use bitvec::vec::BitVec; use bitvec::vec::BitVec;
use futures::{ use futures::{
channel::{mpsc, oneshot}, channel::{mpsc, oneshot},
task::{Spawn, SpawnError},
Future, FutureExt, SinkExt, StreamExt, Future, FutureExt, SinkExt, StreamExt,
}; };
@@ -37,7 +36,7 @@ use polkadot_primitives::v1::{
}; };
use polkadot_node_primitives::{ use polkadot_node_primitives::{
FromTableMisbehavior, Statement, SignedFullStatement, MisbehaviorReport, FromTableMisbehavior, Statement, SignedFullStatement, MisbehaviorReport,
ValidationOutputs, ValidationResult, ValidationOutputs, ValidationResult, SpawnNamed,
}; };
use polkadot_subsystem::{ use polkadot_subsystem::{
Subsystem, SubsystemContext, SpawnedSubsystem, Subsystem, SubsystemContext, SpawnedSubsystem,
@@ -77,8 +76,6 @@ enum Error {
#[from] #[from]
Mpsc(mpsc::SendError), Mpsc(mpsc::SendError),
#[from] #[from]
Spawn(SpawnError),
#[from]
UtilError(util::Error), UtilError(util::Error),
} }
@@ -735,7 +732,7 @@ pub struct CandidateBackingSubsystem<Spawner, Context> {
impl<Spawner, Context> CandidateBackingSubsystem<Spawner, Context> impl<Spawner, Context> CandidateBackingSubsystem<Spawner, Context>
where where
Spawner: Clone + Spawn + Send + Unpin, Spawner: Clone + SpawnNamed + Send + Unpin,
Context: SubsystemContext, Context: SubsystemContext,
ToJob: From<<Context as SubsystemContext>::Message>, ToJob: From<<Context as SubsystemContext>::Message>,
{ {
@@ -754,7 +751,7 @@ where
impl<Spawner, Context> Subsystem<Context> for CandidateBackingSubsystem<Spawner, Context> impl<Spawner, Context> Subsystem<Context> for CandidateBackingSubsystem<Spawner, Context>
where where
Spawner: Spawn + Send + Clone + Unpin + 'static, Spawner: SpawnNamed + Send + Clone + Unpin + 'static,
Context: SubsystemContext, Context: SubsystemContext,
<Context as SubsystemContext>::Message: Into<ToJob>, <Context as SubsystemContext>::Message: Into<ToJob>,
{ {
@@ -769,10 +766,7 @@ where
mod tests { mod tests {
use super::*; use super::*;
use assert_matches::assert_matches; use assert_matches::assert_matches;
use futures::{ use futures::{executor, future, Future};
executor::{self, ThreadPool},
future, Future,
};
use polkadot_primitives::v1::{ use polkadot_primitives::v1::{
AssignmentKind, BlockData, CandidateCommitments, CollatorId, CoreAssignment, CoreIndex, AssignmentKind, BlockData, CandidateCommitments, CollatorId, CoreAssignment, CoreIndex,
LocalValidationData, GlobalValidationSchedule, GroupIndex, HeadData, LocalValidationData, GlobalValidationSchedule, GroupIndex, HeadData,
@@ -905,7 +899,7 @@ mod tests {
} }
fn test_harness<T: Future<Output=()>>(keystore: KeyStorePtr, test: impl FnOnce(TestHarness) -> T) { fn test_harness<T: Future<Output=()>>(keystore: KeyStorePtr, test: impl FnOnce(TestHarness) -> T) {
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (context, virtual_overseer) = subsystem_test::make_subsystem_context(pool.clone()); let (context, virtual_overseer) = subsystem_test::make_subsystem_context(pool.clone());
+1
View File
@@ -20,3 +20,4 @@ polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsys
parking_lot = "0.10.0" parking_lot = "0.10.0"
subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" } subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" }
assert_matches = "1.3.0" assert_matches = "1.3.0"
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
+6 -4
View File
@@ -184,7 +184,10 @@ impl<Net, Context> Subsystem<Context> for NetworkBridge<Net>
fn start(self, ctx: Context) -> SpawnedSubsystem { fn start(self, ctx: Context) -> SpawnedSubsystem {
// Swallow error because failure is fatal to the node and we log with more precision // Swallow error because failure is fatal to the node and we log with more precision
// within `run_network`. // within `run_network`.
SpawnedSubsystem(run_network(self.0, ctx).map(|_| ()).boxed()) SpawnedSubsystem {
name: "network-bridge-subsystem",
future: run_network(self.0, ctx).map(|_| ()).boxed(),
}
} }
} }
@@ -521,7 +524,7 @@ async fn run_network<N: Network>(
mod tests { mod tests {
use super::*; use super::*;
use futures::channel::mpsc; use futures::channel::mpsc;
use futures::executor::{self, ThreadPool}; use futures::executor;
use std::sync::Arc; use std::sync::Arc;
use parking_lot::Mutex; use parking_lot::Mutex;
@@ -632,8 +635,7 @@ mod tests {
} }
fn test_harness<T: Future<Output=()>>(test: impl FnOnce(TestHarness) -> T) { fn test_harness<T: Future<Output=()>>(test: impl FnOnce(TestHarness) -> T) {
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (network, network_handle) = new_test_network(); let (network, network_handle) = new_test_network();
let (context, virtual_overseer) = subsystem_test::make_subsystem_context(pool); let (context, virtual_overseer) = subsystem_test::make_subsystem_context(pool);
@@ -20,3 +20,4 @@ polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsys
parking_lot = "0.10.0" parking_lot = "0.10.0"
subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" } subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" }
assert_matches = "1.3.0" assert_matches = "1.3.0"
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
@@ -69,7 +69,10 @@ impl<C> Subsystem<C> for PoVDistribution
fn start(self, ctx: C) -> SpawnedSubsystem { fn start(self, ctx: C) -> SpawnedSubsystem {
// Swallow error because failure is fatal to the node and we log with more precision // Swallow error because failure is fatal to the node and we log with more precision
// within `run`. // within `run`.
SpawnedSubsystem(run(ctx).map(|_| ()).boxed()) SpawnedSubsystem {
name: "pov-distribution-subsystem",
future: run(ctx).map(|_| ()).boxed(),
}
} }
} }
@@ -548,7 +551,7 @@ async fn run(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use futures::executor::{self, ThreadPool}; use futures::executor;
use polkadot_primitives::v1::BlockData; use polkadot_primitives::v1::BlockData;
use assert_matches::assert_matches; use assert_matches::assert_matches;
@@ -616,7 +619,7 @@ mod tests {
our_view: View(vec![hash_a, hash_b]), our_view: View(vec![hash_a, hash_b]),
}; };
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool); let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let mut descriptor = CandidateDescriptor::default(); let mut descriptor = CandidateDescriptor::default();
descriptor.pov_hash = pov_hash; descriptor.pov_hash = pov_hash;
@@ -696,7 +699,7 @@ mod tests {
our_view: View(vec![hash_a]), our_view: View(vec![hash_a]),
}; };
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool); let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let mut descriptor = CandidateDescriptor::default(); let mut descriptor = CandidateDescriptor::default();
descriptor.pov_hash = pov_hash; descriptor.pov_hash = pov_hash;
@@ -774,7 +777,7 @@ mod tests {
our_view: View(vec![hash_a]), our_view: View(vec![hash_a]),
}; };
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool); let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
executor::block_on(async move { executor::block_on(async move {
@@ -846,7 +849,7 @@ mod tests {
our_view: View(vec![hash_a]), our_view: View(vec![hash_a]),
}; };
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool); let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
executor::block_on(async move { executor::block_on(async move {
@@ -934,7 +937,7 @@ mod tests {
our_view: View(vec![hash_a]), our_view: View(vec![hash_a]),
}; };
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool); let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
executor::block_on(async move { executor::block_on(async move {
@@ -997,7 +1000,7 @@ mod tests {
our_view: View(vec![hash_a]), our_view: View(vec![hash_a]),
}; };
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool); let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
executor::block_on(async move { executor::block_on(async move {
@@ -1058,7 +1061,7 @@ mod tests {
our_view: View(vec![hash_a]), our_view: View(vec![hash_a]),
}; };
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool); let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
executor::block_on(async move { executor::block_on(async move {
@@ -1116,7 +1119,7 @@ mod tests {
our_view: View(vec![hash_a]), our_view: View(vec![hash_a]),
}; };
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool); let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
executor::block_on(async move { executor::block_on(async move {
@@ -1201,7 +1204,7 @@ mod tests {
our_view: View(vec![hash_a, hash_b]), our_view: View(vec![hash_a, hash_b]),
}; };
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool); let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
executor::block_on(async move { executor::block_on(async move {
@@ -1263,7 +1266,7 @@ mod tests {
our_view: View(vec![hash_a]), our_view: View(vec![hash_a]),
}; };
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool); let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
executor::block_on(async move { executor::block_on(async move {
@@ -1340,7 +1343,7 @@ mod tests {
our_view: View(vec![hash_a]), our_view: View(vec![hash_a]),
}; };
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool); let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
executor::block_on(async move { executor::block_on(async move {
@@ -1424,7 +1427,7 @@ mod tests {
our_view: View(vec![hash_a]), our_view: View(vec![hash_a]),
}; };
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool); let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
executor::block_on(async move { executor::block_on(async move {
@@ -24,3 +24,4 @@ parking_lot = "0.10.0"
subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" } subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" }
assert_matches = "1.3.0" assert_matches = "1.3.0"
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
@@ -70,7 +70,10 @@ impl<C> Subsystem<C> for StatementDistribution
fn start(self, ctx: C) -> SpawnedSubsystem { fn start(self, ctx: C) -> SpawnedSubsystem {
// Swallow error because failure is fatal to the node and we log with more precision // Swallow error because failure is fatal to the node and we log with more precision
// within `run`. // within `run`.
SpawnedSubsystem(run(ctx).map(|_| ()).boxed()) SpawnedSubsystem {
name: "statement-distribution-subsystem",
future: run(ctx).map(|_| ()).boxed(),
}
} }
} }
@@ -892,7 +895,7 @@ mod tests {
use node_primitives::Statement; use node_primitives::Statement;
use polkadot_primitives::v1::CommittedCandidateReceipt; use polkadot_primitives::v1::CommittedCandidateReceipt;
use assert_matches::assert_matches; use assert_matches::assert_matches;
use futures::executor::{self, ThreadPool}; use futures::executor;
#[test] #[test]
fn active_head_accepts_only_2_seconded_per_validator() { fn active_head_accepts_only_2_seconded_per_validator() {
@@ -1209,7 +1212,7 @@ mod tests {
}, },
}; };
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool); let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
let peer = PeerId::random(); let peer = PeerId::random();
@@ -1301,7 +1304,7 @@ mod tests {
(peer_c.clone(), peer_data_from_view(peer_c_view)), (peer_c.clone(), peer_data_from_view(peer_c_view)),
].into_iter().collect(); ].into_iter().collect();
let pool = ThreadPool::new().unwrap(); let pool = sp_core::testing::SpawnBlockingExecutor::new();
let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool); let (mut ctx, mut handle) = subsystem_test::make_subsystem_context(pool);
executor::block_on(async move { executor::block_on(async move {
+2
View File
@@ -12,9 +12,11 @@ streamunordered = "0.5.1"
polkadot-primitives = { path = "../../primitives" } polkadot-primitives = { path = "../../primitives" }
client = { package = "sc-client-api", git = "https://github.com/paritytech/substrate", branch = "master" } client = { package = "sc-client-api", git = "https://github.com/paritytech/substrate", branch = "master" }
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../subsystem" } polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../subsystem" }
polkadot-node-primitives = { package = "polkadot-node-primitives", path = "../primitives" }
async-trait = "0.1" async-trait = "0.1"
[dev-dependencies] [dev-dependencies]
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
futures = { version = "0.3.5", features = ["thread-pool"] } futures = { version = "0.3.5", features = ["thread-pool"] }
futures-timer = "3.0.2" futures-timer = "3.0.2"
femme = "2.0.1" femme = "2.0.1"
@@ -21,7 +21,7 @@
use std::time::Duration; use std::time::Duration;
use futures::{ use futures::{
channel::oneshot, channel::oneshot,
pending, pin_mut, executor, select, stream, pending, pin_mut, select, stream,
FutureExt, StreamExt, FutureExt, StreamExt,
}; };
use futures_timer::Delay; use futures_timer::Delay;
@@ -77,9 +77,14 @@ impl<C> Subsystem<C> for Subsystem1
where C: SubsystemContext<Message=CandidateBackingMessage> where C: SubsystemContext<Message=CandidateBackingMessage>
{ {
fn start(self, ctx: C) -> SpawnedSubsystem { fn start(self, ctx: C) -> SpawnedSubsystem {
SpawnedSubsystem(Box::pin(async move { let future = Box::pin(async move {
Self::run(ctx).await; Self::run(ctx).await;
})) });
SpawnedSubsystem {
name: "subsystem-1",
future,
}
} }
} }
@@ -87,12 +92,15 @@ struct Subsystem2;
impl Subsystem2 { impl Subsystem2 {
async fn run(mut ctx: impl SubsystemContext<Message=CandidateValidationMessage>) { async fn run(mut ctx: impl SubsystemContext<Message=CandidateValidationMessage>) {
ctx.spawn(Box::pin(async { ctx.spawn(
loop { "subsystem-2-job",
log::info!("Job tick"); Box::pin(async {
Delay::new(Duration::from_secs(1)).await; loop {
} log::info!("Job tick");
})).await.unwrap(); Delay::new(Duration::from_secs(1)).await;
}
}),
).await.unwrap();
loop { loop {
match ctx.try_recv().await { match ctx.try_recv().await {
@@ -114,16 +122,20 @@ impl<C> Subsystem<C> for Subsystem2
where C: SubsystemContext<Message=CandidateValidationMessage> where C: SubsystemContext<Message=CandidateValidationMessage>
{ {
fn start(self, ctx: C) -> SpawnedSubsystem { fn start(self, ctx: C) -> SpawnedSubsystem {
SpawnedSubsystem(Box::pin(async move { let future = Box::pin(async move {
Self::run(ctx).await; Self::run(ctx).await;
})) });
SpawnedSubsystem {
name: "subsystem-2",
future,
}
} }
} }
fn main() { fn main() {
femme::with_level(femme::LevelFilter::Trace); femme::with_level(femme::LevelFilter::Trace);
let spawner = executor::ThreadPool::new().unwrap(); let spawner = sp_core::testing::SpawnBlockingExecutor::new();
futures::executor::block_on(async { futures::executor::block_on(async {
let timer_stream = stream::repeat(()).then(|_| async { let timer_stream = stream::repeat(()).then(|_| async {
Delay::new(Duration::from_secs(1)).await; Delay::new(Duration::from_secs(1)).await;
+128 -104
View File
@@ -64,9 +64,8 @@ use std::collections::HashSet;
use futures::channel::{mpsc, oneshot}; use futures::channel::{mpsc, oneshot};
use futures::{ use futures::{
pending, poll, select, pending, poll, select,
future::{BoxFuture, RemoteHandle}, future::BoxFuture,
stream::{self, FuturesUnordered}, stream::{self, FuturesUnordered},
task::{Spawn, SpawnExt},
Future, FutureExt, SinkExt, StreamExt, Future, FutureExt, SinkExt, StreamExt,
}; };
use futures_timer::Delay; use futures_timer::Delay;
@@ -86,6 +85,7 @@ pub use polkadot_subsystem::{
Subsystem, SubsystemContext, OverseerSignal, FromOverseer, SubsystemError, SubsystemResult, Subsystem, SubsystemContext, OverseerSignal, FromOverseer, SubsystemError, SubsystemResult,
SpawnedSubsystem, SpawnedSubsystem,
}; };
use polkadot_node_primitives::SpawnNamed;
// A capacity of bounded channels inside the overseer. // A capacity of bounded channels inside the overseer.
@@ -109,8 +109,8 @@ enum ToOverseer {
/// spawn on the overseer and a `oneshot::Sender` to signal the result /// spawn on the overseer and a `oneshot::Sender` to signal the result
/// of the spawn. /// of the spawn.
SpawnJob { SpawnJob {
name: &'static str,
s: BoxFuture<'static, ()>, s: BoxFuture<'static, ()>,
res: oneshot::Sender<SubsystemResult<()>>,
}, },
} }
@@ -279,14 +279,15 @@ impl<M: Send + 'static> SubsystemContext for OverseerSubsystemContext<M> {
self.rx.next().await.ok_or(SubsystemError) self.rx.next().await.ok_or(SubsystemError)
} }
async fn spawn(&mut self, s: Pin<Box<dyn Future<Output = ()> + Send>>) -> SubsystemResult<()> { async fn spawn(&mut self, name: &'static str, s: Pin<Box<dyn Future<Output = ()> + Send>>)
let (tx, rx) = oneshot::channel(); -> SubsystemResult<()>
{
self.tx.send(ToOverseer::SpawnJob { self.tx.send(ToOverseer::SpawnJob {
name,
s, s,
res: tx,
}).await?; }).await?;
rx.await? Ok(())
} }
async fn send_message(&mut self, msg: AllMessages) -> SubsystemResult<()> { async fn send_message(&mut self, msg: AllMessages) -> SubsystemResult<()> {
@@ -322,7 +323,7 @@ struct OverseenSubsystem<M> {
} }
/// The `Overseer` itself. /// The `Overseer` itself.
pub struct Overseer<S: Spawn> { pub struct Overseer<S: SpawnNamed> {
/// A candidate validation subsystem. /// A candidate validation subsystem.
candidate_validation_subsystem: OverseenSubsystem<CandidateValidationMessage>, candidate_validation_subsystem: OverseenSubsystem<CandidateValidationMessage>,
@@ -361,7 +362,7 @@ pub struct Overseer<S: Spawn> {
s: S, s: S,
/// Here we keep handles to spawned subsystems to be notified when they terminate. /// Here we keep handles to spawned subsystems to be notified when they terminate.
running_subsystems: FuturesUnordered<RemoteHandle<()>>, running_subsystems: FuturesUnordered<BoxFuture<'static, ()>>,
/// Gather running subsystms' outbound streams into one. /// Gather running subsystms' outbound streams into one.
running_subsystems_rx: StreamUnordered<mpsc::Receiver<ToOverseer>>, running_subsystems_rx: StreamUnordered<mpsc::Receiver<ToOverseer>>,
@@ -416,7 +417,7 @@ pub struct AllSubsystems<CV, CB, CS, SD, AD, BD, P, PoVD, RA, AS, NB> {
impl<S> Overseer<S> impl<S> Overseer<S>
where where
S: Spawn, S: SpawnNamed,
{ {
/// Create a new intance of the `Overseer` with a fixed set of [`Subsystem`]s. /// Create a new intance of the `Overseer` with a fixed set of [`Subsystem`]s.
/// ///
@@ -467,16 +468,19 @@ where
/// self, /// self,
/// mut ctx: C, /// mut ctx: C,
/// ) -> SpawnedSubsystem { /// ) -> SpawnedSubsystem {
/// SpawnedSubsystem(Box::pin(async move { /// SpawnedSubsystem {
/// loop { /// name: "validation-subsystem",
/// Delay::new(Duration::from_secs(1)).await; /// future: Box::pin(async move {
/// } /// loop {
/// })) /// Delay::new(Duration::from_secs(1)).await;
/// }
/// }),
/// }
/// } /// }
/// } /// }
/// ///
/// # fn main() { executor::block_on(async move { /// # fn main() { executor::block_on(async move {
/// let spawner = executor::ThreadPool::new().unwrap(); /// let spawner = sp_core::testing::SpawnBlockingExecutor::new();
/// let all_subsystems = AllSubsystems { /// let all_subsystems = AllSubsystems {
/// candidate_validation: ValidationSubsystem, /// candidate_validation: ValidationSubsystem,
/// candidate_backing: DummySubsystem, /// candidate_backing: DummySubsystem,
@@ -737,10 +741,8 @@ where
) { ) {
match msg { match msg {
ToOverseer::SubsystemMessage(msg) => self.route_message(msg).await, ToOverseer::SubsystemMessage(msg) => self.route_message(msg).await,
ToOverseer::SpawnJob { s, res } => { ToOverseer::SpawnJob { name, s } => {
let s = self.spawn_job(s); self.spawn_job(name, s);
let _ = res.send(s);
} }
} }
} }
@@ -897,26 +899,33 @@ where
} }
} }
fn spawn_job(&mut self, j: BoxFuture<'static, ()>) -> SubsystemResult<()> { fn spawn_job(&mut self, name: &'static str, j: BoxFuture<'static, ()>) {
self.s.spawn(j).map_err(|_| SubsystemError) self.s.spawn(name, j);
} }
} }
fn spawn<S: Spawn, M: Send + 'static>( fn spawn<S: SpawnNamed, M: Send + 'static>(
spawner: &mut S, spawner: &mut S,
futures: &mut FuturesUnordered<RemoteHandle<()>>, futures: &mut FuturesUnordered<BoxFuture<'static, ()>>,
streams: &mut StreamUnordered<mpsc::Receiver<ToOverseer>>, streams: &mut StreamUnordered<mpsc::Receiver<ToOverseer>>,
s: impl Subsystem<OverseerSubsystemContext<M>>, s: impl Subsystem<OverseerSubsystemContext<M>>,
) -> SubsystemResult<OverseenSubsystem<M>> { ) -> SubsystemResult<OverseenSubsystem<M>> {
let (to_tx, to_rx) = mpsc::channel(CHANNEL_CAPACITY); let (to_tx, to_rx) = mpsc::channel(CHANNEL_CAPACITY);
let (from_tx, from_rx) = mpsc::channel(CHANNEL_CAPACITY); let (from_tx, from_rx) = mpsc::channel(CHANNEL_CAPACITY);
let ctx = OverseerSubsystemContext { rx: to_rx, tx: from_tx }; let ctx = OverseerSubsystemContext { rx: to_rx, tx: from_tx };
let f = s.start(ctx); let SpawnedSubsystem { future, name } = s.start(ctx);
let handle = spawner.spawn_with_handle(f.0)?; let (tx, rx) = oneshot::channel();
let fut = Box::pin(async move {
future.await;
let _ = tx.send(());
});
spawner.spawn(name, fut);
streams.push(from_rx); streams.push(from_rx);
futures.push(handle); futures.push(Box::pin(rx.map(|_| ())));
let instance = Some(SubsystemInstance { let instance = Some(SubsystemInstance {
tx: to_tx, tx: to_tx,
@@ -944,21 +953,24 @@ mod tests {
{ {
fn start(self, mut ctx: C) -> SpawnedSubsystem { fn start(self, mut ctx: C) -> SpawnedSubsystem {
let mut sender = self.0; let mut sender = self.0;
SpawnedSubsystem(Box::pin(async move { SpawnedSubsystem {
let mut i = 0; name: "test-subsystem-1",
loop { future: Box::pin(async move {
match ctx.recv().await { let mut i = 0;
Ok(FromOverseer::Communication { .. }) => { loop {
let _ = sender.send(i).await; match ctx.recv().await {
i += 1; Ok(FromOverseer::Communication { .. }) => {
continue; let _ = sender.send(i).await;
i += 1;
continue;
}
Ok(FromOverseer::Signal(OverseerSignal::Conclude)) => return,
Err(_) => return,
_ => (),
} }
Ok(FromOverseer::Signal(OverseerSignal::Conclude)) => return,
Err(_) => return,
_ => (),
} }
} }),
})) }
} }
} }
@@ -969,39 +981,42 @@ mod tests {
{ {
fn start(self, mut ctx: C) -> SpawnedSubsystem { fn start(self, mut ctx: C) -> SpawnedSubsystem {
let sender = self.0.clone(); let sender = self.0.clone();
SpawnedSubsystem(Box::pin(async move { SpawnedSubsystem {
let _sender = sender; name: "test-subsystem-2",
let mut c: usize = 0; future: Box::pin(async move {
loop { let _sender = sender;
if c < 10 { let mut c: usize = 0;
let (tx, _) = oneshot::channel(); loop {
ctx.send_message( if c < 10 {
AllMessages::CandidateValidation( let (tx, _) = oneshot::channel();
CandidateValidationMessage::ValidateFromChainState( ctx.send_message(
Default::default(), AllMessages::CandidateValidation(
PoV { CandidateValidationMessage::ValidateFromChainState(
block_data: BlockData(Vec::new()), Default::default(),
}.into(), PoV {
tx, block_data: BlockData(Vec::new()),
}.into(),
tx,
)
) )
) ).await.unwrap();
).await.unwrap(); c += 1;
c += 1;
continue;
}
match ctx.try_recv().await {
Ok(Some(FromOverseer::Signal(OverseerSignal::Conclude))) => {
break;
}
Ok(Some(_)) => {
continue; continue;
} }
Err(_) => return, match ctx.try_recv().await {
_ => (), Ok(Some(FromOverseer::Signal(OverseerSignal::Conclude))) => {
break;
}
Ok(Some(_)) => {
continue;
}
Err(_) => return,
_ => (),
}
pending!();
} }
pending!(); }),
} }
}))
} }
} }
@@ -1011,16 +1026,19 @@ mod tests {
where C: SubsystemContext<Message=CandidateBackingMessage> where C: SubsystemContext<Message=CandidateBackingMessage>
{ {
fn start(self, mut _ctx: C) -> SpawnedSubsystem { fn start(self, mut _ctx: C) -> SpawnedSubsystem {
SpawnedSubsystem(Box::pin(async move { SpawnedSubsystem {
// Do nothing and exit. name: "test-subsystem-4",
})) future: Box::pin(async move {
// Do nothing and exit.
}),
}
} }
} }
// Checks that a minimal configuration of two jobs can run and exchange messages. // Checks that a minimal configuration of two jobs can run and exchange messages.
#[test] #[test]
fn overseer_works() { fn overseer_works() {
let spawner = executor::ThreadPool::new().unwrap(); let spawner = sp_core::testing::SpawnBlockingExecutor::new();
executor::block_on(async move { executor::block_on(async move {
let (s1_tx, mut s1_rx) = mpsc::channel(64); let (s1_tx, mut s1_rx) = mpsc::channel(64);
@@ -1084,7 +1102,7 @@ mod tests {
// Should immediately conclude the overseer itself with an error. // Should immediately conclude the overseer itself with an error.
#[test] #[test]
fn overseer_panics_on_subsystem_exit() { fn overseer_panics_on_subsystem_exit() {
let spawner = executor::ThreadPool::new().unwrap(); let spawner = sp_core::testing::SpawnBlockingExecutor::new();
executor::block_on(async move { executor::block_on(async move {
let (s1_tx, _) = mpsc::channel(64); let (s1_tx, _) = mpsc::channel(64);
@@ -1124,21 +1142,24 @@ mod tests {
fn start(self, mut ctx: C) -> SpawnedSubsystem { fn start(self, mut ctx: C) -> SpawnedSubsystem {
let mut sender = self.0.clone(); let mut sender = self.0.clone();
SpawnedSubsystem(Box::pin(async move { SpawnedSubsystem {
loop { name: "test-subsystem-5",
match ctx.try_recv().await { future: Box::pin(async move {
Ok(Some(FromOverseer::Signal(OverseerSignal::Conclude))) => break, loop {
Ok(Some(FromOverseer::Signal(s))) => { match ctx.try_recv().await {
sender.send(s).await.unwrap(); Ok(Some(FromOverseer::Signal(OverseerSignal::Conclude))) => break,
continue; Ok(Some(FromOverseer::Signal(s))) => {
}, sender.send(s).await.unwrap();
Ok(Some(_)) => continue, continue;
Err(_) => return, },
_ => (), Ok(Some(_)) => continue,
Err(_) => return,
_ => (),
}
pending!();
} }
pending!(); }),
} }
}))
} }
} }
@@ -1150,21 +1171,24 @@ mod tests {
fn start(self, mut ctx: C) -> SpawnedSubsystem { fn start(self, mut ctx: C) -> SpawnedSubsystem {
let mut sender = self.0.clone(); let mut sender = self.0.clone();
SpawnedSubsystem(Box::pin(async move { SpawnedSubsystem {
loop { name: "test-subsystem-6",
match ctx.try_recv().await { future: Box::pin(async move {
Ok(Some(FromOverseer::Signal(OverseerSignal::Conclude))) => break, loop {
Ok(Some(FromOverseer::Signal(s))) => { match ctx.try_recv().await {
sender.send(s).await.unwrap(); Ok(Some(FromOverseer::Signal(OverseerSignal::Conclude))) => break,
continue; Ok(Some(FromOverseer::Signal(s))) => {
}, sender.send(s).await.unwrap();
Ok(Some(_)) => continue, continue;
Err(_) => return, },
_ => (), Ok(Some(_)) => continue,
Err(_) => return,
_ => (),
}
pending!();
} }
pending!(); }),
} }
}))
} }
} }
@@ -1172,7 +1196,7 @@ mod tests {
// notifications on imported blocks triggers expected `StartWork` and `StopWork` heartbeats. // notifications on imported blocks triggers expected `StartWork` and `StopWork` heartbeats.
#[test] #[test]
fn overseer_start_stop_works() { fn overseer_start_stop_works() {
let spawner = executor::ThreadPool::new().unwrap(); let spawner = sp_core::testing::SpawnBlockingExecutor::new();
executor::block_on(async move { executor::block_on(async move {
let first_block_hash = [1; 32].into(); let first_block_hash = [1; 32].into();
@@ -1267,7 +1291,7 @@ mod tests {
// notifications on imported blocks triggers expected `StartWork` and `StopWork` heartbeats. // notifications on imported blocks triggers expected `StartWork` and `StopWork` heartbeats.
#[test] #[test]
fn overseer_finalize_works() { fn overseer_finalize_works() {
let spawner = executor::ThreadPool::new().unwrap(); let spawner = sp_core::testing::SpawnBlockingExecutor::new();
executor::block_on(async move { executor::block_on(async move {
let first_block_hash = [1; 32].into(); let first_block_hash = [1; 32].into();
+1
View File
@@ -11,3 +11,4 @@ polkadot-statement-table = { path = "../../statement-table" }
parity-scale-codec = { version = "1.3.0", default-features = false, features = ["derive"] } parity-scale-codec = { version = "1.3.0", default-features = false, features = ["derive"] }
runtime_primitives = { package = "sp-runtime", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } runtime_primitives = { package = "sp-runtime", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
async-trait = "0.1" async-trait = "0.1"
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
+2
View File
@@ -35,6 +35,8 @@ use polkadot_statement_table::{
v1::Misbehavior as TableMisbehavior, v1::Misbehavior as TableMisbehavior,
}; };
pub use sp_core::traits::SpawnNamed;
/// A statement, where the candidate receipt is included in the `Seconded` variant. /// A statement, where the candidate receipt is included in the `Seconded` variant.
/// ///
/// This is the committed candidate receipt instead of the bare candidate receipt. As such, /// This is the committed candidate receipt instead of the bare candidate receipt. As such,
+2 -1
View File
@@ -33,6 +33,7 @@ use polkadot_overseer::{self as overseer, AllSubsystems, BlockInfo, Overseer, Ov
use polkadot_subsystem::DummySubsystem; use polkadot_subsystem::DummySubsystem;
use polkadot_node_core_proposer::ProposerFactory; use polkadot_node_core_proposer::ProposerFactory;
use sp_trie::PrefixedMemoryDB; use sp_trie::PrefixedMemoryDB;
use sp_core::traits::SpawnNamed;
pub use service::{ pub use service::{
Role, PruningMode, TransactionPoolOptions, Error, RuntimeGenesis, Role, PruningMode, TransactionPoolOptions, Error, RuntimeGenesis,
TFullClient, TLightClient, TFullBackend, TLightBackend, TFullCallExecutor, TLightCallExecutor, TFullClient, TLightClient, TFullBackend, TLightBackend, TFullCallExecutor, TLightCallExecutor,
@@ -269,7 +270,7 @@ macro_rules! new_full_start {
}} }}
} }
fn real_overseer<S: futures::task::Spawn>( fn real_overseer<S: SpawnNamed>(
leaves: impl IntoIterator<Item = BlockInfo>, leaves: impl IntoIterator<Item = BlockInfo>,
s: S, s: S,
) -> Result<(Overseer<S>, OverseerHandler), ServiceError> { ) -> Result<(Overseer<S>, OverseerHandler), ServiceError> {
+14 -4
View File
@@ -101,7 +101,12 @@ impl From<std::convert::Infallible> for SubsystemError {
/// An asynchronous subsystem task.. /// An asynchronous subsystem task..
/// ///
/// In essence it's just a newtype wrapping a `BoxFuture`. /// In essence it's just a newtype wrapping a `BoxFuture`.
pub struct SpawnedSubsystem(pub BoxFuture<'static, ()>); pub struct SpawnedSubsystem {
/// Name of the subsystem being spawned.
pub name: &'static str,
/// The task of the subsystem being spawned.
pub future: BoxFuture<'static, ()>,
}
/// A `Result` type that wraps [`SubsystemError`]. /// A `Result` type that wraps [`SubsystemError`].
/// ///
@@ -130,7 +135,7 @@ pub trait SubsystemContext: Send + 'static {
async fn recv(&mut self) -> SubsystemResult<FromOverseer<Self::Message>>; async fn recv(&mut self) -> SubsystemResult<FromOverseer<Self::Message>>;
/// Spawn a child task on the executor. /// Spawn a child task on the executor.
async fn spawn(&mut self, s: Pin<Box<dyn Future<Output = ()> + Send>>) -> SubsystemResult<()>; async fn spawn(&mut self, name: &'static str, s: Pin<Box<dyn Future<Output = ()> + Send>>) -> SubsystemResult<()>;
/// Send a direct message to some other `Subsystem`, routed based on message type. /// Send a direct message to some other `Subsystem`, routed based on message type.
async fn send_message(&mut self, msg: AllMessages) -> SubsystemResult<()>; async fn send_message(&mut self, msg: AllMessages) -> SubsystemResult<()>;
@@ -159,7 +164,7 @@ pub struct DummySubsystem;
impl<C: SubsystemContext> Subsystem<C> for DummySubsystem { impl<C: SubsystemContext> Subsystem<C> for DummySubsystem {
fn start(self, mut ctx: C) -> SpawnedSubsystem { fn start(self, mut ctx: C) -> SpawnedSubsystem {
SpawnedSubsystem(Box::pin(async move { let future = Box::pin(async move {
loop { loop {
match ctx.recv().await { match ctx.recv().await {
Ok(FromOverseer::Signal(OverseerSignal::Conclude)) => return, Ok(FromOverseer::Signal(OverseerSignal::Conclude)) => return,
@@ -167,6 +172,11 @@ impl<C: SubsystemContext> Subsystem<C> for DummySubsystem {
_ => continue, _ => continue,
} }
} }
})) });
SpawnedSubsystem {
name: "DummySubsystem",
future,
}
} }
} }
+17 -12
View File
@@ -30,7 +30,7 @@ use futures::{
prelude::*, prelude::*,
select, select,
stream::Stream, stream::Stream,
task::{self, Spawn, SpawnError, SpawnExt}, task,
}; };
use futures_timer::Delay; use futures_timer::Delay;
use keystore::KeyStorePtr; use keystore::KeyStorePtr;
@@ -40,7 +40,10 @@ use polkadot_primitives::v1::{
EncodeAs, Hash, HeadData, Id as ParaId, Signed, SigningContext, EncodeAs, Hash, HeadData, Id as ParaId, Signed, SigningContext,
ValidatorId, ValidatorIndex, ValidatorPair, ValidatorId, ValidatorIndex, ValidatorPair,
}; };
use sp_core::Pair; use sp_core::{
Pair,
traits::SpawnNamed,
};
use std::{ use std::{
collections::HashMap, collections::HashMap,
convert::{TryFrom, TryInto}, convert::{TryFrom, TryInto},
@@ -64,9 +67,6 @@ pub enum Error {
/// Attempted to send on a MPSC channel which has been canceled /// Attempted to send on a MPSC channel which has been canceled
#[from] #[from]
Mpsc(mpsc::SendError), Mpsc(mpsc::SendError),
/// Attempted to spawn a new task, and failed
#[from]
Spawn(SpawnError),
/// Attempted to convert from an AllMessages to a FromJob, and failed. /// Attempted to convert from an AllMessages to a FromJob, and failed.
SenderConversion(String), SenderConversion(String),
/// The local node is not a validator. /// The local node is not a validator.
@@ -358,7 +358,7 @@ pub struct Jobs<Spawner, Job: JobTrait> {
job: std::marker::PhantomData<Job>, job: std::marker::PhantomData<Job>,
} }
impl<Spawner: Spawn, Job: JobTrait> Jobs<Spawner, Job> { impl<Spawner: SpawnNamed, Job: JobTrait> Jobs<Spawner, Job> {
/// Create a new Jobs manager which handles spawning appropriate jobs. /// Create a new Jobs manager which handles spawning appropriate jobs.
pub fn new(spawner: Spawner) -> Self { pub fn new(spawner: Spawner) -> Self {
Self { Self {
@@ -391,7 +391,7 @@ impl<Spawner: Spawn, Job: JobTrait> Jobs<Spawner, Job> {
let _ = future.await; let _ = future.await;
let _ = finished_tx.send(()); let _ = finished_tx.send(());
}; };
self.spawner.spawn(future)?; self.spawner.spawn(Job::NAME, future.boxed());
// this handle lets us remove the appropriate receiver from self.outgoing_msgs // this handle lets us remove the appropriate receiver from self.outgoing_msgs
// when it's time to stop the job. // when it's time to stop the job.
@@ -444,7 +444,7 @@ impl<Spawner, Job: JobTrait> PinnedDrop for Jobs<Spawner, Job> {
impl<Spawner, Job> Stream for Jobs<Spawner, Job> impl<Spawner, Job> Stream for Jobs<Spawner, Job>
where where
Spawner: Spawn, Spawner: SpawnNamed,
Job: JobTrait, Job: JobTrait,
{ {
type Item = Job::FromJob; type Item = Job::FromJob;
@@ -476,7 +476,7 @@ pub struct JobManager<Spawner, Context, Job: JobTrait> {
impl<Spawner, Context, Job> JobManager<Spawner, Context, Job> impl<Spawner, Context, Job> JobManager<Spawner, Context, Job>
where where
Spawner: Spawn + Clone + Send + Unpin, Spawner: SpawnNamed + Clone + Send + Unpin,
Context: SubsystemContext, Context: SubsystemContext,
Job: JobTrait, Job: JobTrait,
Job::RunArgs: Clone, Job::RunArgs: Clone,
@@ -595,7 +595,7 @@ where
impl<Spawner, Context, Job> Subsystem<Context> for JobManager<Spawner, Context, Job> impl<Spawner, Context, Job> Subsystem<Context> for JobManager<Spawner, Context, Job>
where where
Spawner: Spawn + Send + Clone + Unpin + 'static, Spawner: SpawnNamed + Send + Clone + Unpin + 'static,
Context: SubsystemContext, Context: SubsystemContext,
<Context as SubsystemContext>::Message: Into<Job::ToJob>, <Context as SubsystemContext>::Message: Into<Job::ToJob>,
Job: JobTrait + Send, Job: JobTrait + Send,
@@ -606,8 +606,13 @@ where
let spawner = self.spawner.clone(); let spawner = self.spawner.clone();
let run_args = self.run_args.clone(); let run_args = self.run_args.clone();
SpawnedSubsystem(Box::pin(async move { let future = Box::pin(async move {
Self::run(ctx, run_args, spawner).await; Self::run(ctx, run_args, spawner).await;
})) });
SpawnedSubsystem {
name: "JobManager",
future,
}
} }
} }
@@ -10,3 +10,4 @@ futures = "0.3.5"
async-trait = "0.1" async-trait = "0.1"
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem" } polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem" }
parking_lot = "0.10.0" parking_lot = "0.10.0"
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
@@ -21,9 +21,9 @@ use polkadot_subsystem::messages::AllMessages;
use futures::prelude::*; use futures::prelude::*;
use futures::channel::mpsc; use futures::channel::mpsc;
use futures::task::{Spawn, SpawnExt};
use futures::poll; use futures::poll;
use parking_lot::Mutex; use parking_lot::Mutex;
use sp_core::traits::SpawnNamed;
use std::convert::Infallible; use std::convert::Infallible;
use std::pin::Pin; use std::pin::Pin;
@@ -155,7 +155,7 @@ pub struct TestSubsystemContext<M, S> {
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<M: Send + 'static, S: Spawn + Send + 'static> SubsystemContext for TestSubsystemContext<M, S> { impl<M: Send + 'static, S: SpawnNamed + Send + 'static> SubsystemContext for TestSubsystemContext<M, S> {
type Message = M; type Message = M;
async fn try_recv(&mut self) -> Result<Option<FromOverseer<M>>, ()> { async fn try_recv(&mut self) -> Result<Option<FromOverseer<M>>, ()> {
@@ -170,8 +170,11 @@ impl<M: Send + 'static, S: Spawn + Send + 'static> SubsystemContext for TestSubs
self.rx.next().await.ok_or(SubsystemError) self.rx.next().await.ok_or(SubsystemError)
} }
async fn spawn(&mut self, s: Pin<Box<dyn Future<Output = ()> + Send>>) -> SubsystemResult<()> { async fn spawn(&mut self, name: &'static str, s: Pin<Box<dyn Future<Output = ()> + Send>>)
self.spawn.spawn(s).map_err(Into::into) -> SubsystemResult<()>
{
self.spawn.spawn(name, s);
Ok(())
} }
async fn send_message(&mut self, msg: AllMessages) -> SubsystemResult<()> { async fn send_message(&mut self, msg: AllMessages) -> SubsystemResult<()> {