Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Companion for Substrate#14511 (#2821)
Browse files Browse the repository at this point in the history
* Companion for Substrate#14511

paritytech/substrate#14511

* update lockfile for {"substrate", "polkadot"}

---------

Co-authored-by: parity-processbot <>
  • Loading branch information
bkchr authored Jul 5, 2023
1 parent 5dd8bc9 commit e5674d9
Show file tree
Hide file tree
Showing 11 changed files with 314 additions and 390 deletions.
530 changes: 265 additions & 265 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ url = "2.4.0"

# Substrate
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down
10 changes: 8 additions & 2 deletions client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::{

use codec::Encode;
use sc_chain_spec::ChainSpec;
use sc_client_api::ExecutorProvider;
use sc_service::{
config::{PrometheusConfig, TelemetryEndpoints},
BasePath, TransactionPoolOptions,
Expand Down Expand Up @@ -149,9 +150,14 @@ impl ExportGenesisStateCommand {
pub fn run<Block: BlockT>(
&self,
chain_spec: &dyn ChainSpec,
genesis_state_version: StateVersion,
client: &impl ExecutorProvider<Block>,
) -> sc_cli::Result<()> {
let block: Block = generate_genesis_block(chain_spec, genesis_state_version)?;
let state_version = sc_chain_spec::resolve_state_version_from_wasm(
&chain_spec.build_storage()?,
client.executor(),
)?;

let block: Block = generate_genesis_block(chain_spec, state_version)?;
let raw_header = block.header().encode();
let output_buf = if self.raw {
raw_header
Expand Down
2 changes: 1 addition & 1 deletion client/relay-chain-inprocess-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master" }

# Polkadot
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false, features = ["cli", "polkadot-native"] }
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false, features = ["cli"] }
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "master" }

# Cumulus
Expand Down
53 changes: 22 additions & 31 deletions parachain-template/node/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
use std::net::SocketAddr;

use codec::Encode;
use cumulus_client_cli::generate_genesis_block;
use cumulus_primitives_core::ParaId;
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use log::{info, warn};
use parachain_template_runtime::Block;
use sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,
NetworkParams, Result, SharedParams, SubstrateCli,
};
use sc_service::config::{BasePath, PrometheusConfig};
use sp_core::hexdisplay::HexDisplay;
use sp_runtime::traits::{AccountIdConversion, Block as BlockT};
use sp_runtime::traits::AccountIdConversion;

use crate::{
chain_spec,
Expand Down Expand Up @@ -63,10 +60,6 @@ impl SubstrateCli for Cli {
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
load_spec(id)
}

fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
&parachain_template_runtime::VERSION
}
}

impl SubstrateCli for RelayChainCli {
Expand Down Expand Up @@ -103,10 +96,6 @@ impl SubstrateCli for RelayChainCli {
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)
}

fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
polkadot_cli::Cli::native_runtime_version(chain_spec)
}
}

macro_rules! construct_async_run {
Expand Down Expand Up @@ -175,10 +164,10 @@ pub fn run() -> Result<()> {
},
Some(Subcommand::ExportGenesisState(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|_config| {
let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
let state_version = Cli::native_runtime_version(&spec).state_version();
cmd.run::<Block>(&*spec, state_version)
runner.sync_run(|config| {
let partials = new_partial(&config)?;

cmd.run(&*config.chain_spec, &*partials.client)
})
},
Some(Subcommand::ExportGenesisWasm(cmd)) => {
Expand Down Expand Up @@ -258,11 +247,12 @@ pub fn run() -> Result<()> {
let collator_options = cli.run.collator_options();

runner.run_node_until_exit(|config| async move {
let hwbench = (!cli.no_hardware_benchmarks).then_some(
config.database.path().map(|database_path| {
let hwbench = (!cli.no_hardware_benchmarks)
.then_some(config.database.path().map(|database_path| {
let _ = std::fs::create_dir_all(database_path);
sc_sysinfo::gather_hwbench(Some(database_path))
})).flatten();
}))
.flatten();

let para_id = chain_spec::Extensions::try_get(&*config.chain_spec)
.map(|e| e.para_id)
Expand All @@ -276,25 +266,26 @@ pub fn run() -> Result<()> {
let id = ParaId::from(para_id);

let parachain_account =
AccountIdConversion::<polkadot_primitives::AccountId>::into_account_truncating(&id);

let state_version = Cli::native_runtime_version(&config.chain_spec).state_version();
let block: Block = generate_genesis_block(&*config.chain_spec, state_version)
.map_err(|e| format!("{:?}", e))?;
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
AccountIdConversion::<polkadot_primitives::AccountId>::into_account_truncating(
&id,
);

let tokio_handle = config.tokio_handle.clone();
let polkadot_config =
SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle)
.map_err(|err| format!("Relay chain argument error: {}", err))?;

info!("Parachain id: {:?}", id);
info!("Parachain Account: {}", parachain_account);
info!("Parachain genesis state: {}", genesis_state);
info!("Parachain Account: {parachain_account}");
info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" });

if !collator_options.relay_chain_rpc_urls.is_empty() && !cli.relay_chain_args.is_empty() {
warn!("Detected relay chain node arguments together with --relay-chain-rpc-url. This command starts a minimal Polkadot node that only uses a network-related subset of all relay chain CLI options.");
if !collator_options.relay_chain_rpc_urls.is_empty() &&
!cli.relay_chain_args.is_empty()
{
warn!(
"Detected relay chain node arguments together with --relay-chain-rpc-url. \
This command starts a minimal Polkadot node that only uses a \
network-related subset of all relay chain CLI options."
);
}

crate::service::start_parachain_node(
Expand Down
5 changes: 2 additions & 3 deletions polkadot-parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrat
substrate-state-trie-migration-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }

# Polkadot
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "master" }
# Use rococo-native as this is currently the default "local" relay chain
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "master", features = ["rococo-native"] }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "master" }
xcm = { git = "https://github.com/paritytech/polkadot", branch = "master" }
Expand All @@ -99,8 +100,6 @@ nix = { version = "0.26.1", features = ["signal"] }
tempfile = "3.6.0"
tokio = { version = "1.29.1", features = ["macros", "time", "parking_lot"] }
wait-timeout = "0.2"
# purge_chain_works works with rococo-local and needs to allow this
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "master", features = ["rococo-native"] }

[features]
default = []
Expand Down
21 changes: 0 additions & 21 deletions polkadot-parachain/src/chain_spec/bridge_hubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed};
use cumulus_primitives_core::ParaId;
use parachains_common::Balance as BridgeHubBalance;
use sc_chain_spec::ChainSpec;
use sc_cli::RuntimeVersion;
use sp_core::sr25519;
use std::{path::PathBuf, str::FromStr};

Expand Down Expand Up @@ -165,26 +164,6 @@ impl BridgeHubRuntimeType {
))),
}
}

