From cee9b17ef63d9dcd0a3eb90596a0ad5d53206a37 Mon Sep 17 00:00:00 2001 From: trantorian <114066155+Trantorian1@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:41:50 +0100 Subject: [PATCH] fix(block_time): block time can no longer be less than pending block update time --- CHANGELOG.md | 1 + crates/node/src/cli/chain_config_overrides.rs | 4 ++++ crates/node/src/cli/mod.rs | 2 +- crates/node/src/main.rs | 23 ++++++++++++++++--- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 441d5658e..ddca89a9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Next release +- fix(block_time): block time can no longer be less than pending block update time - fix: Gateway path fix - fix: instrumentation code - feat: block resource cap removed from the pending tick diff --git a/crates/node/src/cli/chain_config_overrides.rs b/crates/node/src/cli/chain_config_overrides.rs index 7d86413db..f571ba4cd 100644 --- a/crates/node/src/cli/chain_config_overrides.rs +++ b/crates/node/src/cli/chain_config_overrides.rs @@ -24,6 +24,10 @@ use url::Url; /// Format: "--chain-config-override chain_id=SN_MADARA,chain_name=MADARA,block_time=1500ms,bouncer_config.block_max_capacity.n_steps=100000000" #[derive(Parser, Clone, Debug)] pub struct ChainConfigOverrideParams { + /// Overrides parameters from the chain config. + /// + /// Use the following syntax: + /// --chain-config-override=block_time=30s,pending_block_update_time=2s... #[clap(env = "MADARA_CHAIN_CONFIG_OVERRIDE", long = "chain-config-override", value_parser = parse_key_value_yaml, use_value_delimiter = true, value_delimiter = ',')] pub overrides: Vec<(String, Value)>, } diff --git a/crates/node/src/cli/mod.rs b/crates/node/src/cli/mod.rs index 557f6d8de..3d704d0cc 100644 --- a/crates/node/src/cli/mod.rs +++ b/crates/node/src/cli/mod.rs @@ -200,7 +200,7 @@ pub struct RunCmd { #[clap(env = "MADARA_PRESET", long, value_name = "PRESET NAME", group = "chain_config")] pub preset: Option, - /// Overrides parameters from the Chain Config. + #[allow(missing_docs)] #[clap(flatten)] pub chain_config_override: ChainConfigOverrideParams, } diff --git a/crates/node/src/main.rs b/crates/node/src/main.rs index b0958cc46..7267f2cb1 100644 --- a/crates/node/src/main.rs +++ b/crates/node/src/main.rs @@ -50,15 +50,32 @@ async fn main() -> anyhow::Result<()> { run_cmd.chain_config()? }; + // If block time is inferior to the tick time, then only empty blocks will + // be produced as we will never update the pending block before storing it. + if run_cmd.is_sequencer() && chain_config.block_time < chain_config.pending_block_update_time { + tracing::error!( + "Block time ({}s) cannot be less than the pending block update time ({}s), as this will yield only empty blocks", + chain_config.block_time.as_secs(), + chain_config.pending_block_update_time.as_secs() + ); + anyhow::bail!("Block time"); + } + // Check if the devnet is running with the correct chain id. if run_cmd.devnet && chain_config.chain_id != NetworkType::Devnet.chain_id() { if !run_cmd.block_production_params.override_devnet_chain_id { - tracing::error!("You're running a devnet with the network config of {:?}. This means that devnet transactions can be replayed on the actual network. Use `--network=devnet` instead. Or if this is the expected behavior please pass `--override-devnet-chain-id`", chain_config.chain_name); - panic!(); + tracing::error!( + "You're running a devnet with the network config of {:?}. This means that devnet transactions can be replayed on the actual network. Use `--network=devnet` instead. Or if this is the expected behavior please pass `--override-devnet-chain-id`", + chain_config.chain_name + ); + anyhow::bail!("devnet"); } else { // This log is immediately flooded with devnet accounts and so this can be missed. // Should we add a delay here to make this clearly visisble? - tracing::warn!("You're running a devnet with the network config of {:?}. This means that devnet transactions can be replayed on the actual network.", run_cmd.network); + tracing::warn!( + "You're running a devnet with the network config of {:?}. This means that devnet transactions can be replayed on the actual network.", + run_cmd.network + ); } }