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
before · node/cli/src/cli.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use crate::chain_spec;18use std::path::PathBuf;19use clap::Parser;2021/// Sub-commands supported by the collator.22#[derive(Debug, Parser)]23pub enum Subcommand {24	/// Export the genesis state of the parachain.25	ExportGenesisState(cumulus_client_cli::ExportGenesisStateCommand),2627	/// Export the genesis wasm of the parachain.28	ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand),2930	/// Keys manipulation subcommand31	#[clap(subcommand)]32	Key(sc_cli::KeySubcommand),3334	/// Build a chain specification.35	BuildSpec(sc_cli::BuildSpecCmd),3637	/// Validate blocks.38	CheckBlock(sc_cli::CheckBlockCmd),3940	/// Export blocks.41	ExportBlocks(sc_cli::ExportBlocksCmd),4243	/// Export the state of a given block into a chain spec.44	ExportState(sc_cli::ExportStateCmd),4546	/// Import blocks.47	ImportBlocks(sc_cli::ImportBlocksCmd),4849	/// Remove the whole chain.50	PurgeChain(cumulus_client_cli::PurgeChainCmd),5152	/// Revert the chain to a previous state.53	Revert(sc_cli::RevertCmd),5455	/// The custom benchmark subcommmand benchmarking runtime pallets.56	#[clap(subcommand)]57	#[cfg(feature = "runtime-benchmarks")]58	Benchmark(frame_benchmarking_cli::BenchmarkCmd),5960	/// Try runtime61	#[cfg(feature = "try-runtime")]62	TryRuntime(try_runtime_cli::TryRuntimeCmd),6364	/// Try runtime. Note: `try-runtime` feature must be enabled.65	#[cfg(not(feature = "try-runtime"))]66	TryRuntime,67}6869#[derive(Debug, Parser)]70#[clap(args_conflicts_with_subcommands = true, subcommand_negates_reqs = true)]71pub struct Cli {72	#[structopt(subcommand)]73	pub subcommand: Option<Subcommand>,7475	#[structopt(flatten)]76	pub run: cumulus_client_cli::RunCmd,7778	/// When running the node in the `--dev` mode and79	/// there is no transaction in the transaction pool,80	/// an empty block will be sealed automatically81	/// after the `--idle-autoseal-interval` milliseconds.82	///83	/// The default interval is 500 milliseconds84	#[structopt(default_value = "500", long)]85	pub idle_autoseal_interval: u64,8687	/// Disable auto-sealing blocks on new transactions in the `--dev` mode.88	#[structopt(long)]89	pub disable_autoseal_on_tx: bool,9091	/// Disable automatic hardware benchmarks.92	///93	/// By default these benchmarks are automatically ran at startup and measure94	/// the CPU speed, the memory bandwidth and the disk speed.95	///96	/// The results are then printed out in the logs, and also sent as part of97	/// telemetry, if telemetry is enabled.98	#[clap(long)]99	pub no_hardware_benchmarks: bool,100101	/// Relaychain arguments102	#[structopt(raw = true)]103	pub relaychain_args: Vec<String>,104}105106impl Cli {107	pub fn node_name() -> String {108		"Unique".into()109	}110}111112#[derive(Debug)]113pub struct RelayChainCli {114	/// The actual relay chain cli object.115	pub base: polkadot_cli::RunCmd,116117	/// Optional chain id that should be passed to the relay chain.118	pub chain_id: Option<String>,119120	/// The base path that should be used by the relay chain.121	pub base_path: PathBuf,122}123124impl RelayChainCli {125	/// Parse the relay chain CLI parameters using the para chain `Configuration`.126	pub fn new<'a>(127		para_config: &sc_service::Configuration,128		relay_chain_args: impl Iterator<Item = &'a String>,129	) -> Self {130		let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);131		let chain_id = extension.map(|e| e.relay_chain.clone());132		let base_path = para_config.base_path.path().join("polkadot");133		Self {134			base_path,135			chain_id,136			base: polkadot_cli::RunCmd::parse_from(relay_chain_args),137		}138	}139}
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
--- a/node/cli/src/service.rs
+++ b/node/cli/src/service.rs
@@ -169,9 +169,9 @@
 }
 
 impl AutosealInterval {
-	pub fn new(config: &Configuration, interval: Duration) -> Self {
+	pub fn new(config: &Configuration, interval: u64) -> Self {
 		let _tokio_runtime = config.tokio_handle.enter();
-		let interval = tokio::time::interval(interval);
+		let interval = tokio::time::interval(Duration::from_millis(interval));
 
 		Self { interval }
 	}
@@ -885,7 +885,8 @@
 /// the parachain inherent
 pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(
 	config: Configuration,
-	autoseal_interval: Duration,
+	autoseal_interval: u64,
+	autoseal_finalize_delay: Option<u64>,
 	disable_autoseal_on_tx: bool,
 ) -> sc_service::error::Result<TaskManager>
 where
@@ -913,7 +914,10 @@
 		+ sp_consensus_aura::AuraApi<Block, AuraId>,
 	ExecutorDispatch: NativeExecutionDispatch + 'static,
 {
-	use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};
+	use sc_consensus_manual_seal::{
+		run_manual_seal, run_delayed_finalize, EngineCommand, ManualSealParams,
+		DelayedFinalizeParams,
+	};
 	use fc_consensus::FrontierBlockImport;
 
 	let sc_service::PartialComponents {
@@ -984,18 +988,19 @@
 				.filter(move |_| futures::future::ready(!disable_autoseal_on_tx))
 				.map(|_| EngineCommand::SealNewBlock {
 					create_empty: true,
-					finalize: false, // todo:collator finalize true
+					finalize: false,
 					parent_hash: None,
 					sender: None,
 				}),
 		);
 
 		let autoseal_interval = Box::pin(AutosealInterval::new(&config, autoseal_interval));
+
 		let idle_commands_stream: Box<
 			dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,
 		> = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {
 			create_empty: true,
-			finalize: false, // todo:collator finalize true
+			finalize: false,
 			parent_hash: None,
 			sender: None,
 		}));
@@ -1005,6 +1010,20 @@
 		let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
 		let client_set_aside_for_cidp = client.clone();
 
+		if let Some(delay_sec) = autoseal_finalize_delay {
+			let spawn_handle = task_manager.spawn_handle();
+
+			task_manager.spawn_essential_handle().spawn_blocking(
+				"finalization_task",
+				Some("block-authoring"),
+				run_delayed_finalize(DelayedFinalizeParams {
+					client: client.clone(),
+					delay_sec,
+					spawn_handle,
+				}),
+			);
+		}
+
 		task_manager.spawn_essential_handle().spawn_blocking(
 			"authorship_task",
 			Some("block-authoring"),