Skip to content

Commit

Permalink
NEU genesis allocation (#82)
Browse files Browse the repository at this point in the history
* generate a neumann config with initial token allocation

* tested w/ new prefix

* NEU distribution

* updating versions
  • Loading branch information
Ryan Huttman committed Feb 18, 2022
1 parent fe7e92a commit b998e9c
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 11 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions distribution/neumann_alloc.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "oak-node"
version = "1.2.4"
version = "1.2.5"
authors = ["OAK Developement Team"]
description = "Automation-first Blockchain"
license = "GPL-3.0"
Expand Down Expand Up @@ -32,6 +32,7 @@ log = "0.4.14"
codec = { package = "parity-scale-codec", version = "2.3.1" }
structopt = "0.3.8"
serde = { version = "1.0.124", features = ["derive"] }
serde_json = "1.0.68"
hex-literal = "0.3.1"

# RPC related Dependencies
Expand Down
138 changes: 136 additions & 2 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use cumulus_primitives_core::ParaId;
use hex_literal::hex;
use neumann_runtime::{
AccountId, AuraId, CouncilConfig, Signature, SudoConfig, ValveConfig, DOLLAR,
AccountId, AuraId, Balance, CouncilConfig, Signature, SudoConfig, ValveConfig, DOLLAR,
EXISTENTIAL_DEPOSIT, TOKEN_DECIMALS,
};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
use sp_core::{crypto::UncheckedInto, sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
use sp_runtime::traits::{IdentifyAccount, Verify, Zero};

static TOKEN_SYMBOL: &str = "NEU";
const SS_58_FORMAT: u32 = 51;
Expand Down Expand Up @@ -294,3 +294,137 @@ fn testnet_genesis(
valve: ValveConfig { start_with_valve_closed: false },
}
}

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

ChainSpec::from_genesis(
// Name
"Neumann Network",
// ID
"neumann",
ChainType::Live,
move || {
let allocation_json = &include_bytes!("../../distribution/neumann_alloc.json")[..];
let initial_allocation: Vec<(AccountId, Balance)> = serde_json::from_slice(allocation_json).unwrap();

testnet_genesis_temp(
// initial collators.
vec![
(
// 5ECasnYivb8cQ4wBrQsdjwRTW4dzJ1ZcFqJNCLJwcc2N6WGL
hex!["5e7aee4ee53ef08d5032ba5db9f7a6fdd9eef52423ac8c1aa960236377b46610"]
.into(),
hex!["5e7aee4ee53ef08d5032ba5db9f7a6fdd9eef52423ac8c1aa960236377b46610"]
.unchecked_into(),
),
(
// 5D2VxzUBZBkYtLxnpZ9uAV7Vht2Jz5MwqSco2GaqyLwGDZ4J
hex!["2a8db6ca2e0cb5679e0eff0609de708c9957f465af49abbe7ff0a3594d52933e"]
.into(),
hex!["2a8db6ca2e0cb5679e0eff0609de708c9957f465af49abbe7ff0a3594d52933e"]
.unchecked_into(),
),
],
// 5GcD1vPdWzBd3VPTPgVFWL9K7b27A2tPYcVTJoGwKcLjdG5w
hex!["c8f7b3791290f2d0f66a08b6ae1ebafe8d1efff56e31b0bb14e8d98157379028"].into(),
initial_allocation,
DEFAULT_PARA_ID.into(),
)
},
// Bootnodes
Vec::new(),
// Telemetry
None,
// Protocol ID
Some("neumann"),
None,
// Properties
Some(properties),
// Extensions
Extensions {
relay_chain: NEUMANN_RELAY_CHAIN.into(), // You MUST set this to the correct network!
para_id: DEFAULT_PARA_ID,
},
)
}

fn testnet_genesis_temp(
invulnerables: Vec<(AccountId, AuraId)>,
root_key: AccountId,
endowed_accounts: Vec<(AccountId, Balance)>,
id: ParaId,
) -> neumann_runtime::GenesisConfig {

validate_endowment(endowed_accounts.clone());

neumann_runtime::GenesisConfig {
system: neumann_runtime::SystemConfig {
code: neumann_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
},
balances: neumann_runtime::BalancesConfig {
balances: endowed_accounts,
},
parachain_info: neumann_runtime::ParachainInfoConfig { parachain_id: id },
collator_selection: neumann_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
..Default::default()
},
session: neumann_runtime::SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
template_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(),
council: CouncilConfig { members: vec![root_key.clone()], phantom: Default::default() },
parachain_system: Default::default(),
sudo: SudoConfig { key: Some(root_key) },
treasury: Default::default(),
valve: ValveConfig { start_with_valve_closed: false },
}
}

/// Validate that the endowment fits the following criteria:
/// - no duplicate accounts
/// - total endowed is equal to TOTAL_TOKENS
pub fn validate_endowment(endowed_accounts: Vec<(AccountId, Balance)>) {
let mut total_endowed: Balance = Zero::zero();
let unique_endowed_accounts = endowed_accounts
.iter()
.map(|(account_id, amount)| {
assert!(*amount >= EXISTENTIAL_DEPOSIT, "endowned amount must gte ED");
total_endowed = total_endowed
.checked_add(*amount)
.expect("shouldn't overflow when building genesis");

account_id
})
.cloned()
.collect::<std::collections::BTreeSet<_>>();
assert!(
unique_endowed_accounts.len() == endowed_accounts.len(),
"duplicate endowed accounts in genesis."
);
assert_eq!(
total_endowed,
TOTAL_TOKENS,
"total endowed must be equal to 1 billion NEU"
);
}
1 change: 1 addition & 0 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, St
"dev" => Box::new(chain_spec::development_config()),
"template-rococo" => Box::new(chain_spec::local_testnet_config()),
"neumann-staging" => Box::new(chain_spec::neumann_staging_testnet_config()),
"neumann-latest" => Box::new(chain_spec::neumann_latest()),
"" | "local" => Box::new(chain_spec::local_testnet_config()),
path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
})
Expand Down
2 changes: 2 additions & 0 deletions node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ mod service;
mod cli;
mod command;
mod rpc;
#[cfg(test)]
mod tests;

fn main() -> sc_cli::Result<()> {
command::run()
Expand Down
10 changes: 10 additions & 0 deletions node/src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::chain_spec::validate_endowment;
use neumann_runtime::{AccountId, Balance};

#[test]
fn validate_neumann_allocation() {
let allocation_json = &include_bytes!("../../distribution/neumann_alloc.json")[..];
let allocation: Vec<(AccountId, Balance)> = serde_json::from_slice(allocation_json).unwrap();

validate_endowment(allocation);
}
2 changes: 1 addition & 1 deletion pallets/automation-time/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pallet-automation-time"
description = "Pallet for scheduling and running tasks in the future."
version = "0.0.0"
version = "1.0.0"
edition = "2018"
authors = ["OAK Developement Team"]
license = "GPL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion pallets/valve/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pallet-valve"
description = "Pallet for pausing different parts of the chain."
version = "0.1.0"
version = "0.2.0"
edition = "2021"
authors = ["OAK Developement Team"]
homepage = "https://oak.tech"
Expand Down
78 changes: 78 additions & 0 deletions resources/neumann-latest.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions runtime/neumann/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("neumann"),
impl_name: create_runtime_str!("neumann"),
authoring_version: 1,
spec_version: 273,
impl_version: 0,
spec_version: 274,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
transaction_version: 3,
state_version: 0,
};

Expand Down

0 comments on commit b998e9c

Please sign in to comment.