Skip to content

Commit

Permalink
Update polkadot-sdk to stable2409 and cleanup workspace (#427)
Browse files Browse the repository at this point in the history
* change: remove `virto-xcm-emulator`

* fix(node): remove unused variables

* change(Cargo): update `polkadot-sdk` to `stable2409`

* change(Cargo/workspace): uniform manifest structure for workspace members

* change(pallet-communities): update to `stable2409`

- Construct mock runtime using v2 runtime macro.
- Use `AssetsFreezer` to handle assets-based vote locks.

* change(pallet-communities-manager): update to `stable2409`

- Upgrade `construct_runtime` to proc macro
- Update configuration for `pallet-communities`

* change(pallet-payments): update to `stable2409`

- Update `construct_runtime` to proc macro

* fix(runtime-kreivo): adjust `Contracts` parameters to meet integrity tests

* change(kreivo-runtime): update to `stable2409`

- Add `pallet-assets-freezer`
- Update `construct_runtime` to newer proc macro
- Adjust changes in pallets configurations

* feat: deprecate `node` in favour of `chain-spec-generator`

* change(ci): update justfile

* change(Cargo): remove unused dependencies

* fix(runtime-kreivo): make ci happy

* change: format root Cargo.toml
  • Loading branch information
pandres95 authored Oct 17, 2024
1 parent bd32ccf commit d627119
Show file tree
Hide file tree
Showing 47 changed files with 3,676 additions and 25,091 deletions.
10,394 changes: 2,555 additions & 7,839 deletions Cargo.lock

Large diffs are not rendered by default.

255 changes: 101 additions & 154 deletions Cargo.toml

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions chain-spec-generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
authors.workspace = true
description = "Chain Spec Generator for Kreivo"
edition.workspace = true
homepage.workspace = true
license.workspace = true
name = "chain-spec-generator"
repository.workspace = true
version = "0.13.3"

[dependencies]
clap = { workspace = true, features = ["derive"] }
serde_json.workspace = true
serde = { workspace = true, features = ["derive"] }

kreivo-runtime = { workspace = true, default-features = true }

cumulus-primitives-core.workspace = true
parachains-common.workspace = true
sp-core.workspace = true
sp-runtime.workspace = true
sc-chain-spec.workspace = true
sc-network.workspace = true
xcm.workspace = true

[features]
runtime-benchmarks = [
"kreivo-runtime/runtime-benchmarks"
]
paseo = [
"kreivo-runtime/paseo"
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ use serde::{Deserialize, Serialize};
use sp_core::{Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};

pub mod kreivo;
pub use kreivo::ChainSpec;

/// The default XCM version to set in genesis config.
const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;
pub const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;

/// The extensions for the [`ChainSpec`].
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
Expand All @@ -21,13 +18,6 @@ pub struct Extensions {
pub para_id: u32,
}

impl Extensions {
/// Try to get the extension from the given `ChainSpec`.
pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> {
sc_chain_spec::get_extension(chain_spec.extensions())
}
}

/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
Expand Down
47 changes: 47 additions & 0 deletions chain-spec-generator/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use clap::Parser;
use sc_chain_spec::ChainSpec;
use std::collections::HashMap;

mod common;
mod spec;

use spec::live;
use spec::local;
use spec::KreivoChainSpec;

#[derive(Parser)]
struct Cli {
/// The chain spec to generate.
chain: String,

/// Generate the chain spec as raw?
#[arg(long)]
raw: bool,
}

fn main() -> Result<(), String> {
let cli = Cli::parse();

let supported_chains = HashMap::<_, Box<dyn Fn() -> Result<Box<dyn ChainSpec>, String>>>::from([
("kreivo", Box::new(live::chain_spec) as Box<_>),
("kreivo-local", Box::new(local::chain_spec) as Box<_>),
]);

if let Some(function) = supported_chains.get(&*cli.chain) {
let chain_spec = (*function)()?.as_json(cli.raw)?;
print!("{chain_spec}");
Ok(())
} else {
let supported = supported_chains.keys().enumerate().fold(String::new(), |c, (n, k)| {
let extra = if n + 1 < supported_chains.len() { ", " } else { "" };
format!("{c}{k}{extra}")
});
if cli.chain.ends_with(".json") {
let chain_spec = Box::new(KreivoChainSpec::from_json_file(cli.chain.into())?.as_json(cli.raw)?);
print!("{chain_spec}");
Ok(())
} else {
Err(format!("Unknown chain, only supported: {supported} or a json file"))
}
}
}
17 changes: 17 additions & 0 deletions chain-spec-generator/src/spec/live/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use super::*;

#[cfg(not(feature = "paseo"))]
pub fn chain_spec() -> Result<Box<dyn ChainSpec>, String> {
Ok(Box::new(
KreivoChainSpec::from_json_bytes(include_bytes!("./kreivo_kusama_chainspec.json").as_slice())
.map_err(|_| "Could not find chainspec for kreivo")?,
))
}

#[cfg(feature = "paseo")]
pub fn chain_spec() -> Result<Box<dyn ChainSpec>, String> {
Ok(Box::new(
KreivoChainSpec::from_json_bytes(include_bytes!("./kreivo_paseador_chainspec.json").as_slice())
.map_err(|_| "Could not find chainspec for kreivo")?,
))
}
162 changes: 162 additions & 0 deletions chain-spec-generator/src/spec/local.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
use super::*;

#[cfg(not(feature = "paseo"))]
pub fn chain_spec() -> Result<Box<dyn ChainSpec>, String> {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "KSM".into());
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("ss58Format".into(), 2.into());

Ok(Box::new(
KreivoChainSpec::builder(
kreivo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions {
relay_chain: "kusama-local".into(),
// You MUST set this to the correct network!
para_id: KREIVO_PARA_ID,
},
)
.with_name("Kreivo-Kusama Local")
.with_id("kreivo_kusama_local")
.with_chain_type(ChainType::Local)
.with_properties(properties)
.with_genesis_config_patch(local_genesis(
KREIVO_PARA_ID.into(),
// initial collators.
vec![
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed("Alice"),
),
(
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_collator_keys_from_seed("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"),
],
))
.build(),
))
}

#[cfg(feature = "paseo")]
pub fn chain_spec() -> Result<Box<dyn ChainSpec>, String> {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "PAS".into());
properties.insert("tokenDecimals".into(), 10.into());
properties.insert("ss58Format".into(), 1.into());

Ok(Box::new(
KreivoChainSpec::builder(
kreivo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions {
relay_chain: "paseo-local".into(),
// You MUST set this to the correct network!
para_id: KREIVO_PARA_ID,
},
)
.with_name("Kreivo de Paseo-Local")
.with_id("kreivo_paseo_local")
.with_chain_type(ChainType::Local)
.with_properties(properties)
.with_genesis_config_patch(local_genesis(
KREIVO_PARA_ID.into(),
// initial collators.
vec![
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed("Alice"),
),
(
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_collator_keys_from_seed("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"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
))
.build(),
))
}

fn local_genesis(
id: ParaId,
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
#[cfg(feature = "paseo")] sudo: AccountId,
) -> serde_json::Value {
let mut config = serde_json::json!({}).as_object().expect("map given; qed").clone();

#[cfg(feature = "paseo")]
config.insert("sudo".into(), serde_json::json!({ "key": sudo }));
config.insert(
"balances".into(),
serde_json::json!({
"balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::<Vec<_>>()
}),
);
config.insert(
"parachainInfo".into(),
serde_json::json!({
"parachainId": id,
}),
);
config.insert(
"collatorSelection".into(),
serde_json::json!({
"invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::<Vec<_>>(),
"candidacyBond": EXISTENTIAL_DEPOSIT * 16,
}),
);
config.insert(
"session".into(),
serde_json::json!({
"keys": invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
session_keys(aura), // session keys
)
})
.collect::<Vec<_>>(),
}),
);
config.insert(
"polkadotXcm".into(),
serde_json::json!({
"safeXcmVersion": Some(SAFE_XCM_VERSION),
}),
);

config.into()
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION};
use crate::common::{get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION};
use cumulus_primitives_core::ParaId;

use kreivo_runtime::{constants::currency::EXISTENTIAL_DEPOSIT, AccountId, AuraId, SessionKeys};
use sc_service::ChainType;
use sc_chain_spec::{ChainSpec, ChainType};
use sp_core::sr25519;

const DEFAULT_PROTOCOL_ID: &str = "kreivo";

#[cfg(feature = "paseo")]
const KREIVO_PARA_ID: u32 = 2281;
#[cfg(not(feature = "paseo"))]
const KREIVO_PARA_ID: u32 = 2281;

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec = sc_service::GenericChainSpec<Extensions>;
pub type KreivoChainSpec = sc_chain_spec::GenericChainSpec<Extensions>;

/// Generate the session keys from individual elements.
///
Expand Down
Loading

0 comments on commit d627119

Please sign in to comment.