Skip to content

Commit

Permalink
Cleanup of chainspecs
Browse files Browse the repository at this point in the history
  • Loading branch information
drewstone committed Nov 23, 2023
1 parent 81dcbdc commit 520533e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 320 deletions.
307 changes: 4 additions & 303 deletions standalone/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,84 +107,6 @@ fn dkg_session_keys(
tangle_runtime::opaque::SessionKeys { grandpa, aura, dkg, im_online }
}

pub fn development_config(chain_id: u64) -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "dTNT".into());
properties.insert("tokenDecimals".into(), 18u32.into());
properties.insert("ss58Format".into(), 42.into());

Ok(ChainSpec::from_genesis(
// Name
"Development",
// ID
"dev",
ChainType::Development,
move || {
testnet_genesis(
wasm_binary,
// Initial PoA authorities
vec![
authority_keys_from_seed("Alice", "Alice//stash"),
authority_keys_from_seed("Bob", "Bob//stash"),
authority_keys_from_seed("Charlie", "Charlie//stash"),
authority_keys_from_seed("Dave", "Dave//stash"),
authority_keys_from_seed("Eve", "Eve//stash"),
],
vec![],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Pre-funded accounts
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"),
],
// Initial Chain Ids
vec![],
// Initial resource Ids
vec![],
// Initial proposers
vec![
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
],
chain_id,
DEFAULT_DKG_KEYGEN_THRESHOLD,
DEFAULT_DKG_SIGNATURE_THRESHOLD,
combine_distributions(vec![
develop::get_evm_balance_distribution(),
testnet::get_evm_balance_distribution(),
]),
testnet::get_substrate_balance_distribution(),
true,
)
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
None,
// Fork id
None,
// Properties
Some(properties),
// Extensions
None,
))
}

pub fn local_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
let mut properties = sc_chain_spec::Properties::new();
Expand Down Expand Up @@ -263,150 +185,6 @@ pub fn local_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
))
}

pub fn relayer_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "tTNT".into());
properties.insert("tokenDecimals".into(), 18u32.into());
properties.insert("ss58Format".into(), 42.into());

let relayer_testnet_dkg_keygen_threshold = 2;
let relayer_testnet_dkg_signature_threshold = 1;

Ok(ChainSpec::from_genesis(
// Name
"Local Testnet",
// ID
"local_testnet",
ChainType::Local,
move || {
testnet_genesis(
wasm_binary,
// Initial PoA authorities
vec![
authority_keys_from_seed("Alice", "Alice//stash"),
authority_keys_from_seed("Charlie", "Charlie//stash"),
],
vec![],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Pre-funded accounts
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"),
],
// Initial Chain Ids
vec![CHAIN_ID_HERMES, CHAIN_ID_ATHENA, CHAIN_ID_DEMETER],
// Initial resource Ids
vec![
(RESOURCE_ID_HERMES_ATHENA, Default::default()),
(RESOURCE_ID_ATHENA_HERMES, Default::default()),
],
// Initial proposers
vec![
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
],
chain_id,
relayer_testnet_dkg_keygen_threshold,
relayer_testnet_dkg_signature_threshold,
combine_distributions(vec![
develop::get_evm_balance_distribution(),
testnet::get_evm_balance_distribution(),
]),
testnet::get_substrate_balance_distribution(),
true,
)
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
None,
// Fork id
None,
// Properties
Some(properties),
// Extensions
None,
))
}

pub fn standalone_live_config(chain_id: u64) -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "tangle wasm not available".to_string())?;
let boot_nodes = get_standalone_bootnodes();
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "tTNT".into());
properties.insert("tokenDecimals".into(), 18u32.into());
properties.insert("ss58Format".into(), 42.into());

