Add Collectives Parachain (#1346)

* add new runtime and remove unnecessary pallets

* make runtime build

* add collectives to collator node

* sketch alliance config in runtime

* Slash handler was supposed to be commented out (for now)

* correct signature

* move to impls

* add alliance to runtime

* rustfmt

* IsReserve, remove Ping, update fn deposit

* add transaction_payment event

* Update parachains/runtimes/collectives/collectives-polkadot/src/lib.rs

Co-authored-by: Squirrel <gilescope@gmail.com>

* fmt

* add genesis config to chain spec

* fix merge

* local and dev configs only (for now)

* remove duplicate imports

* Collectives polkadot runtime to cargo workspace members (#1397)

* Collectives polkadot runtime: use unit type impl for identity verifier (#1398)

* apply fn rename

* fmt

* one less todo

* Less code in magic macros (#1407)

* Less code in magic macros

* cargo fmt

* Bench alliance (#1427)

* add benchmarks

* call one script from the other

* shebang changes so works on nixos too.

* bench in parallel as separate jobs

* hyphens can turn into underscores

* remove workaround to trigger bench

Co-authored-by: alvicsam <alvicsam@gmail.com>
Co-authored-by: paritytech-ci <paritytech-ci@parity.io>

* enable ci jobs

* fix publish bench results jobs

* chainspecs for collectives-westend (#1441)

* initial chainspecs for collections relay chain

* plumb in the collectives-westend chainspec

* add Runtime::CollectivesWestend

* lock

* Collectives: teleport slashed assets  (#1433)

* Collectives: teleport slashed assets

* fmt

* Cargo.lock > polkadot-parachain 0.9.25

* create temp account for imbalance

* treasury acc id from pallet id

* move accounts into constants, use here junction for assets

* assets location is relay chain, accounts as parameters

* fix typos

* fix typo

* Update parachains/runtimes/collectives/collectives-polkadot/src/constants.rs

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

* Move alliance proposal provider to impls.rs (#1464)

* Move to impls alliance proposal provider

* rustfmt

* Bumping spec version

(so that we can redeploy with slashing change.)

* cargo lock

* slurp collectives digest to make appear in release notes (#1473)

* add slurp

* Slurp better :)

* Bring some order

Co-authored-by: Chevdor <chevdor@users.noreply.github.com>
Co-authored-by: Wilfried Kopp <wilfried@parity.io>

* reorder barrier

* Update parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* address review

* clean construct runtime

* fmt

* looks pretty but brings in too much

Co-authored-by: Squirrel <gilescope@gmail.com>
Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>
Co-authored-by: alvicsam <alvicsam@gmail.com>
Co-authored-by: paritytech-ci <paritytech-ci@parity.io>
Co-authored-by: Chevdor <chevdor@users.noreply.github.com>
Co-authored-by: Wilfried Kopp <wilfried@parity.io>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
joe petrowski
2022-08-11 13:11:10 +02:00
committed by GitHub
parent 7ca3562665
commit 7bd426f31e
37 changed files with 3420 additions and 128 deletions
@@ -0,0 +1,179 @@
// Copyright 2022 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, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION,
};
use cumulus_primitives_core::ParaId;
use parachains_common::Balance as CollectivesBalance;
use rococo_parachain_runtime::{AccountId, AuraId};
use sc_service::ChainType;
use sp_core::sr25519;
pub type CollectivesPolkadotChainSpec =
sc_service::GenericChainSpec<collectives_polkadot_runtime::GenesisConfig, Extensions>;
const COLLECTIVES_POLKADOT_ED: CollectivesBalance =
collectives_polkadot_runtime::constants::currency::EXISTENTIAL_DEPOSIT;
/// 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 collectives_polkadot_session_keys(
keys: AuraId,
) -> collectives_polkadot_runtime::SessionKeys {
collectives_polkadot_runtime::SessionKeys { aura: keys }
}
pub fn collectives_polkadot_development_config() -> CollectivesPolkadotChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 0.into());
properties.insert("tokenSymbol".into(), "DOT".into());
properties.insert("tokenDecimals".into(), 10.into());
CollectivesPolkadotChainSpec::from_genesis(
// Name
"Polkadot Collectives Development",
// ID
"collectives_polkadot_dev",
ChainType::Local,
move || {
collectives_polkadot_genesis(
// initial collators.
vec![(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed::<AuraId>("Alice"),
)],
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
],
// 1002 avoids a potential collision with Kusama-1001 (Encointer) should there ever
// be a collective para on Kusama.
1002.into(),
)
},
Vec::new(),
None,
None,
None,
Some(properties),
Extensions { relay_chain: "polkadot-dev".into(), para_id: 1002 },
)
}
/// Collectives Polkadot Local Config.
pub fn collectives_polkadot_local_config() -> CollectivesPolkadotChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 0.into());
properties.insert("tokenSymbol".into(), "DOT".into());
properties.insert("tokenDecimals".into(), 10.into());
CollectivesPolkadotChainSpec::from_genesis(
// Name
"Polkadot Collectives Local",
// ID
"collectives_polkadot_local",
ChainType::Local,
move || {
collectives_polkadot_genesis(
// initial collators.
vec![
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed::<AuraId>("Alice"),
),
(
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_collator_keys_from_seed::<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"),
],
1002.into(),
)
},
Vec::new(),
None,
None,
None,
Some(properties),
Extensions { relay_chain: "polkadot-local".into(), para_id: 1002 },
)
}
fn collectives_polkadot_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> collectives_polkadot_runtime::GenesisConfig {
collectives_polkadot_runtime::GenesisConfig {
system: collectives_polkadot_runtime::SystemConfig {
code: collectives_polkadot_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
},
balances: collectives_polkadot_runtime::BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, COLLECTIVES_POLKADOT_ED * 4096))
.collect(),
},
parachain_info: collectives_polkadot_runtime::ParachainInfoConfig { parachain_id: id },
collator_selection: collectives_polkadot_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: COLLECTIVES_POLKADOT_ED * 16,
..Default::default()
},
session: collectives_polkadot_runtime::SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
collectives_polkadot_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: collectives_polkadot_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
},
alliance: Default::default(),
alliance_motion: Default::default(),
}
}
@@ -23,6 +23,7 @@ use serde::{Deserialize, Serialize};
use sp_core::{crypto::UncheckedInto, sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
pub mod collectives;
pub mod contracts;
pub mod penpal;
pub mod seedling;
@@ -1,4 +1,4 @@
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
// Copyright 2019-2022 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus is free software: you can redistribute it and/or modify
+82 -13
View File
@@ -14,6 +14,14 @@
// 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,
cli::{Cli, RelayChainCli, Subcommand},
service::{
new_partial, Block, CollectivesPolkadotRuntimeExecutor, ShellRuntimeExecutor,
StatemineRuntimeExecutor, StatemintRuntimeExecutor, WestmintRuntimeExecutor,
},
};
use codec::Encode;
use cumulus_client_cli::generate_genesis_block;
use cumulus_primitives_core::ParaId;
@@ -32,15 +40,7 @@ use sp_core::hexdisplay::HexDisplay;
use sp_runtime::traits::{AccountIdConversion, Block as BlockT};
use std::net::SocketAddr;
use crate::{
chain_spec,
cli::{Cli, RelayChainCli, Subcommand},
service::{
new_partial, Block, ShellRuntimeExecutor, StatemineRuntimeExecutor,
StatemintRuntimeExecutor, WestmintRuntimeExecutor,
},
};
#[derive(Debug)]
enum Runtime {
/// This is the default runtime (based on rococo)
Generic,
@@ -51,6 +51,8 @@ enum Runtime {
Westmint,
Penpal(ParaId),
ContractsRococo,
CollectivesPolkadot,
CollectivesWestend,
}
trait ChainType {
@@ -73,7 +75,9 @@ impl ChainType
}
fn runtime(id: &str) -> Runtime {
let (_, id, para_id) = extract_parachain_id(id);
let id = id.replace("_", "-");
let (_, id, para_id) = extract_parachain_id(&id);
if id.starts_with("shell") {
Runtime::Shell
} else if id.starts_with("seedling") {
@@ -88,6 +92,10 @@ fn runtime(id: &str) -> Runtime {
Runtime::Penpal(para_id.unwrap_or(ParaId::new(0)))
} else if id.starts_with("contracts-rococo") {
Runtime::ContractsRococo
} else if id.starts_with("collectives-polkadot") {
Runtime::CollectivesPolkadot
} else if id.starts_with("collectives-westend") {
Runtime::CollectivesWestend
} else {
Runtime::Generic
}
@@ -117,6 +125,7 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
"statemint" => Box::new(chain_spec::ChainSpec::from_json_bytes(
&include_bytes!("../../parachains/chain-specs/statemint.json")[..],
)?),
// -- Statemine
"statemine-dev" => Box::new(chain_spec::statemint::statemine_development_config()),
"statemine-local" => Box::new(chain_spec::statemint::statemine_local_config()),
@@ -126,6 +135,7 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
"statemine" => Box::new(chain_spec::ChainSpec::from_json_bytes(
&include_bytes!("../../parachains/chain-specs/statemine.json")[..],
)?),
// -- Westmint
"westmint-dev" => Box::new(chain_spec::statemint::westmint_development_config()),
"westmint-local" => Box::new(chain_spec::statemint::westmint_local_config()),
@@ -135,6 +145,19 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
"westmint" => Box::new(chain_spec::ChainSpec::from_json_bytes(
&include_bytes!("../../parachains/chain-specs/westmint.json")[..],
)?),
// -- Polkadot Collectives
"collectives-polkadot-dev" =>
Box::new(chain_spec::collectives::collectives_polkadot_development_config()),
"collectives-polkadot-local" =>
Box::new(chain_spec::collectives::collectives_polkadot_local_config()),
"collectives-polkadot" => Box::new(chain_spec::ChainSpec::from_json_bytes(
&include_bytes!("../../parachains/chain-specs/collectives-polkadot.json")[..],
)?),
"collectives-westend" => Box::new(chain_spec::ChainSpec::from_json_bytes(
&include_bytes!("../../parachains/chain-specs/collectives-westend.json")[..],
)?),
// -- Contracts on Rococo
"contracts-rococo-dev" =>
Box::new(chain_spec::contracts::contracts_rococo_development_config()),
@@ -144,8 +167,6 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
"contracts-rococo" => Box::new(chain_spec::ChainSpec::from_json_bytes(
&include_bytes!("../../parachains/chain-specs/contracts-rococo.json")[..],
)?),
// -- 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",
@@ -154,6 +175,10 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
para_id.expect("Must specify parachain id"),
"polkadot-local",
)),
// -- Fallback (generic chainspec)
"" => Box::new(chain_spec::get_chain_spec()),
// -- Loading a specific spec from disk
path => {
let chain_spec = chain_spec::ChainSpec::from_json_file(path.into())?;
@@ -166,6 +191,10 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
),
Runtime::Westmint =>
Box::new(chain_spec::statemint::WestmintChainSpec::from_json_file(path.into())?),
Runtime::CollectivesPolkadot | Runtime::CollectivesWestend =>
Box::new(chain_spec::collectives::CollectivesPolkadotChainSpec::from_json_file(
path.into(),
)?),
Runtime::Shell =>
Box::new(chain_spec::shell::ShellChainSpec::from_json_file(path.into())?),
Runtime::Seedling =>
@@ -243,6 +272,8 @@ impl SubstrateCli for Cli {
Runtime::Statemint => &statemint_runtime::VERSION,
Runtime::Statemine => &statemine_runtime::VERSION,
Runtime::Westmint => &westmint_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,
@@ -317,6 +348,13 @@ macro_rules! construct_benchmark_partials {
)?;
$code
},
Runtime::CollectivesPolkadot | Runtime::CollectivesWestend => {
let $partials = new_partial::<collectives_polkadot_runtime::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
$code
},
_ => Err("The chain is not supported".into()),
}
};
@@ -356,6 +394,16 @@ macro_rules! construct_async_run {
{ $( $code )* }.map(|v| (v, task_manager))
})
},
Runtime::CollectivesPolkadot | Runtime::CollectivesWestend => {
runner.async_run(|$config| {
let $components = new_partial::<collectives_polkadot_runtime::RuntimeApi, _>(
&$config,
crate::service::aura_build_import_queue::<_, AuraId>,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
},
Runtime::Shell => {
runner.async_run(|$config| {
let $components = new_partial::<shell_runtime::RuntimeApi, _>(
@@ -482,7 +530,13 @@ pub fn run() -> Result<()> {
Runtime::Westmint => cmd.run::<Block, WestmintRuntimeExecutor>(config),
Runtime::Statemint =>
cmd.run::<Block, StatemintRuntimeExecutor>(config),
_ => Err("Chain doesn't support benchmarking".into()),
Runtime::CollectivesPolkadot | Runtime::CollectivesWestend =>
cmd.run::<Block, CollectivesPolkadotRuntimeExecutor>(config),
_ => Err(format!(
"Chain '{:?}' doesn't support benchmarking",
config.chain_spec.runtime()
)
.into()),
})
} else {
Err("Benchmarking wasn't enabled when building the node. \
@@ -527,6 +581,13 @@ pub fn run() -> Result<()> {
Runtime::Statemint => runner.async_run(|config| {
Ok((cmd.run::<Block, StatemintRuntimeExecutor>(config), task_manager))
}),
Runtime::CollectivesPolkadot | Runtime::CollectivesWestend =>
runner.async_run(|config| {
Ok((
cmd.run::<Block, CollectivesPolkadotRuntimeExecutor>(config),
task_manager,
))
}),
Runtime::Shell => runner.async_run(|config| {
Ok((cmd.run::<Block, ShellRuntimeExecutor>(config), task_manager))
}),
@@ -604,6 +665,14 @@ pub fn run() -> Result<()> {
.await
.map(|r| r.0)
.map_err(Into::into),
Runtime::CollectivesPolkadot | Runtime::CollectivesWestend =>
crate::service::start_generic_aura_node::<
collectives_polkadot_runtime::RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await
.map(|r| r.0)
.map_err(Into::into),
Runtime::Shell =>
crate::service::start_shell_node::<shell_runtime::RuntimeApi>(
config,
+15
View File
@@ -159,6 +159,21 @@ impl sc_executor::NativeExecutionDispatch for WestmintRuntimeExecutor {
}
}
// Native Polkadot Collectives executor instance.
pub struct CollectivesPolkadotRuntimeExecutor;
impl sc_executor::NativeExecutionDispatch for CollectivesPolkadotRuntimeExecutor {
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
collectives_polkadot_runtime::api::dispatch(method, data)
}
fn native_version() -> sc_executor::NativeVersion {
collectives_polkadot_runtime::native_version()
}
}
/// Native Contracts on Rococo executor instance.
pub struct ContractsRococoRuntimeExecutor;