Skip to content

Commit

Permalink
Housekeeping (#105)
Browse files Browse the repository at this point in the history
* Housekeeping

* Format
  • Loading branch information
AurevoirXavier authored Dec 6, 2022
1 parent 1720db6 commit 437b769
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 226 deletions.
137 changes: 49 additions & 88 deletions node/src/chain_spec/crab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,42 @@ use std::{collections::BTreeMap, str::FromStr};
use cumulus_primitives_core::ParaId;
// darwinia
use super::*;
use crab_runtime::{AuraId, CrabPrecompiles, EvmConfig, Runtime};
use crab_runtime::*;
use dc_primitives::*;
// frontier
use fp_evm::GenesisAccount;
// substrate
use sc_chain_spec::Properties;
use sc_service::ChainType;
use sp_core::H160;

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

/// 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 session_keys(keys: AuraId) -> crab_runtime::SessionKeys {
crab_runtime::SessionKeys { aura: keys }
fn properties() -> Properties {
super::properties("CRAB", 42)
}

pub fn development_config() -> ChainSpec {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "CRAB".into());
properties.insert("tokenDecimals".into(), 18.into());
properties.insert("ss58Format".into(), 42.into());
// 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).
fn session_keys(keys: AuraId) -> SessionKeys {
SessionKeys { aura: keys }
}

pub fn development_config() -> ChainSpec {
ChainSpec::from_genesis(
// Name
"Crab2 Development",
// ID
"crab-dev",
"crab2-development",
ChainType::Development,
move || {
testnet_genesis(
// initial collators.
vec![
// Bind the `Alice` to `Alith` to make `--alice` available for testnet.
(
array_bytes::hex_n_into_unchecked(ALITH),
get_collator_keys_from_seed("Alice"),
),
// Bind the `Bob` to `Balthar` to make `--bob` available for testnet.
(
array_bytes::hex_n_into_unchecked(BALTATHAR),
get_collator_keys_from_seed("Bob"),
),
],
vec![
array_bytes::hex_n_into_unchecked(ALITH),
Expand All @@ -83,32 +74,23 @@ pub fn development_config() -> ChainSpec {
},
Vec::new(),
None,
Some(PROTOCOL_ID),
None,
None,
Some(properties),
Some(properties()),
Extensions {
relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
para_id: 2105,
},
)
}

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

pub fn local_config() -> ChainSpec {
ChainSpec::from_genesis(
// Name
"Crab2 Local Testnet",
// ID
"crab_local_testnet",
"Crab2 Local",
"crab2-local",
ChainType::Local,
move || {
testnet_genesis(
// initial collators.
vec![
// Bind the `Alice` to `Alith` to make `--alice` available for testnet.
(
Expand All @@ -120,6 +102,11 @@ pub fn local_testnet_config() -> ChainSpec {
array_bytes::hex_n_into_unchecked(BALTATHAR),
get_collator_keys_from_seed("Bob"),
),
// Bind the `Charlie` to `CHARLETH` to make `--charlie` available for testnet.
(
array_bytes::hex_n_into_unchecked(CHARLETH),
get_collator_keys_from_seed("Charlie"),
),
],
vec![
array_bytes::hex_n_into_unchecked(ALITH),
Expand All @@ -132,48 +119,32 @@ pub fn local_testnet_config() -> ChainSpec {
2105.into(),
)
},
// Bootnodes
Vec::new(),
// Telemetry
None,
// Protocol ID
Some("crab"),
// Fork ID
Some(PROTOCOL_ID),
None,
// Properties
Some(properties),
// Extensions
Some(properties()),
Extensions {
relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
para_id: 2105,
},
)
}

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

pub fn genesis_config() -> ChainSpec {
// TODO: update this before final release
ChainSpec::from_genesis(
// Name
"Crab2",
// ID
"crab",
"crab2",
ChainType::Live,
move || {
crab_runtime::GenesisConfig {
GenesisConfig {
// System stuff.
system: crab_runtime::SystemConfig {
code: crab_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
},
system: SystemConfig { code: WASM_BINARY.unwrap().to_vec() },
parachain_system: Default::default(),
parachain_info: crab_runtime::ParachainInfoConfig { parachain_id: 2105.into() },
parachain_info: ParachainInfoConfig { parachain_id: 2105.into() },

// Monetary stuff.
balances: Default::default(),
Expand All @@ -182,11 +153,11 @@ pub fn config() -> ChainSpec {
account_migration: Default::default(),

// Consensus stuff.
collator_selection: crab_runtime::CollatorSelectionConfig {
collator_selection: CollatorSelectionConfig {
invulnerables: vec![array_bytes::hex_n_into_unchecked(ALITH)],
..Default::default()
},
session: crab_runtime::SessionConfig {
session: SessionConfig {
keys: vec![(
array_bytes::hex_n_into_unchecked(ALITH),
array_bytes::hex_n_into_unchecked(ALITH),
Expand All @@ -211,65 +182,61 @@ pub fn config() -> ChainSpec {
vesting: Default::default(),

// XCM stuff.
polkadot_xcm: crab_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
},
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },

// EVM stuff.
ethereum: Default::default(),
evm: Default::default(),
base_fee: Default::default(),

// S2S stuff
// S2S stuff.
bridge_darwinia_grandpa: Default::default(),
bridge_darwinia_messages: Default::default(),
darwinia_fee_market: Default::default(),
}
},
// Bootnodes
Vec::new(),
// Telemetry
None,
// Protocol ID
Some("crab"),
// Fork ID
Some(PROTOCOL_ID),
None,
// Properties
Some(properties),
// Extensions
Some(properties()),
Extensions {
relay_chain: "kusama".into(), // You MUST set this to the correct network!
para_id: 2105,
},
)
}

pub fn config() -> ChainSpec {
unimplemented!("TODO")
}

fn testnet_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> crab_runtime::GenesisConfig {
crab_runtime::GenesisConfig {
) -> GenesisConfig {
GenesisConfig {
// System stuff.
system: crab_runtime::SystemConfig { code: crab_runtime::WASM_BINARY.unwrap().to_vec() },
system: SystemConfig { code: WASM_BINARY.unwrap().to_vec() },
parachain_system: Default::default(),
parachain_info: crab_runtime::ParachainInfoConfig { parachain_id: id },
parachain_info: ParachainInfoConfig { parachain_id: id },

// Monetary stuff.
balances: crab_runtime::BalancesConfig {
balances: BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, 100_000_000 * UNIT)).collect(),
},
transaction_payment: Default::default(),
assets: Default::default(),
account_migration: Default::default(),

// Consensus stuff.
collator_selection: crab_runtime::CollatorSelectionConfig {
collator_selection: CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: UNIT,
..Default::default()
},
session: crab_runtime::SessionConfig {
session: SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
Expand All @@ -281,8 +248,6 @@ fn testnet_genesis(
})
.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(),

Expand All @@ -299,7 +264,7 @@ fn testnet_genesis(
vesting: Default::default(),

// XCM stuff.
polkadot_xcm: crab_runtime::PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },

// EVM stuff.
ethereum: Default::default(),
Expand Down Expand Up @@ -347,13 +312,9 @@ fn testnet_genesis(
},
base_fee: Default::default(),

// S2S stuff
// S2S stuff.
bridge_darwinia_grandpa: Default::default(),
bridge_darwinia_messages: Default::default(),
darwinia_fee_market: Default::default(),
}
}

pub fn genesis_config() -> ChainSpec {
unimplemented!("TODO")
}
Loading

0 comments on commit 437b769

Please sign in to comment.