mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 17:31:03 +00:00
Penpal testing runtime (#1254)
* adapt to common good paras * fmt * Updated to leave parachain-template alone * use norm_id + cargo fmt * removed comment as we are not touching parachain template * is_penpal * updated code to new locations * changes required to get penpal running * cargo fmt * remove warning, rename chain * Update polkadot-parachain/src/command.rs * Update polkadot-parachain/src/command.rs Co-authored-by: Ignacio Palacios <ignacio.palacios.santos@gmail.com> * remove now moved functions * added runtime description * add missing copyright notices * more copyright notices. Co-authored-by: NachoPal <ignacio.palacios.santos@gmail.com>
This commit is contained in:
@@ -23,6 +23,7 @@ statemint-runtime = { path = "../parachains/runtimes/assets/statemint" }
|
||||
statemine-runtime = { path = "../parachains/runtimes/assets/statemine" }
|
||||
westmint-runtime = { path = "../parachains/runtimes/assets/westmint" }
|
||||
contracts-rococo-runtime = { path = "../parachains/runtimes/contracts/contracts-rococo" }
|
||||
penpal-runtime = { path = "../parachains/runtimes/testing/penpal" }
|
||||
jsonrpsee = { version = "0.14.0", features = ["server"] }
|
||||
parachains-common = { path = "../parachains/common" }
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ use sp_core::{crypto::UncheckedInto, sr25519, Pair, Public};
|
||||
use sp_runtime::traits::{IdentifyAccount, Verify};
|
||||
|
||||
pub mod contracts;
|
||||
pub mod penpal;
|
||||
pub mod seedling;
|
||||
pub mod shell;
|
||||
pub mod statemint;
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Cumulus.
|
||||
|
||||
// Cumulus is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Cumulus is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// 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::{get_account_id_from_seed, Extensions};
|
||||
use cumulus_primitives_core::ParaId;
|
||||
// use rococo_parachain_runtime::{AuraId};
|
||||
use crate::chain_spec::{get_collator_keys_from_seed, SAFE_XCM_VERSION};
|
||||
use sc_service::ChainType;
|
||||
use sp_core::sr25519;
|
||||
/// Specialized `ChainSpec` for the normal parachain runtime.
|
||||
pub type PenpalChainSpec = sc_service::GenericChainSpec<penpal_runtime::GenesisConfig, Extensions>;
|
||||
|
||||
pub fn get_penpal_chain_spec(id: ParaId, relay_chain: &str) -> PenpalChainSpec {
|
||||
// Give your base currency a unit name and decimal places
|
||||
let mut properties = sc_chain_spec::Properties::new();
|
||||
properties.insert("tokenSymbol".into(), "UNIT".into());
|
||||
properties.insert("tokenDecimals".into(), 12u32.into());
|
||||
properties.insert("ss58Format".into(), 42u32.into());
|
||||
|
||||
PenpalChainSpec::from_genesis(
|
||||
// Name
|
||||
"Penpal Parachain",
|
||||
// ID
|
||||
&format!("penpal-{}", relay_chain.replace("-local", "")),
|
||||
ChainType::Development,
|
||||
move || {
|
||||
penpal_testnet_genesis(
|
||||
// initial collators.
|
||||
vec![
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed::<penpal_runtime::AuraId>("Alice"),
|
||||
),
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_collator_keys_from_seed::<penpal_runtime::AuraId>("Bob"),
|
||||
),
|
||||
],
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Charlie"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Dave"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Eve"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
|
||||
],
|
||||
id,
|
||||
)
|
||||
},
|
||||
Vec::new(),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Extensions {
|
||||
relay_chain: relay_chain.into(), // You MUST set this to the correct network!
|
||||
para_id: id.into(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn penpal_testnet_genesis(
|
||||
invulnerables: Vec<(penpal_runtime::AccountId, penpal_runtime::AuraId)>,
|
||||
endowed_accounts: Vec<penpal_runtime::AccountId>,
|
||||
id: ParaId,
|
||||
) -> penpal_runtime::GenesisConfig {
|
||||
penpal_runtime::GenesisConfig {
|
||||
system: penpal_runtime::SystemConfig {
|
||||
code: penpal_runtime::WASM_BINARY
|
||||
.expect("WASM binary was not build, please build it!")
|
||||
.to_vec(),
|
||||
},
|
||||
balances: penpal_runtime::BalancesConfig {
|
||||
balances: endowed_accounts
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|k| (k, penpal_runtime::EXISTENTIAL_DEPOSIT * 4096))
|
||||
.collect(),
|
||||
},
|
||||
parachain_info: penpal_runtime::ParachainInfoConfig { parachain_id: id },
|
||||
collator_selection: penpal_runtime::CollatorSelectionConfig {
|
||||
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
|
||||
candidacy_bond: penpal_runtime::EXISTENTIAL_DEPOSIT * 16,
|
||||
..Default::default()
|
||||
},
|
||||
session: penpal_runtime::SessionConfig {
|
||||
keys: invulnerables
|
||||
.into_iter()
|
||||
.map(|(acc, aura)| {
|
||||
(
|
||||
acc.clone(), // account id
|
||||
acc, // validator id
|
||||
penpal_session_keys(aura), // session keys
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
},
|
||||
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
|
||||
// of this.
|
||||
aura: Default::default(),
|
||||
aura_ext: Default::default(),
|
||||
parachain_system: Default::default(),
|
||||
polkadot_xcm: penpal_runtime::PolkadotXcmConfig {
|
||||
safe_xcm_version: Some(SAFE_XCM_VERSION),
|
||||
},
|
||||
sudo: penpal_runtime::SudoConfig {
|
||||
key: Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate the session keys from individual elements.
|
||||
///
|
||||
/// The input must be a tuple of individual keys (a single arg for now since we have just one key).
|
||||
pub fn penpal_session_keys(keys: penpal_runtime::AuraId) -> penpal_runtime::SessionKeys {
|
||||
penpal_runtime::SessionKeys { aura: keys }
|
||||
}
|
||||
@@ -14,8 +14,6 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use codec::Encode;
|
||||
use cumulus_client_cli::generate_genesis_block;
|
||||
use cumulus_primitives_core::ParaId;
|
||||
@@ -32,6 +30,7 @@ use sc_service::{
|
||||
};
|
||||
use sp_core::hexdisplay::HexDisplay;
|
||||
use sp_runtime::traits::{AccountIdConversion, Block as BlockT};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use crate::{
|
||||
chain_spec,
|
||||
@@ -50,6 +49,7 @@ enum Runtime {
|
||||
Statemint,
|
||||
Statemine,
|
||||
Westmint,
|
||||
Penpal(ParaId),
|
||||
ContractsRococo,
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ impl ChainType
|
||||
}
|
||||
|
||||
fn runtime(id: &str) -> Runtime {
|
||||
let (_, id, para_id) = extract_parachain_id(id);
|
||||
if id.starts_with("shell") {
|
||||
Runtime::Shell
|
||||
} else if id.starts_with("seedling") {
|
||||
@@ -83,6 +84,8 @@ fn runtime(id: &str) -> Runtime {
|
||||
Runtime::Statemine
|
||||
} else if id.starts_with("westmint") {
|
||||
Runtime::Westmint
|
||||
} else if id.starts_with("penpal") {
|
||||
Runtime::Penpal(para_id.unwrap_or(ParaId::new(0)))
|
||||
} else if id.starts_with("contracts-rococo") {
|
||||
Runtime::ContractsRococo
|
||||
} else {
|
||||
@@ -91,6 +94,7 @@ fn runtime(id: &str) -> Runtime {
|
||||
}
|
||||
|
||||
fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
|
||||
let (id, _, para_id) = extract_parachain_id(id);
|
||||
Ok(match id {
|
||||
"staging" => Box::new(chain_spec::staging_test_net()),
|
||||
"tick" => Box::new(chain_spec::ChainSpec::from_json_bytes(
|
||||
@@ -142,6 +146,14 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
|
||||
)?),
|
||||
// -- Fallback (generic chainspec)
|
||||
"" => Box::new(chain_spec::get_chain_spec()),
|
||||
"penpal-kusama" => Box::new(chain_spec::penpal::get_penpal_chain_spec(
|
||||
para_id.expect("Must specify parachain id"),
|
||||
"kusama-local",
|
||||
)),
|
||||
"penpal-polkadot" => Box::new(chain_spec::penpal::get_penpal_chain_spec(
|
||||
para_id.expect("Must specify parachain id"),
|
||||
"polkadot-local",
|
||||
)),
|
||||
// -- Loading a specific spec from disk
|
||||
path => {
|
||||
let chain_spec = chain_spec::ChainSpec::from_json_file(path.into())?;
|
||||
@@ -161,12 +173,36 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
|
||||
Runtime::ContractsRococo => Box::new(
|
||||
chain_spec::contracts::ContractsRococoChainSpec::from_json_file(path.into())?,
|
||||
),
|
||||
Runtime::Penpal(_para_id) =>
|
||||
Box::new(chain_spec::penpal::PenpalChainSpec::from_json_file(path.into())?),
|
||||
Runtime::Generic => Box::new(chain_spec),
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/// Extracts the normalized chain id and parachain id from the input chain id.
|
||||
/// (H/T to Phala for the idea)
|
||||
/// E.g. "penpal-kusama-2004" yields ("penpal-kusama", Some(2004))
|
||||
fn extract_parachain_id(id: &str) -> (&str, &str, Option<ParaId>) {
|
||||
const KUSAMA_TEST_PARA_PREFIX: &str = "penpal-kusama-";
|
||||
const POLKADOT_TEST_PARA_PREFIX: &str = "penpal-polkadot-";
|
||||
|
||||
let (norm_id, orig_id, para) = if id.starts_with(KUSAMA_TEST_PARA_PREFIX) {
|
||||
let suffix = &id[KUSAMA_TEST_PARA_PREFIX.len()..];
|
||||
let para_id: u32 = suffix.parse().expect("Invalid parachain-id suffix");
|
||||
(&id[..KUSAMA_TEST_PARA_PREFIX.len() - 1], id, Some(para_id))
|
||||
} else if id.starts_with(POLKADOT_TEST_PARA_PREFIX) {
|
||||
let suffix = &id[POLKADOT_TEST_PARA_PREFIX.len()..];
|
||||
let para_id: u32 = suffix.parse().expect("Invalid parachain-id suffix");
|
||||
(&id[..POLKADOT_TEST_PARA_PREFIX.len() - 1], id, Some(para_id))
|
||||
} else {
|
||||
(id, id, None)
|
||||
};
|
||||
|
||||
(norm_id, orig_id, para.map(Into::into))
|
||||
}
|
||||
|
||||
impl SubstrateCli for Cli {
|
||||
fn impl_name() -> String {
|
||||
"Polkadot parachain".into()
|
||||
@@ -210,6 +246,7 @@ impl SubstrateCli for Cli {
|
||||
Runtime::Shell => &shell_runtime::VERSION,
|
||||
Runtime::Seedling => &seedling_runtime::VERSION,
|
||||
Runtime::ContractsRococo => &contracts_rococo_runtime::VERSION,
|
||||
Runtime::Penpal(_) => &penpal_runtime::VERSION,
|
||||
Runtime::Generic => &rococo_parachain_runtime::VERSION,
|
||||
}
|
||||
}
|
||||
@@ -349,7 +386,7 @@ macro_rules! construct_async_run {
|
||||
{ $( $code )* }.map(|v| (v, task_manager))
|
||||
})
|
||||
},
|
||||
Runtime::Generic => {
|
||||
Runtime::Penpal(_) | Runtime::Generic => {
|
||||
runner.async_run(|$config| {
|
||||
let $components = new_partial::<
|
||||
rococo_parachain_runtime::RuntimeApi,
|
||||
@@ -591,16 +628,17 @@ pub fn run() -> Result<()> {
|
||||
.await
|
||||
.map(|r| r.0)
|
||||
.map_err(Into::into),
|
||||
Runtime::Generic => crate::service::start_rococo_parachain_node(
|
||||
config,
|
||||
polkadot_config,
|
||||
collator_options,
|
||||
id,
|
||||
hwbench,
|
||||
)
|
||||
.await
|
||||
.map(|r| r.0)
|
||||
.map_err(Into::into),
|
||||
Runtime::Penpal(_) | Runtime::Generic =>
|
||||
crate::service::start_rococo_parachain_node(
|
||||
config,
|
||||
polkadot_config,
|
||||
collator_options,
|
||||
id,
|
||||
hwbench,
|
||||
)
|
||||
.await
|
||||
.map(|r| r.0)
|
||||
.map_err(Into::into),
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user