Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
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
43 changes: 28 additions & 15 deletions node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ macro_rules! new_full_start {
($config:expr) => {{
let mut import_setup = None;
let inherent_data_providers = inherents::InherentDataProviders::new();
let mut tasks_to_spawn = None;
let mut tasks_to_spawn = Vec::new();

let builder = substrate_service::ServiceBuilder::new_full::<
node_primitives::Block, node_runtime::RuntimeApi, node_executor::Executor
Expand Down Expand Up @@ -79,7 +79,7 @@ macro_rules! new_full_start {
)?;

import_setup = Some((babe_block_import.clone(), link_half, babe_link));
tasks_to_spawn = Some(vec![Box::new(pruning_task)]);
tasks_to_spawn.push(Box::new(pruning_task));

Ok(import_queue)
})?
Expand All @@ -92,7 +92,7 @@ macro_rules! new_full_start {
);
io
})?;

(builder, import_setup, inherent_data_providers, tasks_to_spawn)
}}
}
Expand All @@ -117,14 +117,12 @@ macro_rules! new_full {
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");

// spawn any futures that were created in the previous setup steps
if let Some(tasks) = tasks_to_spawn.take() {
for task in tasks {
service.spawn_task(
task.select(service.on_exit())
.map(|_| ())
.map_err(|_| ())
);
}
for task in tasks_to_spawn.drain(..) {
service.spawn_task(
task.select(service.on_exit())
.map(|_| ())
.map_err(|_| ())
);
}

if service.config().roles.is_authority() {
Expand Down Expand Up @@ -207,9 +205,12 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon
/// Builds a new service for a light client.
pub fn new_light<C: Send + Default + 'static>(config: Configuration<C, GenesisConfig>)
-> Result<impl AbstractService, ServiceError> {
use futures::Future;

let inherent_data_providers = InherentDataProviders::new();
let mut tasks_to_spawn = Vec::new();

ServiceBuilder::new_light::<Block, RuntimeApi, node_executor::Executor>(config)?
let service = ServiceBuilder::new_light::<Block, RuntimeApi, node_executor::Executor>(config)?
.with_select_chain(|_config, client| {
#[allow(deprecated)]
Ok(LongestChain::new(client.backend().clone()))
Expand All @@ -231,8 +232,7 @@ pub fn new_light<C: Send + Default + 'static>(config: Configuration<C, GenesisCo
let finality_proof_request_builder =
finality_proof_import.create_finality_proof_request_builder();

// FIXME: pruning task isn't started since light client doesn't do `AuthoritySetup`.
let (import_queue, ..) = import_queue(
let (import_queue, _, _, pruning_task) = import_queue(
Config::get_or_compute(&*client)?,
block_import,
None,
Expand All @@ -243,6 +243,8 @@ pub fn new_light<C: Send + Default + 'static>(config: Configuration<C, GenesisCo
Some(transaction_pool)
)?;

tasks_to_spawn.push(Box::new(pruning_task));

Ok((import_queue, finality_proof_request_builder))
})?
.with_network_protocol(|_| Ok(NodeProtocol::new()))?
Expand All @@ -258,7 +260,18 @@ pub fn new_light<C: Send + Default + 'static>(config: Configuration<C, GenesisCo
);
io
})?
.build()
.build()?;

// spawn any futures that were created in the previous setup steps
for task in tasks_to_spawn.drain(..) {
service.spawn_task(
task.select(service.on_exit())
.map(|_| ())
.map_err(|_| ())
);
}

Ok(service)
}

#[cfg(test)]
Expand Down