git.delta.rocks / unique-network / refs/commits / 184b30a86bc8

difftreelog

feat finalization can be enabled in dev mode

Daniel Shiposha2023-10-02parent: #b6b1e0f.patch.diff
in: master

3 files changed

modifiednode/cli/src/cli.rsdiffbeforeafterboth
--- a/node/cli/src/cli.rs
+++ b/node/cli/src/cli.rs
@@ -80,7 +80,7 @@
 	/// an empty block will be sealed automatically
 	/// after the `--idle-autoseal-interval` milliseconds.
 	///
-	/// The default interval is 500 milliseconds
+	/// The default interval is 500 milliseconds.
 	#[structopt(default_value = "500", long)]
 	pub idle_autoseal_interval: u64,
 
@@ -88,6 +88,12 @@
 	#[structopt(long)]
 	pub disable_autoseal_on_tx: bool,
 
+	/// Finalization delay (in seconds) of auto-sealed blocks in the `--dev` mode.
+	///
+	/// Disabled by default.
+	#[structopt(long)]
+	pub autoseal_finalization_delay: Option<u64>,
+
 	/// Disable automatic hardware benchmarks.
 	///
 	/// By default these benchmarks are automatically ran at startup and measure
modifiednode/cli/src/command.rsdiffbeforeafterboth
--- a/node/cli/src/command.rs
+++ b/node/cli/src/command.rs
@@ -62,7 +62,6 @@
 use sc_service::config::{BasePath, PrometheusConfig};
 use sp_core::hexdisplay::HexDisplay;
 use sp_runtime::traits::{AccountIdConversion, Block as BlockT};
-use std::{time::Duration};
 
 use up_common::types::opaque::{Block, RuntimeId};
 
@@ -480,15 +479,13 @@
 
 				if is_dev_service {
 					info!("Running Dev service");
-
-					let autoseal_interval = Duration::from_millis(cli.idle_autoseal_interval);
 
 					let mut config = config;
 
 					config.state_pruning = Some(sc_service::PruningMode::ArchiveAll);
 
 					return start_node_using_chain_runtime! {
-						start_dev_node(config, autoseal_interval, cli.disable_autoseal_on_tx).map_err(Into::into)
+						start_dev_node(config, cli.idle_autoseal_interval, cli.autoseal_finalization_delay, cli.disable_autoseal_on_tx).map_err(Into::into)
 					};
 				};
 
modifiednode/cli/src/service.rsdiffbeforeafterboth
169}169}
170170
171impl AutosealInterval {171impl AutosealInterval {
172 pub fn new(config: &Configuration, interval: Duration) -> Self {172 pub fn new(config: &Configuration, interval: u64) -> Self {
173 let _tokio_runtime = config.tokio_handle.enter();173 let _tokio_runtime = config.tokio_handle.enter();
174 let interval = tokio::time::interval(interval);174 let interval = tokio::time::interval(Duration::from_millis(interval));
175175
176 Self { interval }176 Self { interval }
177 }177 }
885/// the parachain inherent885/// the parachain inherent
886pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(886pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(
887 config: Configuration,887 config: Configuration,
888 autoseal_interval: Duration,888 autoseal_interval: u64,
889 autoseal_finalize_delay: Option<u64>,
889 disable_autoseal_on_tx: bool,890 disable_autoseal_on_tx: bool,
890) -> sc_service::error::Result<TaskManager>891) -> sc_service::error::Result<TaskManager>
891where892where
914 ExecutorDispatch: NativeExecutionDispatch + 'static,915 ExecutorDispatch: NativeExecutionDispatch + 'static,
915{916{
916 use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};917 use sc_consensus_manual_seal::{
918 run_manual_seal, run_delayed_finalize, EngineCommand, ManualSealParams,
919 DelayedFinalizeParams,
920 };
917 use fc_consensus::FrontierBlockImport;921 use fc_consensus::FrontierBlockImport;
918922
984 .filter(move |_| futures::future::ready(!disable_autoseal_on_tx))988 .filter(move |_| futures::future::ready(!disable_autoseal_on_tx))
985 .map(|_| EngineCommand::SealNewBlock {989 .map(|_| EngineCommand::SealNewBlock {
986 create_empty: true,990 create_empty: true,
987 finalize: false, // todo:collator finalize true991 finalize: false,
988 parent_hash: None,992 parent_hash: None,
989 sender: None,993 sender: None,
990 }),994 }),
995 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,1000 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,
996 > = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {1001 > = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {
997 create_empty: true,1002 create_empty: true,
998 finalize: false, // todo:collator finalize true1003 finalize: false,
999 parent_hash: None,1004 parent_hash: None,
1000 sender: None,1005 sender: None,
1001 }));1006 }));
1005 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;1010 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
1006 let client_set_aside_for_cidp = client.clone();1011 let client_set_aside_for_cidp = client.clone();
1012
1013 if let Some(delay_sec) = autoseal_finalize_delay {
1014 let spawn_handle = task_manager.spawn_handle();
1015
1016 task_manager.spawn_essential_handle().spawn_blocking(
1017 "finalization_task",
1018 Some("block-authoring"),
1019 run_delayed_finalize(DelayedFinalizeParams {
1020 client: client.clone(),
1021 delay_sec,
1022 spawn_handle,
1023 }),
1024 );
1025 }
10071026
1008 task_manager.spawn_essential_handle().spawn_blocking(1027 task_manager.spawn_essential_handle().spawn_blocking(
1009 "authorship_task",1028 "authorship_task",