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

Commit

Permalink
Remove TaskManagerBuilder (#5725)
Browse files Browse the repository at this point in the history
* Remove TaskManagerBuilder

* Clean up use declaration fo SpawnTaskHandle

Co-Authored-By: Pierre Krieger <[email protected]>

Co-authored-by: Pierre Krieger <[email protected]>
  • Loading branch information
pscott and tomaka authored Apr 21, 2020
1 parent fa7bd73 commit 761d3c8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 122 deletions.
54 changes: 27 additions & 27 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

use crate::{Service, NetworkStatus, NetworkState, error::Error, DEFAULT_PROTOCOL_ID, MallocSizeOfWasm};
use crate::{TaskManagerBuilder, start_rpc_servers, build_network_future, TransactionPoolAdapter};
use crate::{start_rpc_servers, build_network_future, TransactionPoolAdapter, TaskManager};
use crate::status_sinks;
use crate::config::{Configuration, KeystoreConfig, PrometheusConfig};
use crate::metrics::MetricsService;
Expand Down Expand Up @@ -81,7 +81,7 @@ pub struct ServiceBuilder<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp,
config: Configuration,
pub (crate) client: Arc<TCl>,
backend: Arc<Backend>,
tasks_builder: TaskManagerBuilder,
task_manager: TaskManager,
keystore: Arc<RwLock<Keystore>>,
fetcher: Option<TFchr>,
select_chain: Option<TSc>,
Expand Down Expand Up @@ -145,7 +145,7 @@ type TFullParts<TBl, TRtApi, TExecDisp> = (
TFullClient<TBl, TRtApi, TExecDisp>,
Arc<TFullBackend<TBl>>,
Arc<RwLock<sc_keystore::Store>>,
TaskManagerBuilder,
TaskManager,
);

/// Creates a new full client for the given config.
Expand All @@ -172,9 +172,9 @@ fn new_full_parts<TBl, TRtApi, TExecDisp>(
KeystoreConfig::InMemory => Keystore::new_in_memory(),
};

let tasks_builder = {
let task_manager = {
let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry);
TaskManagerBuilder::new(registry)?
TaskManager::new(config.task_executor.clone(), registry)?
};

let executor = NativeExecutor::<TExecDisp>::new(
Expand Down Expand Up @@ -213,12 +213,12 @@ fn new_full_parts<TBl, TRtApi, TExecDisp>(
fork_blocks,
bad_blocks,
extensions,
Box::new(tasks_builder.spawn_handle()),
Box::new(task_manager.spawn_handle()),
config.prometheus_config.as_ref().map(|config| config.registry.clone()),
)?
};

Ok((client, backend, keystore, tasks_builder))
Ok((client, backend, keystore, task_manager))
}

impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> {
Expand All @@ -238,7 +238,7 @@ impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> {
(),
TFullBackend<TBl>,
>, Error> {
let (client, backend, keystore, tasks_builder) = new_full_parts(&config)?;
let (client, backend, keystore, task_manager) = new_full_parts(&config)?;

let client = Arc::new(client);

Expand All @@ -247,7 +247,7 @@ impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> {
client,
backend,
keystore,
tasks_builder,
task_manager,
fetcher: None,
select_chain: None,
import_queue: (),
Expand Down Expand Up @@ -277,9 +277,9 @@ impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> {
(),
TLightBackend<TBl>,
>, Error> {
let tasks_builder = {
let task_manager = {
let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry);
TaskManagerBuilder::new(registry)?
TaskManager::new(config.task_executor.clone(), registry)?
};

let keystore = match &config.keystore {
Expand Down Expand Up @@ -311,7 +311,7 @@ impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> {
sc_client::light::new_fetch_checker::<_, TBl, _>(
light_blockchain.clone(),
executor.clone(),
Box::new(tasks_builder.spawn_handle()),
Box::new(task_manager.spawn_handle()),
),
);
let fetcher = Arc::new(sc_network::config::OnDemand::new(fetch_checker));
Expand All @@ -321,15 +321,15 @@ impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> {
backend.clone(),
config.chain_spec.as_storage_builder(),
executor,
Box::new(tasks_builder.spawn_handle()),
Box::new(task_manager.spawn_handle()),
config.prometheus_config.as_ref().map(|config| config.registry.clone()),
)?);

Ok(ServiceBuilder {
config,
client,
backend,
tasks_builder,
task_manager,
keystore,
fetcher: Some(fetcher.clone()),
select_chain: None,
Expand Down Expand Up @@ -402,7 +402,7 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
config: self.config,
client: self.client,
backend: self.backend,
tasks_builder: self.tasks_builder,
task_manager: self.task_manager,
keystore: self.keystore,
fetcher: self.fetcher,
select_chain,
Expand Down Expand Up @@ -445,7 +445,7 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
config: self.config,
client: self.client,
backend: self.backend,
tasks_builder: self.tasks_builder,
task_manager: self.task_manager,
keystore: self.keystore,
fetcher: self.fetcher,
select_chain: self.select_chain,
Expand Down Expand Up @@ -483,7 +483,7 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
config: self.config,
client: self.client,
backend: self.backend,
tasks_builder: self.tasks_builder,
task_manager: self.task_manager,
keystore: self.keystore,
fetcher: self.fetcher,
select_chain: self.select_chain,
Expand Down Expand Up @@ -545,7 +545,7 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
config: self.config,
client: self.client,
backend: self.backend,
tasks_builder: self.tasks_builder,
task_manager: self.task_manager,
keystore: self.keystore,
fetcher: self.fetcher,
select_chain: self.select_chain,
Expand Down Expand Up @@ -606,7 +606,7 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
Ok(ServiceBuilder {
config: self.config,
client: self.client,
tasks_builder: self.tasks_builder,
task_manager: self.task_manager,
backend: self.backend,
keystore: self.keystore,
fetcher: self.fetcher,
Expand Down Expand Up @@ -635,7 +635,7 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
config: self.config,
client: self.client,
backend: self.backend,
tasks_builder: self.tasks_builder,
task_manager: self.task_manager,
keystore: self.keystore,
fetcher: self.fetcher,
select_chain: self.select_chain,
Expand Down Expand Up @@ -745,7 +745,7 @@ ServiceBuilder<
marker: _,
mut config,
client,
tasks_builder,
task_manager,
fetcher: on_demand,
backend,
keystore,
Expand Down Expand Up @@ -789,7 +789,7 @@ ServiceBuilder<
imports_external_transactions: !matches!(config.role, Role::Light),
pool: transaction_pool.clone(),
client: client.clone(),
executor: tasks_builder.spawn_handle(),
executor: task_manager.spawn_handle(),
});

let protocol_id = {
Expand All @@ -811,7 +811,7 @@ ServiceBuilder<
let network_params = sc_network::config::Params {
role: config.role.clone(),
executor: {
let spawn_handle = tasks_builder.spawn_handle();
let spawn_handle = task_manager.spawn_handle();
Some(Box::new(move |fut| {
spawn_handle.spawn("libp2p-node", fut);
}))
Expand Down Expand Up @@ -845,7 +845,7 @@ ServiceBuilder<
_ => None,
};

let spawn_handle = tasks_builder.spawn_handle();
let spawn_handle = task_manager.spawn_handle();

// Spawn background tasks which were stacked during the
// service building.
Expand All @@ -857,7 +857,7 @@ ServiceBuilder<
// block notifications
let txpool = Arc::downgrade(&transaction_pool);
let offchain = offchain_workers.as_ref().map(Arc::downgrade);
let notifications_spawn_handle = tasks_builder.spawn_handle();
let notifications_spawn_handle = task_manager.spawn_handle();
let network_state_info: Arc<dyn NetworkStateInfo + Send + Sync> = network.clone();
let is_validator = config.role.is_authority();

Expand Down Expand Up @@ -1013,7 +1013,7 @@ ServiceBuilder<
chain_type: chain_spec.chain_type().clone(),
};

let subscriptions = sc_rpc::Subscriptions::new(Arc::new(tasks_builder.spawn_handle()));
let subscriptions = sc_rpc::Subscriptions::new(Arc::new(task_manager.spawn_handle()));

let (chain, state, child_state) = if let (Some(remote_backend), Some(on_demand)) =
(remote_backend.as_ref(), on_demand.as_ref()) {
Expand Down Expand Up @@ -1145,7 +1145,7 @@ ServiceBuilder<

Ok(Service {
client,
task_manager: tasks_builder.into_task_manager(config.task_executor),
task_manager,
network,
network_status_sinks,
select_chain,
Expand Down
4 changes: 1 addition & 3 deletions client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub use std::{ops::Deref, result::Result, sync::Arc};
#[doc(hidden)]
pub use sc_network::config::{FinalityProofProvider, OnDemand, BoxFinalityProofRequestBuilder};
pub use sc_tracing::TracingReceiver;
pub use task_manager::{TaskManagerBuilder, SpawnTaskHandle};
pub use task_manager::SpawnTaskHandle;
use task_manager::TaskManager;

const DEFAULT_PROTOCOL_ID: &str = "sup";
Expand Down Expand Up @@ -304,8 +304,6 @@ impl<TBl, TCl, TSc, TNetStatus, TNet, TTxPool, TOc> Future for
}
}

this.task_manager.process_receiver(cx);

// The service future never ends.
Poll::Pending
}
Expand Down
Loading

0 comments on commit 761d3c8

Please sign in to comment.