pub fn runtime_version(&self) -> &'static RuntimeVersion {
match self {
BridgeHubRuntimeType::Polkadot |
BridgeHubRuntimeType::PolkadotLocal |
BridgeHubRuntimeType::PolkadotDevelopment => &bridge_hub_polkadot_runtime::VERSION,
BridgeHubRuntimeType::Kusama |
BridgeHubRuntimeType::KusamaLocal |
BridgeHubRuntimeType::KusamaDevelopment => &bridge_hub_kusama_runtime::VERSION,
BridgeHubRuntimeType::Westend => &bridge_hub_kusama_runtime::VERSION,
BridgeHubRuntimeType::Rococo |
BridgeHubRuntimeType::RococoLocal |
BridgeHubRuntimeType::RococoDevelopment |
BridgeHubRuntimeType::Wococo |
BridgeHubRuntimeType::WococoLocal => {
// this is intentional, for Rococo/Wococo we just want to have one runtime, which is configured for both sides
&bridge_hub_rococo_runtime::VERSION
},
}
}
}

/// Check if 'id' satisfy BridgeHub-like format
Expand Down
57 changes: 12 additions & 45 deletions polkadot-parachain/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@ use crate::{
cli::{Cli, RelayChainCli, Subcommand},
service::{new_partial, Block},
};
use codec::Encode;
use cumulus_client_cli::generate_genesis_block;
use cumulus_primitives_core::ParaId;
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use log::{info, warn};
use parachains_common::{AssetHubPolkadotAuraId, AuraId};
use sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,
NetworkParams, Result, SharedParams, SubstrateCli,
};
use sc_service::config::{BasePath, PrometheusConfig};
use sp_core::hexdisplay::HexDisplay;
use sp_runtime::traits::{AccountIdConversion, Block as BlockT};
use sp_runtime::traits::AccountIdConversion;
use std::{net::SocketAddr, path::PathBuf};

/// Helper enum that is used for better distinction of different parachain/runtime configuration
Expand Down Expand Up @@ -345,24 +342,6 @@ impl SubstrateCli for Cli {
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
load_spec(id)
}

fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
match chain_spec.runtime() {
Runtime::AssetHubPolkadot => &asset_hub_polkadot_runtime::VERSION,
Runtime::AssetHubKusama => &asset_hub_kusama_runtime::VERSION,
Runtime::AssetHubWestend => &asset_hub_westend_runtime::VERSION,
Runtime::CollectivesPolkadot | Runtime::CollectivesWestend =>
&collectives_polkadot_runtime::VERSION,
Runtime::Shell => &shell_runtime::VERSION,
Runtime::Seedling => &seedling_runtime::VERSION,
Runtime::ContractsRococo => &contracts_rococo_runtime::VERSION,
Runtime::BridgeHub(bridge_hub_runtime_type) =>
bridge_hub_runtime_type.runtime_version(),
Runtime::Penpal(_) => &penpal_runtime::VERSION,
Runtime::Glutton => &glutton_runtime::VERSION,
Runtime::Default => &rococo_parachain_runtime::VERSION,
}
}
}

