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 sc_cli::SubstrateCli;
7
8pub fn run_as_parachain(cli: Cli) -> sc_service::Result<(), sc_cli::Error> {
9 let runner = cli.create_runner(&cli.run.normalize())?;
10 let collator_options = cli.run.collator_options();
11 runner.run_node_until_exit(|config| async move {
12 let hwbench = (!cli.no_hardware_benchmarks)
13 .then_some(config.database.path().map(|database_path| {
14 let _ = std::fs::create_dir_all(database_path);
15 sc_sysinfo::gather_hwbench(Some(database_path), &SUBSTRATE_REFERENCE_HARDWARE)
16 }))
17 .flatten();
18
19 let para_id = chain_spec::Extensions::try_get(&*config.chain_spec)
20 .map(|e: &chain_spec::Extensions| e.para_id)
21 .ok_or("Could not find parachain ID in chain-spec.")?;
22
23 let polkadot_cli = RelayChainCli::new(
24 &config,
25 [RelayChainCli::executable_name()].iter().chain(cli.relay_chain_args.iter()),
26 );
27
28 let id = ParaId::from(para_id);
29
30 let tokio_handle = config.tokio_handle.clone();
31
32 let polkadot_config =
33 SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle)
34 .map_err(|err| format!("Relay chain argument error: {err:?}"))?;
35
36 info!("Parachain id: {id:?}");
37 info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" });
38
39 frequency_service::service::start_parachain_node(
40 config,
41 polkadot_config,
42 collator_options,
43 id,
44 hwbench,
45 None,
46 )
47 .await
48 .map(|r| r.0)
49 .map_err(Into::into)
50 })
51}