Skip to content

Commit

Permalink
Replace deprecated types and consolidate development testnets (#842)
Browse files Browse the repository at this point in the history
* Replace deprecated type with `FungibleAdapter`
* Remove deprecated function `from_genesis()`
* Code cleanup
* Combine dev and local testnets to one config
  • Loading branch information
simonsso authored Mar 25, 2024
1 parent a4f6c42 commit c9d23dd
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 242 deletions.
238 changes: 123 additions & 115 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ sp-core = { version = "28.0.0", default-features = false }
sp-inherents = { version = "26.0.0", default-features = false }
sp-io = { version = "30.0.0", default-features = false }
sp-keystore = { version = "0.34.0", default-features = false }
sp-genesis-builder = { version = "0.7.0", default-features = false}
sp-npos-elections = { version = "26.0.0", default-features = false }
sp-offchain = { version = "26.0.0", default-features = false }
sp-runtime = { version = "31.0.0", default-features = false }
Expand Down Expand Up @@ -138,5 +139,6 @@ log = { version = "0.4.17", default-features = false }
safe-mix = { version = "1.0.1", default-features = false }
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.152", default-features = false }
serde_json = { version = "1.0.104", default-features = false }
static_assertions = "1.1.0"
smallvec = "1.9.0"
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ derive_more.workspace = true
log = { workspace = true, default-features = true}
codec.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true

# RPC related Dependencies
jsonrpsee = { workspace = true, features = ["server"] }
Expand Down
152 changes: 30 additions & 122 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ use cumulus_primitives_core::ParaId;
use primitives::{AccountId, Balance, Signature};
use runtime_eden::{
constants::{EXISTENTIAL_DEPOSIT, NODL},
AuraId, BalancesConfig, CollatorSelectionConfig, ParachainInfoConfig, PolkadotXcmConfig, RuntimeGenesisConfig,
SessionConfig, SessionKeys, SystemConfig, TechnicalMembershipConfig, WASM_BINARY,
AuraId, RuntimeGenesisConfig, SessionKeys, 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::{
bounded_vec,
traits::{IdentifyAccount, Verify},
};
use sp_runtime::traits::{IdentifyAccount, Verify};
const SAFE_XCM_VERSION: u32 = xcm::latest::VERSION;

/// Specialized `ChainSpec` for the normal parachain runtime.
Expand Down Expand Up @@ -93,7 +89,7 @@ fn eden_testnet_genesis(
collators: Vec<(AccountId, AuraId)>,
endowed_accounts: Option<Vec<AccountId>>,
id: ParaId,
) -> RuntimeGenesisConfig {
) -> serde_json::Value {
let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(|| {
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
Expand All @@ -111,24 +107,17 @@ fn eden_testnet_genesis(

const ENDOWMENT: Balance = 10_000 * NODL;

RuntimeGenesisConfig {
// Core
system: SystemConfig {
_config: Default::default(),
},
balances: BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, ENDOWMENT)).collect(),
serde_json::json!({
"balances": {
"balances": endowed_accounts.iter().cloned().map(|k| (k, ENDOWMENT)).collect::<Vec<_>>(),
},
vesting: Default::default(),

// Consensus
collator_selection: CollatorSelectionConfig {
invulnerables: collators.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
..Default::default()
"collatorSelection": {
"invulnerables": collators.iter().cloned().map(|(acc, _)| acc).collect::<Vec<_>>(),
"candidacyBond": EXISTENTIAL_DEPOSIT * 16,
"desiredCandidates": 0
},
session: SessionConfig {
keys: collators
"session": {
"keys": collators
.into_iter()
.map(|(acc, aura)| {
(
Expand All @@ -137,41 +126,21 @@ fn eden_testnet_genesis(
eden_session_keys(aura), // session keys
)
})
.collect(),
.collect::<Vec<_>>(),
},
aura: Default::default(),
aura_ext: Default::default(),
parachain_system: Default::default(),
parachain_info: ParachainInfoConfig {
parachain_id: id,
_config: Default::default(),
"parachainInfo": {
"parachainId": id,
},
transaction_payment: Default::default(),

// Governance
company_reserve: Default::default(),
international_reserve: Default::default(),
usa_reserve: Default::default(),
technical_committee: Default::default(),
technical_membership: TechnicalMembershipConfig {
members: bounded_vec![root_key],
phantom: Default::default(),
"technicalMembership": {
"members": vec![root_key],
},

// Allocations
allocations_oracles: Default::default(),

// DAO
dao_reserve: Default::default(),

polkadot_xcm: PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
_config: Default::default(),
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
}
})
}

fn development_config_genesis(id: ParaId) -> RuntimeGenesisConfig {
fn development_config_genesis(id: ParaId) -> serde_json::Value {
eden_testnet_genesis(
get_account_id_from_seed::<sr25519::Public>("Alice"),
vec![
Expand All @@ -192,79 +161,23 @@ fn development_config_genesis(id: ParaId) -> RuntimeGenesisConfig {
pub fn development_config(id: ParaId) -> ChainSpec {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "NODL".into());
properties.insert("tokenSymbol".into(), "DevNODL".into());
properties.insert("tokenDecimals".into(), 11.into());
properties.insert("ss58Format".into(), 42.into());

ChainSpec::from_genesis(
// Name
"Parachain Eden Development",
// ID
"para_eden_dev",
ChainType::Development,
move || development_config_genesis(id),
Vec::new(),
None,
None,
None,
None,
Extensions {
relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
para_id: id.into(),
},
ChainSpec::builder(
WASM_BINARY.expect("WASM binary was not build, please build it!"),
)
}

fn local_config_genesis(id: ParaId) -> RuntimeGenesisConfig {
eden_testnet_genesis(
get_account_id_from_seed::<sr25519::Public>("Alice"),
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"),
),
],
None,
id,
)
}

pub fn local_testnet_config(id: ParaId) -> ChainSpec {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "NODL".into());
properties.insert("tokenDecimals".into(), 11.into());
properties.insert("ss58Format".into(), 42.into());

ChainSpec::from_genesis(
// Name
"Eden Local Testnet",
// ID
"para_eden_local",
ChainType::Local,
move || local_config_genesis(id),
// Bootnodes
Vec::new(),
// Telemetry
None,
// Protocol ID
Some("eden-local"),
// Fork ID
None,
// Properties
Some(properties),
// Extensions
Extensions {
relay_chain: "westend".into(), // You MUST set this to the correct network!
relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
para_id: id.into(),
},
WASM_BINARY.expect("WASM binary was not build, please build it!"),
)
.with_name("Parachain Eden Development")
.with_id("para_eden_dev")
.with_chain_type(ChainType::Development)
.with_properties(properties)
.with_genesis_config_patch(development_config_genesis(id))
.build()
}

pub fn production_config() -> ChainSpec {
Expand All @@ -288,11 +201,6 @@ pub(crate) mod tests {
assert!(development_config(ParaId::from(1000u32)).build_storage().is_ok());
}

#[test]
fn create_local_chain_spec() {
assert!(local_testnet_config(ParaId::from(1000u32)).build_storage().is_ok());
}

#[test]
fn create_production_spec() {
assert!(production_config().build_storage().is_ok());
Expand Down
3 changes: 1 addition & 2 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ const DEFAULT_PARA_ID: u32 = 2026;

fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"eden-dev" | "dev" => Box::new(chain_spec::development_config(DEFAULT_PARA_ID.into())),
"eden-local" | "local" => Box::new(chain_spec::local_testnet_config(DEFAULT_PARA_ID.into())),
"eden-local" | "local" | "eden-dev" | "dev" => Box::new(chain_spec::development_config(DEFAULT_PARA_ID.into())),
"eden-testing" | "testing" | "test" | "paradis" => Box::new(chain_spec::testing_config()),
"eden" | "production" | "main" | "" => Box::new(chain_spec::production_config()),
path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
Expand Down
2 changes: 2 additions & 0 deletions runtimes/eden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ std = [
"sp-io/std",
"sp-offchain/std",
"sp-runtime/std",
"sp-genesis-builder/std",
"sp-storage/std",
"sp-session/std",
"sp-staking/std",
Expand Down Expand Up @@ -242,6 +243,7 @@ sp-transaction-pool = { workspace = true, default-features = false }
sp-version = { workspace = true, default-features = false }
sp-npos-elections = { workspace = true, default-features = false }
sp-consensus-aura = { workspace = true, default-features = false }
sp-genesis-builder.workspace = true
frame-try-runtime = { workspace = true, default-features = false, optional = true }
primitives = { default-features = false, path = "../../primitives" }
pallet-allocations = { default-features = false, path = "../../pallets/allocations" }
Expand Down
16 changes: 15 additions & 1 deletion runtimes/eden/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ pub fn wasm_binary_unwrap() -> &'static [u8] {
}

use constants::RuntimeBlockWeights;
use frame_support::{construct_runtime, weights::Weight};
use frame_support::{
construct_runtime,
genesis_builder_helper::{build_config, create_default_config},
weights::Weight,
};
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
use primitives::{AccountId, Balance, BlockNumber, Hash, Nonce, Signature};
pub use primitives::{AuraId, ParaId};
Expand Down Expand Up @@ -213,6 +217,16 @@ pub type XcmFungibleBenchmarks = pallet_xcm_benchmarks::fungible::Pallet<Runtime
type EventRecord =
frame_system::EventRecord<<Runtime as frame_system::Config>::RuntimeEvent, <Runtime as frame_system::Config>::Hash>;
sp_api::impl_runtime_apis! {
impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
fn create_default_config() -> Vec<u8> {
create_default_config::<RuntimeGenesisConfig>()
}

fn build_config(config: Vec<u8>) -> sp_genesis_builder::Result {
build_config::<RuntimeGenesisConfig>(config)
}
}

impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
Expand Down
4 changes: 2 additions & 2 deletions runtimes/eden/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use sp_std::vec;
use xcm::latest::{prelude::*, NetworkId, Weight as XcmWeight};
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
CurrencyAdapter, EnsureXcmOrigin, FrameTransactionalProcessor, IsConcrete, NativeAsset, ParentIsPreset,
EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentIsPreset,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WeightInfoBounds,
WithComputedOrigin,
Expand Down Expand Up @@ -117,7 +117,7 @@ pub type XcmOriginToTransactDispatchOrigin = (
pub type AssetTransactors = CurrencyTransactor;

/// Means for transacting the native currency on this chain.
pub type CurrencyTransactor = CurrencyAdapter<
pub type CurrencyTransactor = FungibleAdapter<
// Use this currency:
Balances,
// Use this currency when it is a fungible asset matching the given location or name:
Expand Down

0 comments on commit c9d23dd

Please sign in to comment.