node: fix shutdown (#1308)

* node: remove grandpa authority flags

* node: exit-guard grandpa and aura spawned futures

* node: wait for futures to stop running on shutdown

* core: run connectivity tests on same ports

* core: pass on_exit future when starting aura and grandpa

* node: add issue number to todo

* core: fix aura and grandpa tests
This commit is contained in:
André Silva
2018-12-21 16:30:45 +00:00
committed by Robert Habermeier
parent ef8b94656e
commit f8f932d123
7 changed files with 54 additions and 28 deletions
+13 -3
View File
@@ -50,6 +50,7 @@ pub mod chain_spec;
mod service;
mod params;
use tokio::prelude::Future;
use tokio::runtime::Runtime;
pub use cli::{VersionInfo, IntoExit};
use substrate_service::{ServiceFactory, Roles as ServiceRoles};
@@ -136,8 +137,8 @@ pub fn run<I, T, E>(args: I, exit: E, version: cli::VersionInfo) -> error::Resul
let mut runtime = Runtime::new()?;
let executor = runtime.executor();
match config.roles == ServiceRoles::LIGHT {
true => run_until_exit(&mut runtime, service::Factory::new_light(config, executor)?, exit)?,
false => run_until_exit(&mut runtime, service::Factory::new_full(config, executor)?, exit)?,
true => run_until_exit(runtime, service::Factory::new_light(config, executor)?, exit)?,
false => run_until_exit(runtime, service::Factory::new_full(config, executor)?, exit)?,
}
}
}
@@ -145,7 +146,7 @@ pub fn run<I, T, E>(args: I, exit: E, version: cli::VersionInfo) -> error::Resul
}
fn run_until_exit<T, C, E>(
runtime: &mut Runtime,
mut runtime: Runtime,
service: T,
e: E,
) -> error::Result<()>
@@ -161,5 +162,14 @@ fn run_until_exit<T, C, E>(
let _ = runtime.block_on(e.into_exit());
exit_send.fire();
// we eagerly drop the service so that the internal exit future is fired,
// but we need to keep holding a reference to the global telemetry guard
let _telemetry = service.telemetry();
drop(service);
// TODO [andre]: timeout this future #1318
let _ = runtime.shutdown_on_idle().wait();
Ok(())
}
+13 -12
View File
@@ -19,19 +19,20 @@
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
use std::sync::Arc;
use transaction_pool::{self, txpool::{Pool as TransactionPool}};
use node_runtime::{GenesisConfig, RuntimeApi};
use std::time::Duration;
use client;
use consensus::{import_queue, start_aura, AuraImportQueue, SlotDuration, NothingExtra};
use grandpa;
use node_executor;
use primitives::ed25519::Pair;
use node_primitives::{Block, InherentData};
use node_runtime::{GenesisConfig, RuntimeApi};
use substrate_service::{
FactoryFullConfiguration, LightComponents, FullComponents, FullBackend,
FullClient, LightClient, LightBackend, FullExecutor, LightExecutor, TaskExecutor
};
use node_executor;
use consensus::{import_queue, start_aura, AuraImportQueue, SlotDuration, NothingExtra};
use primitives::ed25519::Pair;
use client;
use std::time::Duration;
use grandpa;
use transaction_pool::{self, txpool::{Pool as TransactionPool}};
construct_simple_protocol! {
/// Demo protocol attachment for substrate.
@@ -89,12 +90,13 @@ construct_service_factory! {
block_import.clone(),
proposer,
service.network(),
service.on_exit(),
));
info!("Running Grandpa session as Authority {}", key.public());
}
let voter = grandpa::run_grandpa(
executor.spawn(grandpa::run_grandpa(
grandpa::Config {
local_key,
gossip_duration: Duration::new(4, 0), // FIXME: make this available through chainspec?
@@ -102,9 +104,8 @@ construct_service_factory! {
},
link_half,
grandpa::NetworkBridge::new(service.network()),
)?;
executor.spawn(voter);
service.on_exit(),
)?);
Ok(service)
}