diff --git a/parachain/src/chain_spec/interlay.rs b/parachain/src/chain_spec/interlay.rs index 827bf39191..f10b8cf7e4 100644 --- a/parachain/src/chain_spec/interlay.rs +++ b/parachain/src/chain_spec/interlay.rs @@ -13,8 +13,8 @@ pub type InterlayDevChainSpec = sc_service::GenericChainSpec Result<(), String> { sp_state_machine::BasicExternalities::execute_with_storage(storage, || { - interlay_runtime::EnableManualSeal::set(&self.enable_instant_seal); + interlay_runtime::EnableManualSeal::set(&self.enable_manual_seal); interlay_runtime::evm::EnableCreate::set(&self.enable_create); }); self.genesis_config.assimilate_storage(storage) @@ -51,7 +51,7 @@ fn default_pair_interlay(currency_id: CurrencyId) -> VaultCurrencyPair InterlayDevChainSpec { +pub fn interlay_dev_config(enable_manual_seal: bool) -> InterlayDevChainSpec { let id: ParaId = PARA_ID.into(); InterlayDevChainSpec::from_genesis( "Interlay", @@ -71,7 +71,7 @@ pub fn interlay_dev_config(enable_instant_seal: bool) -> InterlayDevChainSpec { 1, false, // disable difficulty check ), - enable_instant_seal, + enable_manual_seal, enable_create: true, }, Vec::new(), diff --git a/parachain/src/chain_spec/kintsugi.rs b/parachain/src/chain_spec/kintsugi.rs index a77c2ee6ab..3d570e3fdb 100644 --- a/parachain/src/chain_spec/kintsugi.rs +++ b/parachain/src/chain_spec/kintsugi.rs @@ -13,8 +13,8 @@ pub type KintsugiDevChainSpec = sc_service::GenericChainSpec Result<(), String> { sp_state_machine::BasicExternalities::execute_with_storage(storage, || { - kintsugi_runtime::EnableManualSeal::set(&self.enable_instant_seal); + kintsugi_runtime::EnableManualSeal::set(&self.enable_manual_seal); kintsugi_runtime::evm::EnableCreate::set(&self.enable_create); }); self.genesis_config.assimilate_storage(storage) @@ -51,7 +51,7 @@ fn default_pair_kintsugi(currency_id: CurrencyId) -> VaultCurrencyPair KintsugiDevChainSpec { +pub fn kintsugi_dev_config(enable_manual_seal: bool) -> KintsugiDevChainSpec { let id: ParaId = PARA_ID.into(); KintsugiDevChainSpec::from_genesis( "Kintsugi", @@ -71,7 +71,7 @@ pub fn kintsugi_dev_config(enable_instant_seal: bool) -> KintsugiDevChainSpec { 1, false, // disable difficulty check ), - enable_instant_seal, + enable_manual_seal, enable_create: true, }, Vec::new(), diff --git a/parachain/src/chain_spec/testnet_kintsugi.rs b/parachain/src/chain_spec/testnet_kintsugi.rs index 7ec7628e1a..87a6520028 100644 --- a/parachain/src/chain_spec/testnet_kintsugi.rs +++ b/parachain/src/chain_spec/testnet_kintsugi.rs @@ -61,7 +61,7 @@ pub fn local_config(id: ParaId) -> KintsugiChainSpec { ) } -pub fn development_config(id: ParaId, enable_instant_seal: bool) -> KintsugiDevChainSpec { +pub fn development_config(id: ParaId, enable_manual_seal: bool) -> KintsugiDevChainSpec { KintsugiDevChainSpec::from_genesis( "Kintsugi", "kintsugi", @@ -103,7 +103,7 @@ pub fn development_config(id: ParaId, enable_instant_seal: bool) -> KintsugiDevC DEFAULT_BITCOIN_CONFIRMATIONS, true, // disable difficulty check ), - enable_instant_seal, + enable_manual_seal, enable_create: true, }, Vec::new(), diff --git a/parachain/src/cli.rs b/parachain/src/cli.rs index f6aaad6011..e92a5b62c3 100644 --- a/parachain/src/cli.rs +++ b/parachain/src/cli.rs @@ -52,6 +52,12 @@ pub enum Subcommand { TryRuntime, } +#[derive(clap::ValueEnum, Debug, Clone)] +pub enum RuntimeName { + Interlay, + Kintsugi, +} + /// Command for exporting the metadata. #[derive(Debug, Parser)] pub struct ExportMetadataCommand { @@ -68,10 +74,14 @@ pub struct ExportMetadataCommand { pub runtime: RuntimeName, } -#[derive(clap::ValueEnum, Debug, Clone)] -pub enum RuntimeName { - Interlay, - Kintsugi, +/// Available Sealing methods. +#[derive(Copy, Clone, Debug, Default, clap::ValueEnum)] +pub enum Sealing { + /// Seal using rpc method. + #[default] + Manual, + /// Seal when transaction is executed. + Instant, } #[derive(Debug, Parser)] @@ -94,12 +104,12 @@ pub struct Cli { #[clap(raw = true)] pub relaychain_args: Vec, - /// Instant block sealing + /// Choose sealing method. /// /// This flag requires `--dev` **or** `--chain=...`, /// `--force-authoring` and `--alice` flags. - #[clap(long = "instant-seal")] - pub instant_seal: bool, + #[arg(long, value_enum, ignore_case = true)] + pub sealing: Option, } #[derive(Debug)] diff --git a/parachain/src/command.rs b/parachain/src/command.rs index e3aa51ec4e..68a0c9e926 100644 --- a/parachain/src/command.rs +++ b/parachain/src/command.rs @@ -16,7 +16,7 @@ use crate::{ chain_spec, - cli::{Cli, RelayChainCli, RuntimeName, Subcommand}, + cli::{Cli, RelayChainCli, RuntimeName, Sealing, Subcommand}, service::{new_partial, InterlayRuntimeExecutor, KintsugiRuntimeExecutor}, }; use cumulus_primitives_core::ParaId; @@ -66,19 +66,19 @@ impl IdentifyChain for T { } } -fn load_spec(id: &str, enable_instant_seal: bool) -> std::result::Result, String> { +fn load_spec(id: &str, enable_manual_seal: bool) -> std::result::Result, String> { Ok(match id { "" => Box::new(chain_spec::testnet_kintsugi::local_config(DEFAULT_PARA_ID.into())), "dev" => Box::new(chain_spec::testnet_kintsugi::development_config( DEFAULT_PARA_ID.into(), - enable_instant_seal, + enable_manual_seal, )), - "kintsugi-dev" | "kintsugi-bench" => Box::new(chain_spec::kintsugi::kintsugi_dev_config(enable_instant_seal)), + "kintsugi-dev" | "kintsugi-bench" => Box::new(chain_spec::kintsugi::kintsugi_dev_config(enable_manual_seal)), "kintsugi-latest" => Box::new(chain_spec::kintsugi::kintsugi_mainnet_config()), "kintsugi" => Box::new(chain_spec::KintsugiChainSpec::from_json_bytes( &include_bytes!("../res/kintsugi.json")[..], )?), - "interlay-dev" | "interlay-bench" => Box::new(chain_spec::interlay::interlay_dev_config(enable_instant_seal)), + "interlay-dev" | "interlay-bench" => Box::new(chain_spec::interlay::interlay_dev_config(enable_manual_seal)), "interlay-latest" => Box::new(chain_spec::interlay::interlay_mainnet_config()), "interlay" => Box::new(chain_spec::InterlayChainSpec::from_json_bytes( &include_bytes!("../res/interlay.json")[..], @@ -154,7 +154,8 @@ impl SubstrateCli for Cli { } fn load_spec(&self, id: &str) -> std::result::Result, String> { - load_spec(id, self.instant_seal) + let enable_manual_seal = self.sealing.is_some(); + load_spec(id, enable_manual_seal) } fn native_runtime_version(chain_spec: &Box) -> &'static RuntimeVersion { @@ -313,7 +314,7 @@ pub fn run() -> Result<()> { Some(Subcommand::Benchmark(cmd)) => { // some benchmarks set the timestamp so we ignore // the aura check which would otherwise panic - cli.instant_seal = true; + cli.sealing = Some(Sealing::Manual); let runner = cli.create_runner(cmd)?; match cmd { BenchmarkCmd::Pallet(cmd) => { @@ -470,8 +471,8 @@ pub fn run() -> Result<()> { runner .run_node_until_exit(|config| async move { - if cli.instant_seal { - start_instant(cli, config).await + if let Some(sealing) = cli.sealing { + start_instant(cli, config, sealing).await } else { start_node(cli, config).await } @@ -481,10 +482,10 @@ pub fn run() -> Result<()> { } } -async fn start_instant(cli: Cli, config: Configuration) -> sc_service::error::Result { +async fn start_instant(cli: Cli, config: Configuration, sealing: Sealing) -> sc_service::error::Result { with_runtime_or_err!(config.chain_spec, { { - crate::service::start_instant::(config, cli.eth) + crate::service::start_instant::(config, cli.eth, sealing) .await .map(|r| r.0) .map_err(Into::into) diff --git a/parachain/src/lib.rs b/parachain/src/lib.rs index 5a048e9d6d..1a11895181 100644 --- a/parachain/src/lib.rs +++ b/parachain/src/lib.rs @@ -1,4 +1,5 @@ pub mod chain_spec; pub mod service; +mod cli; mod eth; diff --git a/parachain/src/service.rs b/parachain/src/service.rs index 76719ed7de..0446ac6669 100644 --- a/parachain/src/service.rs +++ b/parachain/src/service.rs @@ -1,3 +1,4 @@ +use crate::cli::Sealing; use cumulus_client_cli::CollatorOptions; use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion}; use cumulus_client_consensus_common::{ParachainBlockImport as TParachainBlockImport, ParachainConsensus}; @@ -15,6 +16,7 @@ use polkadot_service::CollatorPair; use primitives::*; use sc_client_api::{HeaderBackend, StateBackendFor}; use sc_consensus::{ImportQueue, LongestChain}; +use sc_consensus_manual_seal::EngineCommand; use sc_executor::NativeElseWasmExecutor; use sc_network::NetworkBlock; use sc_network_sync::SyncingService; @@ -219,7 +221,7 @@ where pub fn new_partial( config: &Configuration, eth_config: &EthConfiguration, - instant_seal: bool, + manual_seal: bool, ) -> Result< PartialComponents< FullClient, @@ -285,7 +287,7 @@ where client.clone(), ); - let select_chain = if instant_seal { + let select_chain = if manual_seal { Some(LongestChain::new(backend.clone())) } else { None @@ -294,8 +296,8 @@ where let overrides = interbtc_rpc::overrides_handle(client.clone()); let frontier_backend = open_frontier_backend(client.clone(), config, eth_config, overrides.clone())?; - let import_queue = if instant_seal { - // instant sealing + let import_queue = if manual_seal { + // manual / instant seal sc_consensus_manual_seal::import_queue( Box::new(EthBlockImport::new(client.clone(), client.clone())), &task_manager.spawn_essential_handle(), @@ -679,6 +681,7 @@ where pub async fn start_instant( mut config: Configuration, eth_config: EthConfiguration, + sealing: Sealing, ) -> sc_service::error::Result<(TaskManager, RpcHandlers)> where RuntimeApi: ConstructRuntimeApi> + Send + Sync + 'static, @@ -731,15 +734,24 @@ where // Channel for the rpc handler to communicate with the authorship task. let (command_sink, commands_stream) = futures::channel::mpsc::channel(1024); - let pool = transaction_pool.pool().clone(); - let import_stream = pool.validated_pool().import_notification_stream().map(|_| { - sc_consensus_manual_seal::rpc::EngineCommand::SealNewBlock { - create_empty: true, - finalize: true, - parent_hash: None, - sender: None, + let commands_stream: Box> + Send + Sync + Unpin> = match sealing + { + Sealing::Instant => { + let import_stream = transaction_pool + .pool() + .validated_pool() + .import_notification_stream() + .map(|_| EngineCommand::SealNewBlock { + create_empty: true, + finalize: true, + parent_hash: None, + sender: None, + }); + // combine so we can still seal blocks manually + Box::new(futures::stream_select!(commands_stream, import_stream)) } - }); + Sealing::Manual => Box::new(commands_stream), + }; let client_for_cidp = client.clone(); @@ -748,7 +760,7 @@ where env: proposer_factory, client: client.clone(), pool: transaction_pool.clone(), - commands_stream: futures::stream_select!(commands_stream, import_stream), + commands_stream, select_chain, consensus_data_provider: None, create_inherent_data_providers: move |block: Hash, _| { @@ -774,7 +786,7 @@ where }); // we spawn the future on a background thread managed by service. task_manager.spawn_essential_handle().spawn_blocking( - "instant-seal", + "authorship_task", Some("block-authoring"), authorship_future, );