impl SubstrateCli for RelayChainCli {
Expand Down Expand Up @@ -399,10 +378,6 @@ impl SubstrateCli for RelayChainCli {
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)
}

fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
polkadot_cli::Cli::native_runtime_version(chain_spec)
}
}

/// Creates partial components for the runtimes that are supported by the benchmarks.
Expand Down Expand Up @@ -586,7 +561,7 @@ macro_rules! construct_async_run {
runner.async_run(|$config| {
let $components = new_partial::<
rococo_parachain_runtime::RuntimeApi,
_
_,
>(
&$config,
crate::service::rococo_parachain_build_import_queue,
Expand Down Expand Up @@ -660,14 +635,10 @@ pub fn run() -> Result<()> {
cmd.run(config, polkadot_config)
})
},
Some(Subcommand::ExportGenesisState(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|_config| {
let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
let state_version = Cli::native_runtime_version(&spec).state_version();
cmd.run::<crate::service::Block>(&*spec, state_version)
})
},
Some(Subcommand::ExportGenesisState(cmd)) =>
construct_async_run!(|components, cli, cmd, config| {
Ok(async move { cmd.run(&*config.chain_spec, &*components.client) })
}),
Some(Subcommand::ExportGenesisWasm(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|_config| {
Expand Down Expand Up @@ -797,25 +768,21 @@ pub fn run() -> Result<()> {
let parachain_account =
AccountIdConversion::<polkadot_primitives::AccountId>::into_account_truncating(&id);

let state_version = Cli::native_runtime_version(&config.chain_spec).state_version();

let block: crate::service::Block =
generate_genesis_block(&*config.chain_spec, state_version)
.map_err(|e| format!("{:?}", e))?;
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));

let tokio_handle = config.tokio_handle.clone();
let polkadot_config =
SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle)
.map_err(|err| format!("Relay chain argument error: {}", err))?;

info!("Parachain id: {:?}", id);
info!("Parachain Account: {}", parachain_account);
info!("Parachain genesis state: {}", genesis_state);
info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" });

if !collator_options.relay_chain_rpc_urls.is_empty() && !cli.relaychain_args.is_empty() {
warn!("Detected relay chain node arguments together with --relay-chain-rpc-url. This command starts a minimal Polkadot node that only uses a network-related subset of all relay chain CLI options.");
warn!(
"Detected relay chain node arguments together with --relay-chain-rpc-url. \
This command starts a minimal Polkadot node that only uses a \
network-related subset of all relay chain CLI options."
);
}

match config.chain_spec.runtime() {
Expand Down
6 changes: 2 additions & 4 deletions polkadot-parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ where
&task_manager,
)?;

let params = PartialComponents {
Ok(PartialComponents {
backend,
client,
import_queue,
Expand All @@ -326,9 +326,7 @@ where
transaction_pool,
select_chain: (),
other: (block_import, telemetry, telemetry_worker_handle),
};

Ok(params)
})
}

/// Start a shell node with the given parachain `Configuration` and relay chain `Configuration`.
Expand Down
10 changes: 1 addition & 9 deletions test/service/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{net::SocketAddr, path::PathBuf};
use polkadot_service::{ChainSpec, ParaId, PrometheusConfig};
use sc_cli::{
CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams,
Result as CliResult, RuntimeVersion, SharedParams, SubstrateCli,
Result as CliResult, SharedParams, SubstrateCli,
};
use sc_service::BasePath;

Expand Down Expand Up @@ -296,10 +296,6 @@ impl SubstrateCli for TestCollatorCli {
},
})
}

fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
&cumulus_test_service::runtime::VERSION
}
}

impl SubstrateCli for RelayChainCli {
Expand Down Expand Up @@ -337,8 +333,4 @@ impl SubstrateCli for RelayChainCli {
<polkadot_cli::Cli as SubstrateCli>::from_iter([RelayChainCli::executable_name()].iter())
.load_spec(id)
}

fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
polkadot_cli::Cli::native_runtime_version(chain_spec)
}
}
9 changes: 0 additions & 9 deletions test/service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,13 @@ fn main() -> Result<(), sc_cli::Error> {
&parachain_id,
);

let state_version =
RelayChainCli::native_runtime_version(&config.chain_spec).state_version();

let block: parachains_common::Block =
generate_genesis_block(&*config.chain_spec, state_version)
.map_err(|e| format!("{:?}", e))?;
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));

let tokio_handle = config.tokio_handle.clone();
let polkadot_config =
SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle)
.map_err(|err| format!("Relay chain argument error: {}", err))?;

tracing::info!("Parachain id: {:?}", parachain_id);
tracing::info!("Parachain Account: {}", parachain_account);
tracing::info!("Parachain genesis state: {}", genesis_state);
tracing::info!(
"Is collating: {}",
if config.role.is_authority() { "yes" } else { "no" }
Expand Down

0 comments on commit e5674d9

Please sign in to comment.