diff --git a/Cargo.lock b/Cargo.lock index ea0e1735a5..cbab3be7a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -335,7 +335,7 @@ dependencies = [ [[package]] name = "astar-collator" -version = "5.1.0" +version = "5.2.0" dependencies = [ "astar-runtime", "async-trait", diff --git a/bin/collator/Cargo.toml b/bin/collator/Cargo.toml index 22e58d1e25..921ac49697 100644 --- a/bin/collator/Cargo.toml +++ b/bin/collator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "astar-collator" -version = "5.1.0" +version = "5.2.0" description = "Astar collator implementation in Rust." build = "build.rs" default-run = "astar-collator" diff --git a/bin/collator/src/cli.rs b/bin/collator/src/cli.rs index b685ecedfe..c0eba4ca0d 100644 --- a/bin/collator/src/cli.rs +++ b/bin/collator/src/cli.rs @@ -86,6 +86,14 @@ pub struct Cli { /// Relaychain arguments #[clap(raw = true)] pub relaychain_args: Vec, + + /// Proposer's maximum block size limit in bytes + #[clap(long, default_value = sc_basic_authorship::DEFAULT_BLOCK_SIZE_LIMIT.to_string())] + pub proposer_block_size_limit: usize, + + /// Proposer's soft deadline in percents of block size + #[clap(long, default_value = "50")] + pub proposer_soft_deadline_percent: u8, } /// Possible subcommands of the main binary. diff --git a/bin/collator/src/command.rs b/bin/collator/src/command.rs index bae24f26e4..17f0298af8 100644 --- a/bin/collator/src/command.rs +++ b/bin/collator/src/command.rs @@ -21,8 +21,8 @@ use crate::{ cli::{Cli, RelayChainCli, Subcommand}, local::{self, development_config}, parachain::{ - self, astar, chain_spec, shibuya, shiden, start_astar_node, start_shibuya_node, - start_shiden_node, + self, astar, chain_spec, service::StartupConfiguration, shibuya, shiden, start_astar_node, + start_shibuya_node, start_shiden_node, }, primitives::Block, }; @@ -884,17 +884,44 @@ pub fn run() -> Result<()> { #[cfg(feature = "evm-tracing")] if config.chain_spec.is_astar() { - start_astar_node(config, polkadot_config, evm_tracing_config, collator_options, para_id, cli.enable_evm_rpc) + start_astar_node(StartupConfiguration { + parachain_config: config, + polkadot_config, + evm_tracing_config, + collator_options, + id: para_id, + enable_evm_rpc: cli.enable_evm_rpc, + proposer_block_size_limit: cli.proposer_block_size_limit, + proposer_soft_deadline_percent: cli.proposer_soft_deadline_percent, + }) .await .map(|r| r.0) .map_err(Into::into) } else if config.chain_spec.is_shiden() { - start_shiden_node(config, polkadot_config, evm_tracing_config, collator_options, para_id, cli.enable_evm_rpc) + start_shiden_node(StartupConfiguration { + parachain_config: config, + polkadot_config, + evm_tracing_config, + collator_options, + id: para_id, + enable_evm_rpc: cli.enable_evm_rpc, + proposer_block_size_limit: cli.proposer_block_size_limit, + proposer_soft_deadline_percent: cli.proposer_soft_deadline_percent, + }) .await .map(|r| r.0) .map_err(Into::into) } else if config.chain_spec.is_shibuya() { - start_shibuya_node(config, polkadot_config, evm_tracing_config, collator_options, para_id, cli.enable_evm_rpc) + start_shibuya_node(StartupConfiguration { + parachain_config: config, + polkadot_config, + evm_tracing_config, + collator_options, + id: para_id, + enable_evm_rpc: cli.enable_evm_rpc, + proposer_block_size_limit: cli.proposer_block_size_limit, + proposer_soft_deadline_percent: cli.proposer_soft_deadline_percent, + }) .await .map(|r| r.0) .map_err(Into::into) @@ -906,17 +933,41 @@ pub fn run() -> Result<()> { #[cfg(not(feature = "evm-tracing"))] if config.chain_spec.is_astar() { - start_astar_node(config, polkadot_config, collator_options, para_id, cli.enable_evm_rpc) + start_astar_node(StartupConfiguration { + parachain_config: config, + polkadot_config, + collator_options, + id: para_id, + enable_evm_rpc: cli.enable_evm_rpc, + proposer_block_size_limit: cli.proposer_block_size_limit, + proposer_soft_deadline_percent: cli.proposer_soft_deadline_percent, + }) .await .map(|r| r.0) .map_err(Into::into) } else if config.chain_spec.is_shiden() { - start_shiden_node(config, polkadot_config, collator_options, para_id, cli.enable_evm_rpc) + start_shiden_node(StartupConfiguration { + parachain_config: config, + polkadot_config, + collator_options, + id: para_id, + enable_evm_rpc: cli.enable_evm_rpc, + proposer_block_size_limit: cli.proposer_block_size_limit, + proposer_soft_deadline_percent: cli.proposer_soft_deadline_percent, + }) .await .map(|r| r.0) .map_err(Into::into) } else if config.chain_spec.is_shibuya() { - start_shibuya_node(config, polkadot_config, collator_options, para_id, cli.enable_evm_rpc) + start_shibuya_node(StartupConfiguration { + parachain_config: config, + polkadot_config, + collator_options, + id: para_id, + enable_evm_rpc: cli.enable_evm_rpc, + proposer_block_size_limit: cli.proposer_block_size_limit, + proposer_soft_deadline_percent: cli.proposer_soft_deadline_percent, + }) .await .map(|r| r.0) .map_err(Into::into) diff --git a/bin/collator/src/parachain/service.rs b/bin/collator/src/parachain/service.rs index 2e13f08e1b..6f876bb8c0 100644 --- a/bin/collator/src/parachain/service.rs +++ b/bin/collator/src/parachain/service.rs @@ -43,6 +43,7 @@ use sp_api::ConstructRuntimeApi; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_keystore::SyncCryptoStorePtr; use sp_runtime::traits::BlakeTwo256; +use sp_runtime::Percent; use std::{collections::BTreeMap, sync::Arc, time::Duration}; use substrate_prometheus_endpoint::Registry; @@ -577,6 +578,34 @@ where Ok((task_manager, client)) } +/// Configuration used to start a node +pub struct StartupConfiguration { + /// Parachain configuration + pub parachain_config: Configuration, + + /// Relay chain configuration + pub polkadot_config: Configuration, + + /// EVM tracing configuration + #[cfg(feature = "evm-tracing")] + pub evm_tracing_config: EvmTracingConfig, + + /// Options specific to collators + pub collator_options: CollatorOptions, + + /// Parachain ID to collate + pub id: ParaId, + + /// Whether EVM RPC be enabled + pub enable_evm_rpc: bool, + + /// Maxium allowed block size limit to propose + pub proposer_block_size_limit: usize, + + /// Soft deadline limit used by `Proposer` + pub proposer_soft_deadline_percent: u8, +} + /// Start a node with the given parachain `Configuration` and relay chain `Configuration`. /// /// This is the actual implementation that is abstract over the executor and the runtime api. @@ -979,23 +1008,18 @@ where /// Start a parachain node for Astar. #[cfg(feature = "evm-tracing")] pub async fn start_astar_node( - parachain_config: Configuration, - polkadot_config: Configuration, - evm_tracing_config: EvmTracingConfig, - collator_options: CollatorOptions, - id: ParaId, - enable_evm_rpc: bool, + configuration: StartupConfiguration, ) -> sc_service::error::Result<( TaskManager, Arc>>, )> { start_node_impl::( - parachain_config, - polkadot_config, - evm_tracing_config, - collator_options, - id, - enable_evm_rpc, + configuration.parachain_config, + configuration.polkadot_config, + configuration.evm_tracing_config, + configuration.collator_options, + configuration.id, + configuration.enable_evm_rpc, |client, block_import, config, @@ -1045,7 +1069,7 @@ pub async fn start_astar_node( let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client).unwrap(); - let proposer_factory = + let mut proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( spawn_handle, client.clone(), @@ -1054,6 +1078,9 @@ pub async fn start_astar_node( telemetry.clone(), ); + proposer_factory.set_default_block_size_limit(configuration.proposer_block_size_limit); + proposer_factory.set_soft_deadline(Percent::from_percent(configuration.proposer_soft_deadline_percent)); + let relay_chain_for_aura = relay_chain_interface.clone(); Ok(AuraConsensus::build::< @@ -1075,7 +1102,7 @@ pub async fn start_astar_node( relay_parent, &relay_chain_for_aura, &validation_data, - id, + configuration.id, ).await; let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); let slot = @@ -1112,21 +1139,17 @@ pub async fn start_astar_node( /// Start a parachain node for Astar. #[cfg(not(feature = "evm-tracing"))] pub async fn start_astar_node( - parachain_config: Configuration, - polkadot_config: Configuration, - collator_options: CollatorOptions, - id: ParaId, - enable_evm_rpc: bool, + configuration: StartupConfiguration, ) -> sc_service::error::Result<( TaskManager, Arc>>, )> { start_node_impl::( - parachain_config, - polkadot_config, - collator_options, - id, - enable_evm_rpc, + configuration.parachain_config, + configuration.polkadot_config, + configuration.collator_options, + configuration.id, + configuration.enable_evm_rpc, |client, block_import, config, @@ -1176,7 +1199,7 @@ pub async fn start_astar_node( let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client).unwrap(); - let proposer_factory = + let mut proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( spawn_handle, client.clone(), @@ -1185,6 +1208,9 @@ pub async fn start_astar_node( telemetry.clone(), ); + proposer_factory.set_default_block_size_limit(configuration.proposer_block_size_limit); + proposer_factory.set_soft_deadline(Percent::from_percent(configuration.proposer_soft_deadline_percent)); + let relay_chain_for_aura = relay_chain_interface.clone(); Ok(AuraConsensus::build::< @@ -1206,7 +1232,7 @@ pub async fn start_astar_node( relay_parent, &relay_chain_for_aura, &validation_data, - id, + configuration.id, ).await; let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); let slot = @@ -1243,23 +1269,18 @@ pub async fn start_astar_node( /// Start a parachain node for Shiden. #[cfg(feature = "evm-tracing")] pub async fn start_shiden_node( - parachain_config: Configuration, - polkadot_config: Configuration, - evm_tracing_config: EvmTracingConfig, - collator_options: CollatorOptions, - id: ParaId, - enable_evm_rpc: bool, + configuration: StartupConfiguration, ) -> sc_service::error::Result<( TaskManager, Arc>>, )> { start_node_impl::( - parachain_config, - polkadot_config, - evm_tracing_config, - collator_options, - id, - enable_evm_rpc, + configuration.parachain_config, + configuration.polkadot_config, + configuration.evm_tracing_config, + configuration.collator_options, + configuration.id, + configuration.enable_evm_rpc, build_import_queue, |client, block_import, @@ -1286,7 +1307,7 @@ pub async fn start_shiden_node( let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client2).unwrap(); - let proposer_factory = + let mut proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( spawn_handle, client2.clone(), @@ -1295,6 +1316,9 @@ pub async fn start_shiden_node( telemetry2.clone(), ); + proposer_factory.set_default_block_size_limit(configuration.proposer_block_size_limit); + proposer_factory.set_soft_deadline(Percent::from_percent(configuration.proposer_soft_deadline_percent)); + AuraConsensus::build::< sp_consensus_aura::sr25519::AuthorityPair, _, @@ -1314,7 +1338,7 @@ pub async fn start_shiden_node( relay_parent, &relay_chain_for_aura, &validation_data, - id, + configuration.id, ).await; let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); @@ -1350,7 +1374,7 @@ pub async fn start_shiden_node( }), )); - let proposer_factory = + let mut proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( task_manager.spawn_handle(), client.clone(), @@ -1359,10 +1383,13 @@ pub async fn start_shiden_node( telemetry.clone(), ); + proposer_factory.set_default_block_size_limit(configuration.proposer_block_size_limit); + proposer_factory.set_soft_deadline(Percent::from_percent(configuration.proposer_soft_deadline_percent)); + let relay_chain_consensus = cumulus_client_consensus_relay_chain::build_relay_chain_consensus( cumulus_client_consensus_relay_chain::BuildRelayChainConsensusParams { - para_id: id, + para_id: configuration.id, proposer_factory, block_import: block_import, //client.clone(), relay_chain_interface: relay_chain_interface.clone(), @@ -1375,7 +1402,7 @@ pub async fn start_shiden_node( relay_parent, &relay_chain_for_aura, &validation_data, - id, + configuration.id, ).await; let parachain_inherent = parachain_inherent.ok_or_else(|| { @@ -1402,21 +1429,17 @@ pub async fn start_shiden_node( /// Start a parachain node for Shiden. #[cfg(not(feature = "evm-tracing"))] pub async fn start_shiden_node( - parachain_config: Configuration, - polkadot_config: Configuration, - collator_options: CollatorOptions, - id: ParaId, - enable_evm_rpc: bool, + configuration: StartupConfiguration, ) -> sc_service::error::Result<( TaskManager, Arc>>, )> { start_node_impl::( - parachain_config, - polkadot_config, - collator_options, - id, - enable_evm_rpc, + configuration.parachain_config, + configuration.polkadot_config, + configuration.collator_options, + configuration.id, + configuration.enable_evm_rpc, build_import_queue, |client, block_import, @@ -1443,7 +1466,7 @@ pub async fn start_shiden_node( let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client2).unwrap(); - let proposer_factory = + let mut proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( spawn_handle, client2.clone(), @@ -1452,6 +1475,9 @@ pub async fn start_shiden_node( telemetry2.clone(), ); + proposer_factory.set_default_block_size_limit(configuration.proposer_block_size_limit); + proposer_factory.set_soft_deadline(Percent::from_percent(configuration.proposer_soft_deadline_percent)); + AuraConsensus::build::< sp_consensus_aura::sr25519::AuthorityPair, _, @@ -1471,7 +1497,7 @@ pub async fn start_shiden_node( relay_parent, &relay_chain_for_aura, &validation_data, - id, + configuration.id, ).await; let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); @@ -1507,7 +1533,7 @@ pub async fn start_shiden_node( }), )); - let proposer_factory = + let mut proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( task_manager.spawn_handle(), client.clone(), @@ -1516,10 +1542,13 @@ pub async fn start_shiden_node( telemetry.clone(), ); + proposer_factory.set_default_block_size_limit(configuration.proposer_block_size_limit); + proposer_factory.set_soft_deadline(Percent::from_percent(configuration.proposer_soft_deadline_percent)); + let relay_chain_consensus = cumulus_client_consensus_relay_chain::build_relay_chain_consensus( cumulus_client_consensus_relay_chain::BuildRelayChainConsensusParams { - para_id: id, + para_id: configuration.id, proposer_factory, block_import: block_import, //client.clone(), relay_chain_interface: relay_chain_interface.clone(), @@ -1532,7 +1561,7 @@ pub async fn start_shiden_node( relay_parent, &relay_chain_for_aura, &validation_data, - id, + configuration.id, ).await; let parachain_inherent = parachain_inherent.ok_or_else(|| { @@ -1559,23 +1588,26 @@ pub async fn start_shiden_node( /// Start a parachain node for Shibuya. #[cfg(feature = "evm-tracing")] pub async fn start_shibuya_node( - parachain_config: Configuration, - polkadot_config: Configuration, - evm_tracing_config: EvmTracingConfig, - collator_options: CollatorOptions, - id: ParaId, - enable_evm_rpc: bool, + configuration: StartupConfiguration, + // parachain_config: Configuration, + // polkadot_config: Configuration, + // evm_tracing_config: EvmTracingConfig, + // collator_options: CollatorOptions, + // id: ParaId, + // enable_evm_rpc: bool, + // proposer_block_size_limit: Option, + // proposer_soft_deadline_percent: Option, ) -> sc_service::error::Result<( TaskManager, Arc>>, )> { start_node_impl::( - parachain_config, - polkadot_config, - evm_tracing_config, - collator_options, - id, - enable_evm_rpc, + configuration.parachain_config, + configuration.polkadot_config, + configuration.evm_tracing_config, + configuration.collator_options, + configuration.id, + configuration.enable_evm_rpc, |client, block_import, config, @@ -1625,7 +1657,7 @@ pub async fn start_shibuya_node( let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client).unwrap(); - let proposer_factory = + let mut proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( spawn_handle, client.clone(), @@ -1634,6 +1666,9 @@ pub async fn start_shibuya_node( telemetry.clone(), ); + proposer_factory.set_default_block_size_limit(configuration.proposer_block_size_limit); + proposer_factory.set_soft_deadline(Percent::from_percent(configuration.proposer_soft_deadline_percent)); + Ok(AuraConsensus::build::< sp_consensus_aura::sr25519::AuthorityPair, _, @@ -1653,7 +1688,7 @@ pub async fn start_shibuya_node( relay_parent, &relay_chain_for_aura, &validation_data, - id, + configuration.id, ).await; let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); let slot = @@ -1690,21 +1725,24 @@ pub async fn start_shibuya_node( /// Start a parachain node for Shibuya. #[cfg(not(feature = "evm-tracing"))] pub async fn start_shibuya_node( - parachain_config: Configuration, - polkadot_config: Configuration, - collator_options: CollatorOptions, - id: ParaId, - enable_evm_rpc: bool, + configuration: StartupConfiguration, + // parachain_config: Configuration, + // polkadot_config: Configuration, + // collator_options: CollatorOptions, + // id: ParaId, + // enable_evm_rpc: bool, + // proposer_block_size_limit: Option, + // proposer_soft_deadline_percent: Option, ) -> sc_service::error::Result<( TaskManager, Arc>>, )> { start_node_impl::( - parachain_config, - polkadot_config, - collator_options, - id, - enable_evm_rpc, + configuration.parachain_config, + configuration.polkadot_config, + configuration.collator_options, + configuration.id, + configuration.enable_evm_rpc, |client, block_import, config, @@ -1754,7 +1792,7 @@ pub async fn start_shibuya_node( let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client).unwrap(); - let proposer_factory = + let mut proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( spawn_handle, client.clone(), @@ -1763,6 +1801,9 @@ pub async fn start_shibuya_node( telemetry.clone(), ); + proposer_factory.set_default_block_size_limit(configuration.proposer_block_size_limit); + proposer_factory.set_soft_deadline(Percent::from_percent(configuration.proposer_soft_deadline_percent)); + Ok(AuraConsensus::build::< sp_consensus_aura::sr25519::AuthorityPair, _, @@ -1782,7 +1823,7 @@ pub async fn start_shibuya_node( relay_parent, &relay_chain_for_aura, &validation_data, - id, + configuration.id, ).await; let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); let slot =