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
80 /// an empty block will be sealed automatically80 /// an empty block will be sealed automatically
81 /// after the `--idle-autoseal-interval` milliseconds.81 /// after the `--idle-autoseal-interval` milliseconds.
82 ///82 ///
83 /// The default interval is 500 milliseconds83 /// The default interval is 500 milliseconds.
84 #[structopt(default_value = "500", long)]84 #[structopt(default_value = "500", long)]
85 pub idle_autoseal_interval: u64,85 pub idle_autoseal_interval: u64,
8686
87 /// Disable auto-sealing blocks on new transactions in the `--dev` mode.87 /// Disable auto-sealing blocks on new transactions in the `--dev` mode.
88 #[structopt(long)]88 #[structopt(long)]
89 pub disable_autoseal_on_tx: bool,89 pub disable_autoseal_on_tx: bool,
90
91 /// Finalization delay (in seconds) of auto-sealed blocks in the `--dev` mode.
92 ///
93 /// Disabled by default.
94 #[structopt(long)]
95 pub autoseal_finalization_delay: Option<u64>,
9096
91 /// Disable automatic hardware benchmarks.97 /// Disable automatic hardware benchmarks.
92 ///98 ///
modifiednode/cli/src/command.rsdiffbeforeafterboth
62use sc_service::config::{BasePath, PrometheusConfig};62use sc_service::config::{BasePath, PrometheusConfig};
63use sp_core::hexdisplay::HexDisplay;63use sp_core::hexdisplay::HexDisplay;
64use sp_runtime::traits::{AccountIdConversion, Block as BlockT};64use sp_runtime::traits::{AccountIdConversion, Block as BlockT};
65use std::{time::Duration};
6665
67use up_common::types::opaque::{Block, RuntimeId};66use up_common::types::opaque::{Block, RuntimeId};
6867
481 if is_dev_service {480 if is_dev_service {
482 info!("Running Dev service");481 info!("Running Dev service");
483
484 let autoseal_interval = Duration::from_millis(cli.idle_autoseal_interval);
485482
486 let mut config = config;483 let mut config = config;
487484
488 config.state_pruning = Some(sc_service::PruningMode::ArchiveAll);485 config.state_pruning = Some(sc_service::PruningMode::ArchiveAll);
489486
490 return start_node_using_chain_runtime! {487 return start_node_using_chain_runtime! {
491 start_dev_node(config, autoseal_interval, cli.disable_autoseal_on_tx).map_err(Into::into)488 start_dev_node(config, cli.idle_autoseal_interval, cli.autoseal_finalization_delay, cli.disable_autoseal_on_tx).map_err(Into::into)
492 };489 };
493 };490 };
494491
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",