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

Use SpawnNamed instead of Spawn in Overseer #1430

Merged
merged 3 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion node/core/backing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
sp-blockchain = { 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-node-primitives = { path = "../../primitives" }
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem" }
Expand All @@ -20,6 +19,7 @@ derive_more = "0.99.9"
bitvec = { version = "0.17.4", default-features = false, features = ["alloc"] }

[dev-dependencies]
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"] }
subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" }
Expand Down
16 changes: 5 additions & 11 deletions node/core/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use std::sync::Arc;
use bitvec::vec::BitVec;
use futures::{
channel::{mpsc, oneshot},
task::{Spawn, SpawnError},
Future, FutureExt, SinkExt, StreamExt,
};

Expand All @@ -37,7 +36,7 @@ use polkadot_primitives::v1::{
};
use polkadot_node_primitives::{
FromTableMisbehavior, Statement, SignedFullStatement, MisbehaviorReport,
ValidationOutputs, ValidationResult,
ValidationOutputs, ValidationResult, SpawnNamed,
};
use polkadot_subsystem::{
Subsystem, SubsystemContext, SpawnedSubsystem,
Expand Down Expand Up @@ -77,8 +76,6 @@ enum Error {
#[from]
Mpsc(mpsc::SendError),
#[from]
Spawn(SpawnError),
#[from]
UtilError(util::Error),
}

Expand Down Expand Up @@ -735,7 +732,7 @@ pub struct CandidateBackingSubsystem<Spawner, Context> {

impl<Spawner, Context> CandidateBackingSubsystem<Spawner, Context>
where
Spawner: Clone + Spawn + Send + Unpin,
Spawner: Clone + SpawnNamed + Send + Unpin,
Context: SubsystemContext,
ToJob: From<<Context as SubsystemContext>::Message>,
{
Expand All @@ -754,7 +751,7 @@ where

impl<Spawner, Context> Subsystem<Context> for CandidateBackingSubsystem<Spawner, Context>
where
Spawner: Spawn + Send + Clone + Unpin + 'static,
Spawner: SpawnNamed + Send + Clone + Unpin + 'static,
Context: SubsystemContext,
<Context as SubsystemContext>::Message: Into<ToJob>,
{
Expand All @@ -769,10 +766,7 @@ where
mod tests {
use super::*;
use assert_matches::assert_matches;
use futures::{
executor::{self, ThreadPool},
future, Future,
};
use futures::{executor, future, Future};
use polkadot_primitives::v1::{
AssignmentKind, BlockData, CandidateCommitments, CollatorId, CoreAssignment, CoreIndex,
LocalValidationData, GlobalValidationSchedule, GroupIndex, HeadData,
Expand Down Expand Up @@ -905,7 +899,7 @@ mod tests {
}

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());

Expand Down
1 change: 1 addition & 0 deletions node/network/bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsys
parking_lot = "0.10.0"
subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" }
assert_matches = "1.3.0"
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
10 changes: 6 additions & 4 deletions node/network/bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ impl<Net, Context> Subsystem<Context> for NetworkBridge<Net>
fn start(self, ctx: Context) -> SpawnedSubsystem {
// Swallow error because failure is fatal to the node and we log with more precision
// within `run_network`.
SpawnedSubsystem(run_network(self.0, ctx).map(|_| ()).boxed())
SpawnedSubsystem {
name: "network-bridge-subsystem",
future: run_network(self.0, ctx).map(|_| ()).boxed(),
}
}
}

Expand Down Expand Up @@ -521,7 +524,7 @@ async fn run_network<N: Network>(
mod tests {
use super::*;
use futures::channel::mpsc;
use futures::executor::{self, ThreadPool};
use futures::executor;

use std::sync::Arc;
use parking_lot::Mutex;
Expand Down Expand Up @@ -632,8 +635,7 @@ mod tests {
}

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 (context, virtual_overseer) = subsystem_test::make_subsystem_context(pool);

Expand Down
1 change: 1 addition & 0 deletions node/network/pov-distribution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsys
parking_lot = "0.10.0"
subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" }
assert_matches = "1.3.0"
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
31 changes: 17 additions & 14 deletions node/network/pov-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ impl<C> Subsystem<C> for PoVDistribution
fn start(self, ctx: C) -> SpawnedSubsystem {
// Swallow error because failure is fatal to the node and we log with more precision
// within `run`.
SpawnedSubsystem(run(ctx).map(|_| ()).boxed())
SpawnedSubsystem {
name: "pov-distribution-subsystem",
future: run(ctx).map(|_| ()).boxed(),
}
}
}

Expand Down Expand Up @@ -548,7 +551,7 @@ async fn run(
#[cfg(test)]
mod tests {
use super::*;
use futures::executor::{self, ThreadPool};
use futures::executor;
use polkadot_primitives::v1::BlockData;
use assert_matches::assert_matches;

Expand Down Expand Up @@ -616,7 +619,7 @@ mod tests {
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 descriptor = CandidateDescriptor::default();
descriptor.pov_hash = pov_hash;
Expand Down Expand Up @@ -696,7 +699,7 @@ mod tests {
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 descriptor = CandidateDescriptor::default();
descriptor.pov_hash = pov_hash;
Expand Down Expand Up @@ -774,7 +777,7 @@ mod tests {
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);

executor::block_on(async move {
Expand Down Expand Up @@ -846,7 +849,7 @@ mod tests {
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);

executor::block_on(async move {
Expand Down Expand Up @@ -934,7 +937,7 @@ mod tests {
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);

executor::block_on(async move {
Expand Down Expand Up @@ -997,7 +1000,7 @@ mod tests {
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);

executor::block_on(async move {
Expand Down Expand Up @@ -1058,7 +1061,7 @@ mod tests {
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);

executor::block_on(async move {
Expand Down Expand Up @@ -1116,7 +1119,7 @@ mod tests {
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);

executor::block_on(async move {
Expand Down Expand Up @@ -1201,7 +1204,7 @@ mod tests {
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);

executor::block_on(async move {
Expand Down Expand Up @@ -1263,7 +1266,7 @@ mod tests {
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);

executor::block_on(async move {
Expand Down Expand Up @@ -1340,7 +1343,7 @@ mod tests {
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);

executor::block_on(async move {
Expand Down Expand Up @@ -1424,7 +1427,7 @@ mod tests {
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);

executor::block_on(async move {
Expand Down
1 change: 1 addition & 0 deletions node/network/statement-distribution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ parking_lot = "0.10.0"
subsystem-test = { package = "polkadot-subsystem-test-helpers", path = "../../test-helpers/subsystem" }
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" }
11 changes: 7 additions & 4 deletions node/network/statement-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ impl<C> Subsystem<C> for StatementDistribution
fn start(self, ctx: C) -> SpawnedSubsystem {
// Swallow error because failure is fatal to the node and we log with more precision
// within `run`.
SpawnedSubsystem(run(ctx).map(|_| ()).boxed())
SpawnedSubsystem {
name: "statement-distribution-subsystem",
future: run(ctx).map(|_| ()).boxed(),
}
}
}

Expand Down Expand Up @@ -892,7 +895,7 @@ mod tests {
use node_primitives::Statement;
use polkadot_primitives::v1::CommittedCandidateReceipt;
use assert_matches::assert_matches;
use futures::executor::{self, ThreadPool};
use futures::executor;

#[test]
fn active_head_accepts_only_2_seconded_per_validator() {
Expand Down Expand Up @@ -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 peer = PeerId::random();

Expand Down Expand Up @@ -1301,7 +1304,7 @@ mod tests {
(peer_c.clone(), peer_data_from_view(peer_c_view)),
].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);

executor::block_on(async move {
Expand Down
2 changes: 2 additions & 0 deletions node/overseer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ streamunordered = "0.5.1"
polkadot-primitives = { path = "../../primitives" }
client = { package = "sc-client-api", git = "https://github.com/paritytech/substrate", branch = "master" }
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../subsystem" }
polkadot-node-primitives = { package = "polkadot-node-primitives", path = "../primitives" }
async-trait = "0.1"

[dev-dependencies]
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
futures = { version = "0.3.5", features = ["thread-pool"] }
futures-timer = "3.0.2"
femme = "2.0.1"
Expand Down
Loading