Skip to content
Snippets Groups Projects
Commit 26eeb5cc authored by Éloïs's avatar Éloïs
Browse files

feat(node): allow manual seal everywhere

parent 16d0c9bb
Branches
Tags
1 merge request!27make manual seal compatible with BABE
...@@ -28,8 +28,8 @@ pub struct Cli { ...@@ -28,8 +28,8 @@ pub struct Cli {
/// When blocks should be sealed in the dev service. /// When blocks should be sealed in the dev service.
/// ///
/// Options are "instant", "manual", or timer interval in milliseconds /// Options are "production", "instant", "manual", or timer interval in milliseconds
#[structopt(long, default_value = "6000")] #[structopt(long, default_value = "production")]
pub sealing: Sealing, pub sealing: Sealing,
} }
...@@ -63,9 +63,11 @@ pub enum Subcommand { ...@@ -63,9 +63,11 @@ pub enum Subcommand {
Benchmark(frame_benchmarking_cli::BenchmarkCmd), Benchmark(frame_benchmarking_cli::BenchmarkCmd),
} }
/// Block authoring scheme to be used by the dev service. /// Block authoring scheme to be used by the node
#[derive(Debug)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Sealing { pub enum Sealing {
/// Author a block using normal runtime behavior (mandatory for production networks)
Production,
/// Author a block immediately upon receiving a transaction into the transaction pool /// Author a block immediately upon receiving a transaction into the transaction pool
Instant, Instant,
/// Author a block upon receiving an RPC command /// Author a block upon receiving an RPC command
...@@ -74,11 +76,18 @@ pub enum Sealing { ...@@ -74,11 +76,18 @@ pub enum Sealing {
Interval(u64), Interval(u64),
} }
impl Sealing {
pub fn is_manual_consensus(self) -> bool {
self != Self::Production
}
}
impl FromStr for Sealing { impl FromStr for Sealing {
type Err = String; type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s { Ok(match s {
"production" => Self::Production,
"instant" => Self::Instant, "instant" => Self::Instant,
"manual" => Self::Manual, "manual" => Self::Manual,
s => { s => {
......
...@@ -152,28 +152,32 @@ pub fn run() -> sc_cli::Result<()> { ...@@ -152,28 +152,32 @@ pub fn run() -> sc_cli::Result<()> {
Some(Subcommand::CheckBlock(cmd)) => { Some(Subcommand::CheckBlock(cmd)) => {
let runner = cli.create_runner(cmd)?; let runner = cli.create_runner(cmd)?;
runner.async_run(|mut config| { runner.async_run(|mut config| {
let (client, _, import_queue, task_manager) = service::new_chain_ops(&mut config)?; let (client, _, import_queue, task_manager) =
service::new_chain_ops(&mut config, cli.sealing.is_manual_consensus())?;
Ok((cmd.run(client, import_queue), task_manager)) Ok((cmd.run(client, import_queue), task_manager))
}) })
} }
Some(Subcommand::ExportBlocks(cmd)) => { Some(Subcommand::ExportBlocks(cmd)) => {
let runner = cli.create_runner(cmd)?; let runner = cli.create_runner(cmd)?;
runner.async_run(|mut config| { runner.async_run(|mut config| {
let (client, _, _, task_manager) = service::new_chain_ops(&mut config)?; let (client, _, _, task_manager) =
service::new_chain_ops(&mut config, cli.sealing.is_manual_consensus())?;
Ok((cmd.run(client, config.database), task_manager)) Ok((cmd.run(client, config.database), task_manager))
}) })
} }
Some(Subcommand::ExportState(cmd)) => { Some(Subcommand::ExportState(cmd)) => {
let runner = cli.create_runner(cmd)?; let runner = cli.create_runner(cmd)?;
runner.async_run(|mut config| { runner.async_run(|mut config| {
let (client, _, _, task_manager) = service::new_chain_ops(&mut config)?; let (client, _, _, task_manager) =
service::new_chain_ops(&mut config, cli.sealing.is_manual_consensus())?;
Ok((cmd.run(client, config.chain_spec), task_manager)) Ok((cmd.run(client, config.chain_spec), task_manager))
}) })
} }
Some(Subcommand::ImportBlocks(cmd)) => { Some(Subcommand::ImportBlocks(cmd)) => {
let runner = cli.create_runner(cmd)?; let runner = cli.create_runner(cmd)?;
runner.async_run(|mut config| { runner.async_run(|mut config| {
let (client, _, import_queue, task_manager) = service::new_chain_ops(&mut config)?; let (client, _, import_queue, task_manager) =
service::new_chain_ops(&mut config, cli.sealing.is_manual_consensus())?;
Ok((cmd.run(client, import_queue), task_manager)) Ok((cmd.run(client, import_queue), task_manager))
}) })
} }
...@@ -184,7 +188,8 @@ pub fn run() -> sc_cli::Result<()> { ...@@ -184,7 +188,8 @@ pub fn run() -> sc_cli::Result<()> {
Some(Subcommand::Revert(cmd)) => { Some(Subcommand::Revert(cmd)) => {
let runner = cli.create_runner(cmd)?; let runner = cli.create_runner(cmd)?;
runner.async_run(|mut config| { runner.async_run(|mut config| {
let (client, backend, _, task_manager) = service::new_chain_ops(&mut config)?; let (client, backend, _, task_manager) =
service::new_chain_ops(&mut config, cli.sealing.is_manual_consensus())?;
Ok((cmd.run(client, backend), task_manager)) Ok((cmd.run(client, backend), task_manager))
}) })
} }
...@@ -215,29 +220,23 @@ pub fn run() -> sc_cli::Result<()> { ...@@ -215,29 +220,23 @@ pub fn run() -> sc_cli::Result<()> {
None => { None => {
let runner = cli.create_runner(&cli.run)?; let runner = cli.create_runner(&cli.run)?;
runner.run_node_until_exit(|config| async move { runner.run_node_until_exit(|config| async move {
let chain_spec_id = config.chain_spec.id();
let sealing_opt = if chain_spec_id.ends_with("dev") && chain_spec_id != "gdev" {
Some(cli.sealing)
} else {
None
};
match config.chain_spec.runtime_type() { match config.chain_spec.runtime_type() {
#[cfg(feature = "g1")] #[cfg(feature = "g1")]
RuntimeType::G1 => { RuntimeType::G1 => {
service::new_full::<g1_runtime::RuntimeApi, G1Executor>(config, sealing_opt) service::new_full::<g1_runtime::RuntimeApi, G1Executor>(config, cli.sealing)
.map_err(sc_cli::Error::Service) .map_err(sc_cli::Error::Service)
} }
#[cfg(feature = "gtest")] #[cfg(feature = "gtest")]
RuntimeType::GTest => service::new_full::< RuntimeType::GTest => service::new_full::<
gtest_runtime::RuntimeApi, gtest_runtime::RuntimeApi,
GTestExecutor, GTestExecutor,
>(config, sealing_opt) >(config, cli.sealing)
.map_err(sc_cli::Error::Service), .map_err(sc_cli::Error::Service),
#[cfg(feature = "gdev")] #[cfg(feature = "gdev")]
RuntimeType::GDev => { RuntimeType::GDev => {
service::new_full::<gdev_runtime::RuntimeApi, GDevExecutor>( service::new_full::<gdev_runtime::RuntimeApi, GDevExecutor>(
config, config,
sealing_opt, cli.sealing,
) )
.map_err(sc_cli::Error::Service) .map_err(sc_cli::Error::Service)
} }
......
...@@ -131,6 +131,7 @@ impl IdentifyRuntimeType for Box<dyn sc_chain_spec::ChainSpec> { ...@@ -131,6 +131,7 @@ impl IdentifyRuntimeType for Box<dyn sc_chain_spec::ChainSpec> {
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
pub fn new_chain_ops( pub fn new_chain_ops(
config: &mut Configuration, config: &mut Configuration,
manual_consensus: bool,
) -> Result< ) -> Result<
( (
Arc<Client>, Arc<Client>,
...@@ -149,7 +150,7 @@ pub fn new_chain_ops( ...@@ -149,7 +150,7 @@ pub fn new_chain_ops(
import_queue, import_queue,
task_manager, task_manager,
.. ..
} = new_partial::<g1_runtime::RuntimeApi, G1Executor>(config, false)?; } = new_partial::<g1_runtime::RuntimeApi, G1Executor>(config, manual_consensus)?;
Ok(( Ok((
Arc::new(Client::G1(client)), Arc::new(Client::G1(client)),
backend, backend,
...@@ -165,7 +166,7 @@ pub fn new_chain_ops( ...@@ -165,7 +166,7 @@ pub fn new_chain_ops(
import_queue, import_queue,
task_manager, task_manager,
.. ..
} = new_partial::<gtest_runtime::RuntimeApi, GTestExecutor>(config, false)?; } = new_partial::<gtest_runtime::RuntimeApi, GTestExecutor>(config, manual_consensus)?;
Ok(( Ok((
Arc::new(Client::GTest(client)), Arc::new(Client::GTest(client)),
backend, backend,
...@@ -181,7 +182,7 @@ pub fn new_chain_ops( ...@@ -181,7 +182,7 @@ pub fn new_chain_ops(
import_queue, import_queue,
task_manager, task_manager,
.. ..
} = new_partial::<gdev_runtime::RuntimeApi, GDevExecutor>(config, true)?; } = new_partial::<gdev_runtime::RuntimeApi, GDevExecutor>(config, manual_consensus)?;
Ok(( Ok((
Arc::new(Client::GDev(client)), Arc::new(Client::GDev(client)),
backend, backend,
...@@ -293,7 +294,7 @@ where ...@@ -293,7 +294,7 @@ where
let babe_config = babe::Config::get(&*client)?; let babe_config = babe::Config::get(&*client)?;
let (babe_block_import, babe_link) = let (babe_block_import, babe_link) =
babe::block_import(babe_config, grandpa_block_import.clone(), client.clone())?; babe::block_import(babe_config, grandpa_block_import, client.clone())?;
let import_queue = if consensus_manual { let import_queue = if consensus_manual {
manual_seal::import_queue( manual_seal::import_queue(
...@@ -349,7 +350,7 @@ fn remote_keystore(_url: &str) -> Result<Arc<LocalKeystore>, &'static str> { ...@@ -349,7 +350,7 @@ fn remote_keystore(_url: &str) -> Result<Arc<LocalKeystore>, &'static str> {
/// Builds a new service for a full client. /// Builds a new service for a full client.
pub fn new_full<RuntimeApi, Executor>( pub fn new_full<RuntimeApi, Executor>(
mut config: Configuration, mut config: Configuration,
sealing_opt: Option<crate::cli::Sealing>, sealing: crate::cli::Sealing,
) -> Result<TaskManager, ServiceError> ) -> Result<TaskManager, ServiceError>
where where
RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, Executor>> RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, Executor>>
...@@ -369,7 +370,7 @@ where ...@@ -369,7 +370,7 @@ where
select_chain, select_chain,
transaction_pool, transaction_pool,
other: (block_import, babe_link, grandpa_link, mut telemetry), other: (block_import, babe_link, grandpa_link, mut telemetry),
} = new_partial::<RuntimeApi, Executor>(&config, sealing_opt.is_some())?; } = new_partial::<RuntimeApi, Executor>(&config, sealing.is_manual_consensus())?;
if let Some(url) = &config.keystore_remote { if let Some(url) = &config.keystore_remote {
match remote_keystore(url) { match remote_keystore(url) {
...@@ -430,7 +431,7 @@ where ...@@ -430,7 +431,7 @@ where
telemetry.as_ref().map(|x| x.handle()), telemetry.as_ref().map(|x| x.handle()),
); );
if let Some(sealing) = sealing_opt { if sealing.is_manual_consensus() {
let commands_stream: Box<dyn Stream<Item = EngineCommand<H256>> + Send + Sync + Unpin> = let commands_stream: Box<dyn Stream<Item = EngineCommand<H256>> + Send + Sync + Unpin> =
match sealing { match sealing {
crate::cli::Sealing::Instant => { crate::cli::Sealing::Instant => {
...@@ -463,6 +464,7 @@ where ...@@ -463,6 +464,7 @@ where
sender: None, sender: None,
}, },
)), )),
crate::cli::Sealing::Production => unreachable!(),
}; };
let babe_consensus_data_provider = let babe_consensus_data_provider =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment