Skip to content

Commit

Permalink
add cli option --block-authoring-duration (#2726)
Browse files Browse the repository at this point in the history
  • Loading branch information
librelois authored Mar 28, 2024
1 parent 5b834ca commit 2187a05
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ assert_cmd = "2.0.10"
async-io = "1.3"
bip32 = { version = "0.5.1", default-features = false, features = ["bip39"] }
clap = { version = "4.0.9", features = ["derive"] }
clap-num = "=1.1.1"
exit-future = "0.2"
flume = "0.10.9"
futures = { version = "0.3.21" }
Expand Down
1 change: 1 addition & 0 deletions node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.37.0"

[dependencies]
clap = { workspace = true, features = ["derive"] }
clap-num = { workspace = true }
log = { workspace = true }
parity-scale-codec = { workspace = true }

Expand Down
11 changes: 11 additions & 0 deletions node/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use moonbeam_cli_opt::{account_key::GenerateAccountKey, EthApi, FrontierBackendT
use moonbeam_service::chain_spec;
use sc_cli::{Error as CliError, SubstrateCli};
use std::path::PathBuf;
use std::time::Duration;

/// Sub-commands supported by the collator.
#[derive(Debug, clap::Subcommand)]
Expand Down Expand Up @@ -232,6 +233,16 @@ pub struct RunCmd {
/// Removes moonbeam prefix from Prometheus metrics
#[clap(long)]
pub no_prometheus_prefix: bool,

/// Maximum duration in milliseconds to produce a block
#[clap(long, default_value = "1500", value_parser=block_authoring_duration_parser)]
pub block_authoring_duration: Duration,
}

fn block_authoring_duration_parser(s: &str) -> Result<Duration, String> {
Ok(Duration::from_millis(clap_num::number_range(
s, 250, 2_000,
)?))
}

impl RunCmd {
Expand Down
3 changes: 3 additions & 0 deletions node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ pub fn run() -> Result<()> {
id,
rpc_config,
false,
cli.run.block_authoring_duration,
hwbench,
)
.await
Expand All @@ -811,6 +812,7 @@ pub fn run() -> Result<()> {
id,
rpc_config,
false,
cli.run.block_authoring_duration,
hwbench,
)
.await
Expand All @@ -827,6 +829,7 @@ pub fn run() -> Result<()> {
id,
rpc_config,
true,
cli.run.block_authoring_duration,
hwbench,
)
.await
Expand Down
7 changes: 6 additions & 1 deletion node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ async fn start_node_impl<RuntimeApi, Customizations>(
para_id: ParaId,
rpc_config: RpcConfig,
async_backing: bool,
block_authoring_duration: Duration,
hwbench: Option<sc_sysinfo::HwBench>,
) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi>>)>
where
Expand Down Expand Up @@ -884,6 +885,7 @@ where
announce_block,
force_authoring,
relay_chain_slot_duration,
block_authoring_duration,
sync_service.clone(),
)?;
/*let parachain_consensus = build_consensus(
Expand Down Expand Up @@ -946,6 +948,7 @@ fn start_consensus<RuntimeApi, SO>(
announce_block: Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,
force_authoring: bool,
relay_chain_slot_duration: Duration,
block_authoring_duration: Duration,
sync_oracle: SO,
) -> Result<(), sc_service::Error>
where
Expand Down Expand Up @@ -1024,7 +1027,7 @@ where
additional_relay_keys: vec![
moonbeam_core_primitives::well_known_relay_keys::TIMESTAMP_NOW.to_vec(),
],
authoring_duration: Duration::from_millis(1500),
authoring_duration: block_authoring_duration,
block_import,
code_hash_provider,
collator_key,
Expand Down Expand Up @@ -1085,6 +1088,7 @@ pub async fn start_node<RuntimeApi, Customizations>(
para_id: ParaId,
rpc_config: RpcConfig,
async_backing: bool,
block_authoring_duration: Duration,
hwbench: Option<sc_sysinfo::HwBench>,
) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi>>)>
where
Expand All @@ -1101,6 +1105,7 @@ where
para_id,
rpc_config,
async_backing,
block_authoring_duration,
hwbench,
)
.await
Expand Down

0 comments on commit 2187a05

Please sign in to comment.