Skip to content

Commit

Permalink
feat: finalization can be enabled in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mrshiposha committed Oct 2, 2023
1 parent b6b1e0f commit 184b30a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
8 changes: 7 additions & 1 deletion node/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,20 @@ pub struct Cli {
/// 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,

/// Disable auto-sealing blocks on new transactions in the `--dev` mode.
#[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
Expand Down
5 changes: 1 addition & 4 deletions node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ use sc_cli::{
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};

Expand Down Expand Up @@ -481,14 +480,12 @@ pub fn run() -> Result<()> {
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)
};
};

Expand Down
31 changes: 25 additions & 6 deletions node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ pub struct AutosealInterval {
}

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 }
}
Expand Down Expand Up @@ -885,7 +885,8 @@ pub struct OtherPartial {
/// 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
Expand Down Expand Up @@ -913,7 +914,10 @@ where
+ 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 {
Expand Down Expand Up @@ -984,18 +988,19 @@ where
.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,
}));
Expand All @@ -1005,6 +1010,20 @@ where
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"),
Expand Down

0 comments on commit 184b30a

Please sign in to comment.