mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 15:11:02 +00:00
Add parachains for rococo (#144)
* Add parachains for rococo * Fix chain specs * Update to revert log rotation * Support selecting the chain in `export-genesis-state` * Add subcommand for exporting the genesis wasm of a Parachain * Update stuff * Fix `export-genesis-wasm` * Update the polkadot ref * Add bootNodes address * Add bootNodes address - track * Add bootNodes address - trick * Fix incorrect peer id (trick) * Fixes https://github.com/paritytech/cumulus/issues/157 * Update chainspecs * Update specs again * Set correct sudo account * Update properties * Update readme * Update `Cargo.lock` * Switch to rococo-branch Co-authored-by: Evaldo <contato@evaldofelipe.com> Co-authored-by: Cecile Tonglet <cecile.tonglet@cecton.com>
This commit is contained in:
@@ -19,31 +19,33 @@ trie-root = '0.15.2'
|
||||
codec = { package = 'parity-scale-codec', version = '1.0.0' }
|
||||
structopt = "0.3.3"
|
||||
ansi_term = "0.12.1"
|
||||
serde = { version = "1.0.101", features = ["derive"] }
|
||||
hex-literal = "0.2.1"
|
||||
|
||||
# Parachain dependencies
|
||||
parachain-runtime = { package = "cumulus-test-parachain-runtime", path = "runtime" }
|
||||
|
||||
# Substrate dependencies
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-service = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-network = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", version = "0.8.0-rc5" }
|
||||
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-api = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-informant = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sc-service = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sc-network = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch", version = "0.8.0-rc5" }
|
||||
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sp-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sc-informant = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
|
||||
# Cumulus dependencies
|
||||
cumulus-consensus = { path = "../../consensus" }
|
||||
@@ -52,15 +54,15 @@ cumulus-network = { path = "../../network" }
|
||||
cumulus-primitives = { path = "../../primitives" }
|
||||
|
||||
# Polkadot dependencies
|
||||
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-collator = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||
polkadot-collator = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||
polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||
|
||||
[build-dependencies]
|
||||
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = "0.12"
|
||||
@@ -69,12 +71,12 @@ rand = "0.7.3"
|
||||
tokio = { version = "0.2.13", features = ["macros"] }
|
||||
|
||||
# Polkadot dependencies
|
||||
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-test-runtime = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-test-runtime-client = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||
polkadot-test-runtime = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||
polkadot-test-runtime-client = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||
polkadot-test-service = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch" }
|
||||
|
||||
# Substrate dependencies
|
||||
pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
substrate-test-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
substrate-test-client = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
substrate-test-runtime-client = { git = "https://github.com/paritytech/substrate", branch = "rococo-branch" }
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -9,26 +9,26 @@ serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] }
|
||||
|
||||
# Substrate dependencies
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-offchain = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
sp-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
sp-offchain = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "cumulus-branch" }
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "rococo-branch" }
|
||||
|
||||
# Cumulus dependencies
|
||||
cumulus-runtime = { path = "../../../runtime", default-features = false }
|
||||
@@ -38,7 +38,7 @@ cumulus-upward-message = { path = "../../../upward-message", default-features =
|
||||
cumulus-primitives = { path = "../../../primitives", default-features = false }
|
||||
|
||||
# Polkadot dependencies
|
||||
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
|
||||
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "rococo-branch", default-features = false }
|
||||
|
||||
[build-dependencies]
|
||||
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.6" }
|
||||
|
||||
@@ -101,11 +101,11 @@ pub mod opaque {
|
||||
|
||||
/// This runtime version.
|
||||
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: create_runtime_str!("wasm-test-parachain"),
|
||||
impl_name: create_runtime_str!("wasm-test-parachain"),
|
||||
authoring_version: 3,
|
||||
spec_version: 4,
|
||||
impl_version: 4,
|
||||
spec_name: create_runtime_str!("cumulus-test-parachain"),
|
||||
impl_name: create_runtime_str!("cumulus-test-parachain"),
|
||||
authoring_version: 1,
|
||||
spec_version: 1,
|
||||
impl_version: 1,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
transaction_version: 1,
|
||||
};
|
||||
@@ -250,7 +250,7 @@ parameter_types! {
|
||||
impl cumulus_message_broker::Trait for Runtime {
|
||||
type Event = Event;
|
||||
type DownwardMessageHandlers = TokenDealer;
|
||||
type UpwardMessage = cumulus_upward_message::WestendUpwardMessage;
|
||||
type UpwardMessage = cumulus_upward_message::RococoUpwardMessage;
|
||||
type ParachainId = ParachainId;
|
||||
type XCMPMessage = XCMPMessage<AccountId, Balance>;
|
||||
type XCMPMessageHandlers = TokenDealer;
|
||||
@@ -259,7 +259,7 @@ impl cumulus_message_broker::Trait for Runtime {
|
||||
impl message_example::Trait for Runtime {
|
||||
type Event = Event;
|
||||
type UpwardMessageSender = MessageBroker;
|
||||
type UpwardMessage = cumulus_upward_message::WestendUpwardMessage;
|
||||
type UpwardMessage = cumulus_upward_message::RococoUpwardMessage;
|
||||
type Currency = Balances;
|
||||
type XCMPMessageSender = MessageBroker;
|
||||
}
|
||||
|
||||
@@ -19,12 +19,15 @@ use parachain_runtime::{
|
||||
AccountId, BalancesConfig, GenesisConfig, Signature, SudoConfig, SystemConfig,
|
||||
TokenDealerConfig, WASM_BINARY,
|
||||
};
|
||||
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
|
||||
use sc_service::ChainType;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sp_core::{sr25519, Pair, Public};
|
||||
use sp_runtime::traits::{IdentifyAccount, Verify};
|
||||
use hex_literal::hex;
|
||||
|
||||
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
|
||||
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;
|
||||
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig, Extensions>;
|
||||
|
||||
/// Helper function to generate a crypto pair from seed
|
||||
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
|
||||
@@ -33,6 +36,23 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu
|
||||
.public()
|
||||
}
|
||||
|
||||
/// The extensions for the [`ChainSpec`].
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Extensions {
|
||||
/// The relay chain of the Parachain.
|
||||
pub relay_chain: String,
|
||||
/// The id of the Parachain.
|
||||
pub para_id: u32,
|
||||
}
|
||||
|
||||
impl Extensions {
|
||||
/// Try to get the extension from the given `ChainSpec`.
|
||||
pub fn try_get(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Option<&Self> {
|
||||
sc_chain_spec::get_extension(chain_spec.extensions())
|
||||
}
|
||||
}
|
||||
|
||||
type AccountPublic = <Signature as Verify>::Signer;
|
||||
|
||||
/// Helper function to generate an account ID from seed
|
||||
@@ -72,7 +92,33 @@ pub fn get_chain_spec(id: ParaId) -> ChainSpec {
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Extensions {
|
||||
relay_chain: "westend-dev".into(),
|
||||
para_id: id.into(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn staging_test_net(id: ParaId) -> ChainSpec {
|
||||
ChainSpec::from_genesis(
|
||||
"Staging Testnet",
|
||||
"staging_testnet",
|
||||
ChainType::Live,
|
||||
move || {
|
||||
testnet_genesis(
|
||||
hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into(),
|
||||
vec![hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into()],
|
||||
id,
|
||||
)
|
||||
},
|
||||
Vec::new(),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Extensions {
|
||||
relay_chain: "westend-dev".into(),
|
||||
para_id: id.into(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,10 @@ pub enum Subcommand {
|
||||
/// Export the genesis state of the parachain.
|
||||
#[structopt(name = "export-genesis-state")]
|
||||
ExportGenesisState(ExportGenesisStateCommand),
|
||||
|
||||
/// Export the genesis wasm of the parachain.
|
||||
#[structopt(name = "export-genesis-wasm")]
|
||||
ExportGenesisWasm(ExportGenesisWasmCommand),
|
||||
}
|
||||
|
||||
/// Command for exporting the genesis state of the parachain
|
||||
@@ -40,6 +44,22 @@ pub struct ExportGenesisStateCommand {
|
||||
/// Id of the parachain this state is for.
|
||||
#[structopt(long, default_value = "100")]
|
||||
pub parachain_id: u32,
|
||||
|
||||
/// The name of the chain for that the genesis state should be exported.
|
||||
#[structopt(long)]
|
||||
pub chain: Option<String>,
|
||||
}
|
||||
|
||||
/// Command for exporting the genesis wasm file.
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct ExportGenesisWasmCommand {
|
||||
/// Output file name or stdout if unspecified.
|
||||
#[structopt(parse(from_os_str))]
|
||||
pub output: Option<PathBuf>,
|
||||
|
||||
/// The name of the chain for that the genesis wasm file should be exported.
|
||||
#[structopt(long)]
|
||||
pub chain: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
@@ -48,8 +68,8 @@ pub struct RunCmd {
|
||||
pub base: sc_cli::RunCmd,
|
||||
|
||||
/// Id of the parachain this collator collates for.
|
||||
#[structopt(long, default_value = "100")]
|
||||
pub parachain_id: u32,
|
||||
#[structopt(long)]
|
||||
pub parachain_id: Option<u32>,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for RunCmd {
|
||||
@@ -78,11 +98,29 @@ pub struct Cli {
|
||||
pub relaychain_args: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct PolkadotCli {
|
||||
#[structopt(flatten)]
|
||||
#[derive(Debug)]
|
||||
pub struct RelayChainCli {
|
||||
/// The actual relay chain cli object.
|
||||
pub base: polkadot_cli::RunCmd,
|
||||
|
||||
#[structopt(skip)]
|
||||
/// Optional chain id that should be passed to the relay chain.
|
||||
pub chain_id: Option<String>,
|
||||
|
||||
/// The base path that should be used by the relay chain.
|
||||
pub base_path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl RelayChainCli {
|
||||
/// Create a new instance of `Self`.
|
||||
pub fn new<'a>(
|
||||
base_path: Option<PathBuf>,
|
||||
chain_id: Option<String>,
|
||||
relay_chain_args: impl Iterator<Item = &'a String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
base_path,
|
||||
chain_id,
|
||||
base: polkadot_cli::RunCmd::from_iter(relay_chain_args),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,10 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::chain_spec;
|
||||
use crate::cli::{Cli, PolkadotCli, Subcommand};
|
||||
use crate::{
|
||||
chain_spec,
|
||||
cli::{Cli, RelayChainCli, Subcommand},
|
||||
};
|
||||
use codec::Encode;
|
||||
use cumulus_primitives::ParaId;
|
||||
use log::info;
|
||||
@@ -27,11 +29,8 @@ use sc_cli::{
|
||||
};
|
||||
use sc_service::config::{BasePath, PrometheusConfig};
|
||||
use sp_core::hexdisplay::HexDisplay;
|
||||
use sp_runtime::{
|
||||
traits::{Block as BlockT, Hash as HashT, Header as HeaderT, Zero},
|
||||
BuildStorage,
|
||||
};
|
||||
use std::{net::SocketAddr, sync::Arc};
|
||||
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, Zero};
|
||||
use std::{io::Write, net::SocketAddr, sync::Arc};
|
||||
|
||||
impl SubstrateCli for Cli {
|
||||
fn impl_name() -> String {
|
||||
@@ -64,11 +63,27 @@ impl SubstrateCli for Cli {
|
||||
2017
|
||||
}
|
||||
|
||||
fn load_spec(&self, _id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
|
||||
// Such a hack :(
|
||||
Ok(Box::new(chain_spec::get_chain_spec(
|
||||
self.run.parachain_id.into(),
|
||||
)))
|
||||
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
|
||||
match id {
|
||||
"staging" => Ok(Box::new(chain_spec::staging_test_net(
|
||||
self.run.parachain_id.unwrap_or(100).into(),
|
||||
))),
|
||||
"tick" => Ok(Box::new(chain_spec::ChainSpec::from_json_bytes(
|
||||
&include_bytes!("../res/tick.json")[..],
|
||||
)?)),
|
||||
"trick" => Ok(Box::new(chain_spec::ChainSpec::from_json_bytes(
|
||||
&include_bytes!("../res/trick.json")[..],
|
||||
)?)),
|
||||
"track" => Ok(Box::new(chain_spec::ChainSpec::from_json_bytes(
|
||||
&include_bytes!("../res/track.json")[..],
|
||||
)?)),
|
||||
"" => Ok(Box::new(chain_spec::get_chain_spec(
|
||||
self.run.parachain_id.unwrap_or(100).into(),
|
||||
))),
|
||||
path => Ok(Box::new(chain_spec::ChainSpec::from_json_file(
|
||||
path.into(),
|
||||
)?)),
|
||||
}
|
||||
}
|
||||
|
||||
fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
|
||||
@@ -76,7 +91,7 @@ impl SubstrateCli for Cli {
|
||||
}
|
||||
}
|
||||
|
||||
impl SubstrateCli for PolkadotCli {
|
||||
impl SubstrateCli for RelayChainCli {
|
||||
fn impl_name() -> String {
|
||||
"Cumulus Test Parachain Collator".into()
|
||||
}
|
||||
@@ -106,7 +121,7 @@ impl SubstrateCli for PolkadotCli {
|
||||
}
|
||||
|
||||
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
|
||||
polkadot_cli::Cli::from_iter([PolkadotCli::executable_name().to_string()].iter())
|
||||
polkadot_cli::Cli::from_iter([RelayChainCli::executable_name().to_string()].iter())
|
||||
.load_spec(id)
|
||||
}
|
||||
|
||||
@@ -115,9 +130,8 @@ impl SubstrateCli for PolkadotCli {
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate the genesis block
|
||||
pub fn generate_genesis_state(para_id: ParaId) -> Result<Block> {
|
||||
let storage = (&chain_spec::get_chain_spec(para_id)).build_storage()?;
|
||||
pub fn generate_genesis_state(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Block> {
|
||||
let storage = chain_spec.build_storage()?;
|
||||
|
||||
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
|
||||
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
@@ -144,6 +158,15 @@ pub fn generate_genesis_state(para_id: ParaId) -> Result<Block> {
|
||||
))
|
||||
}
|
||||
|
||||
fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Vec<u8>> {
|
||||
let mut storage = chain_spec.build_storage()?;
|
||||
|
||||
storage
|
||||
.top
|
||||
.remove(sp_core::storage::well_known_keys::CODE)
|
||||
.ok_or_else(|| "Could not find wasm file in genesis state!".into())
|
||||
}
|
||||
|
||||
/// Parse command line arguments into service configuration.
|
||||
pub fn run() -> Result<()> {
|
||||
let cli = Cli::from_args();
|
||||
@@ -166,7 +189,8 @@ pub fn run() -> Result<()> {
|
||||
Some(Subcommand::ExportGenesisState(params)) => {
|
||||
sc_cli::init_logger("");
|
||||
|
||||
let block = generate_genesis_state(params.parachain_id.into())?;
|
||||
let block =
|
||||
generate_genesis_state(&cli.load_spec(¶ms.chain.clone().unwrap_or_default())?)?;
|
||||
let header_hex = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
|
||||
|
||||
if let Some(output) = ¶ms.output {
|
||||
@@ -177,29 +201,47 @@ pub fn run() -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Some(Subcommand::ExportGenesisWasm(params)) => {
|
||||
sc_cli::init_logger("");
|
||||
|
||||
let wasm_file =
|
||||
extract_genesis_wasm(&cli.load_spec(¶ms.chain.clone().unwrap_or_default())?)?;
|
||||
|
||||
if let Some(output) = ¶ms.output {
|
||||
std::fs::write(output, wasm_file)?;
|
||||
} else {
|
||||
std::io::stdout().write_all(&wasm_file)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
None => {
|
||||
let runner = cli.create_runner(&*cli.run)?;
|
||||
|
||||
// TODO
|
||||
let key = Arc::new(sp_core::Pair::generate().0);
|
||||
|
||||
let mut polkadot_cli = PolkadotCli::from_iter(
|
||||
[PolkadotCli::executable_name().to_string()]
|
||||
.iter()
|
||||
.chain(cli.relaychain_args.iter()),
|
||||
);
|
||||
|
||||
let id = ParaId::from(cli.run.parachain_id);
|
||||
|
||||
let parachain_account =
|
||||
AccountIdConversion::<polkadot_primitives::v0::AccountId>::into_account(&id);
|
||||
|
||||
let block = generate_genesis_state(id)?;
|
||||
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
|
||||
|
||||
runner.run_node_until_exit(|config| {
|
||||
polkadot_cli.base_path =
|
||||
config.base_path.as_ref().map(|x| x.path().join("polkadot"));
|
||||
// TODO
|
||||
let key = Arc::new(sp_core::Pair::generate().0);
|
||||
|
||||
let extension = chain_spec::Extensions::try_get(&config.chain_spec);
|
||||
let relay_chain_id = extension.map(|e| e.relay_chain.clone());
|
||||
let para_id = extension.map(|e| e.para_id);
|
||||
|
||||
let polkadot_cli = RelayChainCli::new(
|
||||
config.base_path.as_ref().map(|x| x.path().join("polkadot")),
|
||||
relay_chain_id,
|
||||
[RelayChainCli::executable_name().to_string()]
|
||||
.iter()
|
||||
.chain(cli.relaychain_args.iter()),
|
||||
);
|
||||
|
||||
let id = ParaId::from(cli.run.parachain_id.or(para_id).unwrap_or(100));
|
||||
|
||||
let parachain_account =
|
||||
AccountIdConversion::<polkadot_primitives::v0::AccountId>::into_account(&id);
|
||||
|
||||
let block =
|
||||
generate_genesis_state(&config.chain_spec).map_err(|e| format!("{:?}", e))?;
|
||||
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
|
||||
|
||||
let task_executor = config.task_executor.clone();
|
||||
let polkadot_config =
|
||||
@@ -227,7 +269,7 @@ pub fn run() -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
impl CliConfiguration for PolkadotCli {
|
||||
impl CliConfiguration for RelayChainCli {
|
||||
fn shared_params(&self) -> &SharedParams {
|
||||
self.base.base.shared_params()
|
||||
}
|
||||
@@ -310,6 +352,16 @@ impl CliConfiguration for PolkadotCli {
|
||||
unreachable!("PolkadotCli is never initialized; qed");
|
||||
}
|
||||
|
||||
fn chain_id(&self, is_dev: bool) -> Result<String> {
|
||||
let chain_id = self.base.base.chain_id(is_dev)?;
|
||||
|
||||
Ok(if chain_id.is_empty() {
|
||||
self.chain_id.clone().unwrap_or_default()
|
||||
} else {
|
||||
chain_id
|
||||
})
|
||||
}
|
||||
|
||||
fn role(&self, is_dev: bool) -> Result<sc_service::Role> {
|
||||
self.base.base.role(is_dev)
|
||||
}
|
||||
|
||||
@@ -60,8 +60,7 @@ async fn integration_test() {
|
||||
INTEGRATION_TEST_ALLOWED_TIME
|
||||
.and_then(|x| x.parse().ok())
|
||||
.unwrap_or(600),
|
||||
))
|
||||
.fuse();
|
||||
)).fuse();
|
||||
|
||||
let t2 = async {
|
||||
let para_id = ParaId::from(100);
|
||||
@@ -69,7 +68,8 @@ async fn integration_test() {
|
||||
future::join(alice.wait_for_blocks(2), bob.wait_for_blocks(2)).await;
|
||||
|
||||
// export genesis state
|
||||
let genesis_state = crate::command::generate_genesis_state(para_id)
|
||||
let spec = crate::chain_spec::get_chain_spec(para_id);
|
||||
let genesis_state = crate::command::generate_genesis_state(&(Box::new(spec) as Box<_>))
|
||||
.unwrap()
|
||||
.encode();
|
||||
|
||||
|
||||
@@ -112,9 +112,6 @@ pub fn run_collator(
|
||||
if matches!(parachain_config.role, Role::Light) {
|
||||
return Err("Light client not supported!".into());
|
||||
}
|
||||
if matches!(polkadot_config.role, Role::Light) {
|
||||
return Err("Light client not supported!".into());
|
||||
}
|
||||
|
||||
let mut parachain_config = prepare_collator_config(parachain_config);
|
||||
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::{process::{Child, ExitStatus}, thread, time::Duration};
|
||||
use std::{
|
||||
process::{Child, ExitStatus},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
/// Wait for the given `child` the given ammount of `secs`.
|
||||
///
|
||||
|
||||
@@ -22,17 +22,18 @@ mod common;
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn polkadot_argument_parsing() {
|
||||
use nix::sys::signal::{
|
||||
kill,
|
||||
Signal::{self, SIGINT, SIGTERM},
|
||||
use nix::{
|
||||
sys::signal::{
|
||||
kill,
|
||||
Signal::{self, SIGINT, SIGTERM},
|
||||
},
|
||||
unistd::Pid,
|
||||
};
|
||||
use nix::unistd::Pid;
|
||||
|
||||
fn run_command_and_kill(signal: Signal) {
|
||||
let _ = fs::remove_dir_all("polkadot_argument_parsing");
|
||||
let mut cmd = Command::new(cargo_bin("cumulus-test-parachain-collator"))
|
||||
.args(&[
|
||||
"--dev",
|
||||
"-d",
|
||||
"polkadot_argument_parsing",
|
||||
"--",
|
||||
|
||||
@@ -15,25 +15,33 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use assert_cmd::cargo::cargo_bin;
|
||||
use std::{convert::TryInto, process::Command, thread, time::Duration, fs};
|
||||
use std::{convert::TryInto, fs, process::Command, thread, time::Duration};
|
||||
|
||||
mod common;
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn interrupt_polkadot_mdns_issue_test() {
|
||||
use nix::sys::signal::{kill, Signal::{self, SIGINT, SIGTERM}};
|
||||
use nix::unistd::Pid;
|
||||
use nix::{
|
||||
sys::signal::{
|
||||
kill,
|
||||
Signal::{self, SIGINT, SIGTERM},
|
||||
},
|
||||
unistd::Pid,
|
||||
};
|
||||
|
||||
fn run_command_and_kill(signal: Signal) {
|
||||
let _ = fs::remove_dir_all("interrupt_polkadot_mdns_issue_test");
|
||||
let mut cmd = Command::new(cargo_bin("cumulus-test-parachain-collator"))
|
||||
.args(&["-d", "interrupt_polkadot_mdns_issue_test", "--dev", "--", "--dev"])
|
||||
.args(&["-d", "interrupt_polkadot_mdns_issue_test", "--", "--dev"])
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
thread::sleep(Duration::from_secs(20));
|
||||
assert!(cmd.try_wait().unwrap().is_none(), "the process should still be running");
|
||||
assert!(
|
||||
cmd.try_wait().unwrap().is_none(),
|
||||
"the process should still be running"
|
||||
);
|
||||
kill(Pid::from_raw(cmd.id().try_into().unwrap()), signal).unwrap();
|
||||
assert_eq!(
|
||||
common::wait_for(&mut cmd, 30).map(|x| x.success()),
|
||||
|
||||
@@ -15,31 +15,38 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use assert_cmd::cargo::cargo_bin;
|
||||
use std::{convert::TryInto, process::Command, thread, time::Duration, fs, path::PathBuf};
|
||||
use std::{convert::TryInto, fs, path::PathBuf, process::Command, thread, time::Duration};
|
||||
|
||||
mod common;
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn purge_chain_works() {
|
||||
use nix::sys::signal::{kill, Signal::SIGINT};
|
||||
use nix::unistd::Pid;
|
||||
use nix::{
|
||||
sys::signal::{kill, Signal::SIGINT},
|
||||
unistd::Pid,
|
||||
};
|
||||
|
||||
let base_path = "purge_chain_test";
|
||||
|
||||
let _ = fs::remove_dir_all(base_path);
|
||||
let mut cmd = Command::new(cargo_bin("cumulus-test-parachain-collator"))
|
||||
.args(&["-d", base_path, "--dev", "--", "--dev"])
|
||||
.args(&["-d", base_path, "--", "--dev"])
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
// Let it produce some blocks.
|
||||
thread::sleep(Duration::from_secs(30));
|
||||
assert!(cmd.try_wait().unwrap().is_none(), "the process should still be running");
|
||||
assert!(
|
||||
cmd.try_wait().unwrap().is_none(),
|
||||
"the process should still be running"
|
||||
);
|
||||
|
||||
// Stop the process
|
||||
kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap();
|
||||
assert!(common::wait_for(&mut cmd, 30).map(|x| x.success()).unwrap_or_default());
|
||||
assert!(common::wait_for(&mut cmd, 30)
|
||||
.map(|x| x.success())
|
||||
.unwrap_or_default());
|
||||
|
||||
let status = Command::new(cargo_bin("cumulus-test-parachain-collator"))
|
||||
.args(&["purge-chain", "-d", base_path, "-y"])
|
||||
@@ -48,6 +55,10 @@ fn purge_chain_works() {
|
||||
assert!(status.success());
|
||||
|
||||
// Make sure that the `parachain_local_testnet` chain folder exists, but the `db` is deleted.
|
||||
assert!(PathBuf::from(base_path).join("chains/local_testnet/").exists());
|
||||
assert!(!PathBuf::from(base_path).join("chains/local_testnet/db").exists());
|
||||
assert!(PathBuf::from(base_path)
|
||||
.join("chains/local_testnet/")
|
||||
.exists());
|
||||
assert!(!PathBuf::from(base_path)
|
||||
.join("chains/local_testnet/db")
|
||||
.exists());
|
||||
}
|
||||
|
||||
@@ -15,25 +15,33 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use assert_cmd::cargo::cargo_bin;
|
||||
use std::{convert::TryInto, process::Command, thread, time::Duration, fs};
|
||||
use std::{convert::TryInto, fs, process::Command, thread, time::Duration};
|
||||
|
||||
mod common;
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn running_the_node_works_and_can_be_interrupted() {
|
||||
use nix::sys::signal::{kill, Signal::{self, SIGINT, SIGTERM}};
|
||||
use nix::unistd::Pid;
|
||||
use nix::{
|
||||
sys::signal::{
|
||||
kill,
|
||||
Signal::{self, SIGINT, SIGTERM},
|
||||
},
|
||||
unistd::Pid,
|
||||
};
|
||||
|
||||
fn run_command_and_kill(signal: Signal) {
|
||||
let _ = fs::remove_dir_all("interrupt_test");
|
||||
let mut cmd = Command::new(cargo_bin("cumulus-test-parachain-collator"))
|
||||
.args(&["--dev", "-d", "interrupt_test", "--", "--dev"])
|
||||
.args(&["-d", "interrupt_test", "--", "--dev"])
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
thread::sleep(Duration::from_secs(30));
|
||||
assert!(cmd.try_wait().unwrap().is_none(), "the process should still be running");
|
||||
assert!(
|
||||
cmd.try_wait().unwrap().is_none(),
|
||||
"the process should still be running"
|
||||
);
|
||||
kill(Pid::from_raw(cmd.id().try_into().unwrap()), signal).unwrap();
|
||||
assert_eq!(
|
||||
common::wait_for(&mut cmd, 30).map(|x| x.success()),
|
||||
|
||||
Reference in New Issue
Block a user