frequency_cli/
run_as_parachain.rs1use crate::cli::{Cli, RelayChainCli};
2use cumulus_primitives_core::ParaId;
3use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE;
4use frequency_service::chain_spec;
5use log::info;
6use polkadot_service::TransactionPoolOptions;
7use sc_cli::{SubstrateCli, TransactionPoolType};
8
9#[allow(clippy::result_large_err)]
10pub fn run_as_parachain(cli: Cli) -> sc_service::Result<(), sc_cli::Error> {
11 let runner = cli.create_runner(&cli.run.normalize())?;
12 let collator_options = cli.run.collator_options();
13 let override_pool_config = TransactionPoolOptions::new_with_params(
14 cli.run.base.pool_config.pool_limit,
15 cli.run.base.pool_config.pool_kbytes * 1024,
16 cli.run.base.pool_config.tx_ban_seconds,
17 TransactionPoolType::ForkAware.into(),
18 false,
19 );
20
21 runner.run_node_until_exit(|config| async move {
22 let hwbench = (!cli.no_hardware_benchmarks)
23 .then_some(config.database.path().map(|database_path| {
24 let _ = std::fs::create_dir_all(database_path);
25 sc_sysinfo::gather_hwbench(Some(database_path), &SUBSTRATE_REFERENCE_HARDWARE)
26 }))
27 .flatten();
28
29 let para_id = chain_spec::Extensions::try_get(&*config.chain_spec)
30 .map(|e: &chain_spec::Extensions| e.para_id)
31 .ok_or("Could not find parachain ID in chain-spec.")?;
32
33 let polkadot_cli = RelayChainCli::new(
34 &config,
35 [RelayChainCli::executable_name()].iter().chain(cli.relay_chain_args.iter()),
36 );
37
38 let id = ParaId::from(para_id);
39
40 let tokio_handle = config.tokio_handle.clone();
41
42 let polkadot_config =
43 SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle)
44 .map_err(|err| format!("Relay chain argument error: {err:?}"))?;
45
46 info!("Parachain id: {id:?}");
47 info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" });
48
49 frequency_service::service::start_parachain_node(
50 config,
51 polkadot_config,
52 collator_options,
53 id,
54 hwbench,
55 Some(override_pool_config),
56 )
57 .await
58 .map(|r| r.0)
59 .map_err(Into::into)
60 })
61}