Ok(ChainSpec::from_genesis(
"Tangle Standalone",
"tangle-standalone",
ChainType::Development,
move || {
testnet_genesis(
wasm_binary,
// Initial PoA authorities
get_standalone_initial_authorities(),
// initial nominators
vec![],
// Sudo account
get_testnet_root_key(),
// Pre-funded accounts
vec![
get_testnet_root_key(),
hex!["4e85271af1330e5e9384bd3ac5bdc04c0f8ef5a8cc29c1a8ae483d674164745c"].into(),
hex!["804808fb75d16340dc250871138a1a6f1dfa3cab9cc1fbd6f42960f1c39a950d"].into(),
hex!["587c2ef00ec0a1b98af4c655763acd76ece690fccbb255f01663660bc274960d"].into(),
hex!["cc195602a63bbdcf2ef4773c86fdbfefe042cb9aa8e3059d02e59a062d9c3138"].into(),
hex!["a24f729f085de51eebaeaeca97d6d499761b8f6daeca9b99d754a06ef8bcec3f"].into(),
hex!["368ea402dbd9c9888ae999d6a799cf36e08673ee53c001dfb4529c149fc2c13b"].into(),
hex!["2c7f3cc085da9175414d1a9d40aa3aa161c8584a9ca62a938684dfbe90ae9d74"].into(),
hex!["0a55e5245382700f35d16a5ea6d60a56c36c435bef7204353b8c36871f347857"].into(),
hex!["e0948453e7acbc6ac937e124eb01580191e99f4262d588d4524994deb6134349"].into(),
hex!["6c73e5ee9f8614e7c9f23fd8f7257d12e061e75fcbeb3b50ed70eb87ba91f500"].into(),
],
vec![],
vec![],
get_standalone_initial_authorities().iter().map(|a| a.0.clone()).collect(),
chain_id,
DEFAULT_DKG_KEYGEN_THRESHOLD,
DEFAULT_DKG_SIGNATURE_THRESHOLD,
combine_distributions(vec![
develop::get_evm_balance_distribution(),
testnet::get_evm_balance_distribution(),
]),
testnet::get_substrate_balance_distribution(),
true,
)
},
// Bootnodes
boot_nodes,
// Telemetry
None,
// Protocol ID
None,
// Fork id
None,
// Properties
Some(properties),
// Extensions
None,
))
}

pub fn tangle_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "tangle wasm not available".to_string())?;
let boot_nodes = get_standalone_bootnodes();
Expand Down Expand Up @@ -485,69 +263,6 @@ pub fn tangle_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
))
}

// same as tangle_testnet but without bootnodes so that we can spinup same network locally
pub fn tangle_local_config(chain_id: u64) -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "tangle wasm not available".to_string())?;
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "tTNT".into());
properties.insert("tokenDecimals".into(), 18u32.into());
properties.insert("ss58Format".into(), 42.into());

Ok(ChainSpec::from_genesis(
"Tangle Local",
"tangle-local",
ChainType::Development,
move || {
testnet_genesis(
wasm_binary,
// Initial PoA authorities
get_standalone_initial_authorities(),
vec![],
// Sudo account
get_testnet_root_key(),
// Pre-funded accounts
vec![
get_testnet_root_key(),
hex!["4e85271af1330e5e9384bd3ac5bdc04c0f8ef5a8cc29c1a8ae483d674164745c"].into(),
hex!["804808fb75d16340dc250871138a1a6f1dfa3cab9cc1fbd6f42960f1c39a950d"].into(),
hex!["587c2ef00ec0a1b98af4c655763acd76ece690fccbb255f01663660bc274960d"].into(),
hex!["cc195602a63bbdcf2ef4773c86fdbfefe042cb9aa8e3059d02e59a062d9c3138"].into(),
hex!["a24f729f085de51eebaeaeca97d6d499761b8f6daeca9b99d754a06ef8bcec3f"].into(),
hex!["368ea402dbd9c9888ae999d6a799cf36e08673ee53c001dfb4529c149fc2c13b"].into(),
hex!["2c7f3cc085da9175414d1a9d40aa3aa161c8584a9ca62a938684dfbe90ae9d74"].into(),
hex!["0a55e5245382700f35d16a5ea6d60a56c36c435bef7204353b8c36871f347857"].into(),
hex!["e0948453e7acbc6ac937e124eb01580191e99f4262d588d4524994deb6134349"].into(),
hex!["6c73e5ee9f8614e7c9f23fd8f7257d12e061e75fcbeb3b50ed70eb87ba91f500"].into(),
],
vec![],
vec![],
get_standalone_initial_authorities().iter().map(|a| a.0.clone()).collect(),
chain_id,
DEFAULT_DKG_KEYGEN_THRESHOLD,
DEFAULT_DKG_SIGNATURE_THRESHOLD,
combine_distributions(vec![
develop::get_evm_balance_distribution(),
testnet::get_evm_balance_distribution(),
]),
testnet::get_substrate_balance_distribution(),
true,
)
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
None,
// Fork id
None,
// Properties
Some(properties),
// Extensions
None,
))
}

pub fn tangle_mainnet_config(chain_id: u64) -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "tangle wasm not available".to_string())?;
let boot_nodes = get_standalone_bootnodes();
Expand All @@ -571,8 +286,6 @@ pub fn tangle_mainnet_config(chain_id: u64) -> Result<ChainSpec, String> {
authority_keys_from_seed("Dave", "Dave//stash"),
authority_keys_from_seed("Eve", "Eve//stash"),
],
// initial nominators
vec![],
// Sudo account
get_testnet_root_key(),
// Pre-funded accounts
Expand Down Expand Up @@ -748,34 +461,22 @@ fn testnet_genesis(
fn mainnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AccountId, AccountId, AuraId, GrandpaId, ImOnlineId, DKGId)>,
initial_nominators: Vec<AccountId>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
chain_id: u64,
genesis_evm_distribution: Vec<(H160, fp_evm::GenesisAccount)>,
_genesis_evm_distribution: Vec<(H160, fp_evm::GenesisAccount)>,
genesis_substrate_distribution: Vec<(AccountId, Balance)>,
_enable_println: bool,
) -> RuntimeGenesisConfig {
const ENDOWMENT: Balance = 100 * UNIT;
const STASH: Balance = ENDOWMENT / 100;

// stakers: all validators and nominators.
let mut rng = rand::thread_rng();
let _rng = rand::thread_rng();
let stakers = initial_authorities
.iter()
.map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator))
.chain(initial_nominators.iter().map(|x| {
use rand::{seq::SliceRandom, Rng};
let limit = (MaxNominations::get() as usize).min(initial_authorities.len());
let count = rng.gen::<usize>() % limit;
let nominations = initial_authorities
.as_slice()
.choose_multiple(&mut rng, count)
.map(|choice| choice.0.clone())
.collect::<Vec<_>>();
(x.clone(), x.clone(), STASH, StakerStatus::Nominator(nominations))
}))
.collect::<Vec<_>>();
.map(|x| (x.0.clone(), x.0.clone(), STASH, StakerStatus::Validator))
.collect();

RuntimeGenesisConfig {
system: SystemConfig {
Expand Down
10 changes: 2 additions & 8 deletions standalone/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,11 @@ impl SubstrateCli for Cli {

fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"dev" => Box::new(chain_spec::development_config(4006)?),
"relayer" => Box::new(chain_spec::relayer_testnet_config(4006)?),
"" | "local" => Box::new(chain_spec::local_testnet_config(4006)?),
// generates the standalone spec for testing locally
"local" => Box::new(chain_spec::tangle_local_config(4006)?),
// generates the standalone spec for testnet
"testnet-alpha" => Box::new(chain_spec::tangle_testnet_config(4006)?),
// generates the spec for testnet
"testnet" => Box::new(chain_spec::tangle_testnet_config(4006)?),
// generates the spec for mainnet
"mainnet" => Box::new(chain_spec::tangle_mainnet_config(4006)?),
// generates the standalone spec for longterm testnet
"standalone" => Box::new(chain_spec::standalone_live_config(4006)?),
"tangle-testnet" => Box::new(chain_spec::ChainSpec::from_json_bytes(
&include_bytes!("../../../chainspecs/testnet/tangle-standalone.json")[..],
)?),
Expand Down
13 changes: 4 additions & 9 deletions standalone/node/src/distributions/mainnet.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
use std::{
fs::File,
io::Read,
path::{Path, PathBuf},
str::FromStr,
};
use std::str::FromStr;

use fp_evm::GenesisAccount;
use serde_json::Value;
use sp_core::{crypto::Ss58Codec, H160, U256};

use sp_core::{H160, U256};
use sp_runtime::AccountId32;
use std::collections::BTreeMap;
use tangle_runtime::{AccountId, Balance, ExistentialDeposit};
Expand Down Expand Up @@ -72,7 +67,7 @@ pub fn get_edgeware_genesis_balance_distribution() -> Vec<(H160, GenesisAccount)

pub fn get_leaderboard_balance_distribution() -> Vec<(H160, GenesisAccount)> {
const ONE_TOKEN: u128 = 1_000_000_000_000_000_000;
const ENDOWMENT: u128 = 1 * ONE_TOKEN;
const ENDOWMENT: u128 = ONE_TOKEN;
get_discord_list()
.into_iter()
.map(|address| {
Expand Down

0 comments on commit 520533e

Please sign in to comment.