Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP
  • Loading branch information
Alain Brenzikofer committed Oct 4, 2021
commit b4ea8bd28e8d610157a316bb5ded6381e80e100a
1 change: 1 addition & 0 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 node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ name = 'integritee-node'
[dependencies]
structopt = "0.3.8"
serde_json = "1.0.63"
hex = "0.4"

sc-cli = { version = "0.10.0-dev", features = ["wasmtime"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
Expand Down
221 changes: 150 additions & 71 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use integritee_node_runtime::{
AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, Multisig, Signature,
SudoConfig, SystemConfig, TeerexConfig, TreasuryPalletId, WASM_BINARY,
SudoConfig, SystemConfig, TeerexConfig, TreasuryPalletId, WASM_BINARY, Balance, TEER
};
use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{crypto::Ss58Codec, ed25519, sr25519, Pair, Public};
use sp_finality_grandpa::AuthorityId as GrandpaId;
use sp_runtime::traits::{AccountIdConversion, IdentifyAccount, Verify};
use std::str::FromStr;
use hex::ToHex;

// The URL for the telemetry server.
// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
Expand Down Expand Up @@ -49,6 +50,16 @@ pub fn treasury_account_id() -> AccountId {
TreasuryPalletId::get().into_account()
}

pub fn multisig_account(mut accounts: Vec<AccountId>, threshold: u16) -> AccountId {
// sort accounts by public key, as js/apps would do
accounts.sort_by(|a, b| (*a).encode_hex::<String>().cmp(&(*b).encode_hex::<String>()));

Multisig::multi_account_id(
&accounts,
threshold,
)
}

pub fn development_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
Ok(ChainSpec::from_genesis(
Expand All @@ -66,22 +77,17 @@ pub fn development_config() -> Result<ChainSpec, String> {
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>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
treasury_account_id(),
(get_account_id_from_seed::<sr25519::Public>("Alice"), 1_000_000_000_000),
(get_account_id_from_seed::<sr25519::Public>("Bob"), 1_000_000_000_000),
(get_account_id_from_seed::<sr25519::Public>("Charlie"), 1_000_000_000_000),
(treasury_account_id(), 1_000_000_000_000),
// The address of a multi-signature account is deterministically generated from the signers and threshold of the multisig wallet.
// Creating a multi-sig account from Polkadot-JS Apps UI, always sort the accounts according to the keys. Here we do the same
Multisig::multi_account_id(
&[
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Alice"),
],
2,
),
(multisig_account(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")
], 2), 1_000_000_000_000),
],
true,
)
Expand Down Expand Up @@ -116,28 +122,17 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
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"),
treasury_account_id(),
Multisig::multi_account_id(
&[
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"),
],
3,
),
(get_account_id_from_seed::<sr25519::Public>("Alice"), 1_000_000_000_000),
(get_account_id_from_seed::<sr25519::Public>("Bob"), 1_000_000_000_000),
(get_account_id_from_seed::<sr25519::Public>("Charlie"), 1_000_000_000_000),
(treasury_account_id(), 1_000_000_000_000),
// The address of a multi-signature account is deterministically generated from the signers and threshold of the multisig wallet.
// Creating a multi-sig account from Polkadot-JS Apps UI, always sort the accounts according to the keys. Here we do the same
(multisig_account(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")
], 2), 1_000_000_000_000),
],
true,
)
Expand Down Expand Up @@ -178,6 +173,8 @@ fn chain_spec<F: Fn() -> GenesisConfig + 'static + Send + Sync>(
)
}



#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub enum GenesisKeys {
/// Use integriTEE keys.
Expand Down Expand Up @@ -247,6 +244,7 @@ impl IntegriteeKeys {
),
]
}

}

struct CrannyKeys;
Expand Down Expand Up @@ -293,16 +291,111 @@ impl CrannyKeys {
}

pub fn integritee_mainnet_fresh_config() -> Result<ChainSpec, String> {
integritee_chain_spec(
let wasm_binary = WASM_BINARY.ok_or_else(|| "wasm not available".to_string())?;

let sudo_account: AccountId = public_from_ss58::<sr25519::Public>("2JPGqddf4yEU7waYt7RMp9xwYabm16h8neYEk24tKQs4bAwN").into();
let multisig_controller_accounts: Vec<AccountId> = vec![
public_from_ss58::<sr25519::Public>("2P3Yo9DgGxUiBgdrYorLTHpRnwTSwAiF92xhnfen1SpYc4XN").into(),
public_from_ss58::<sr25519::Public>("2NXxRz9k9V8VBu2Z3HQLWiXocoKBhxYyNR1LqxRQFcNT1m2D").into(),
public_from_ss58::<sr25519::Public>("2NBSuNod6Vy97nmkXkg7vsyU1guudk9Ygakr6LVCXk8mTuvD").into(),
public_from_ss58::<sr25519::Public>("2PyzGJkumD4d5byCLxZnn3HESF7qqrMfHBYRgQ4Dx3hdEvuk").into(),
];
let multisig_controller_threshold: u16 = 3;

let mut allocations = vec![(sudo_account, 5 * TEER)];
allocations.append(multisig_controller_accounts.iter().map(|a| (*a, 1 * TEER)).collect());
allocations.append([(multisig_account(
multisig_controller_accounts,
multisig_controller_threshold
), 1 * TEER)]);

Ok(ChainSpec::from_genesis(
// Name
"Integritee Network (Solo)",
// ID
"integritee-solo",
GenesisKeys::Integritee,
r#"{
"ss58Format": 13,
"tokenDecimals": 12,
"tokenSymbol": "TEER"
}"#,
)
ChainType::Live,
move || {
genesis_config(
wasm_binary,
// Initial PoA authorities
vec![
( public_from_ss58::<sr25519::Public>(
"2PPzpwiTGvcgc4stV326en2mWqY1qFzhQ95SCqYZ4Q5dqwhJ",
).into(),
public_from_ss58::<ed25519::Public>(
"2N8Q3CSCrXjEEBRiSaiXSLTDcbHCSeoKdXePZiSr8ySnoP4f",
).into()
),
(
public_from_ss58::<sr25519::Public>(
"2Px7JZCbMTBhBdWHT7cbC2SGqsVF2cFygdvdaYmuNgV53Bgh",
)
.into(),
public_from_ss58::<ed25519::Public>(
"2MrnyHrQgJb1omjrCu8ZJ4LYBaczcXnREREYX72gmkZZHYFG",
)
.into(),
),
(
public_from_ss58::<sr25519::Public>(
"2PGjX1Nyq2SC7uuWTHWiEMQuJBMRupaefgaG5t6t588nFMZU",
)
.into(),
public_from_ss58::<ed25519::Public>(
"2PLiyfMnuEc7mcgSqfqA7ZHstYeQh3kVZ8eJrsUcYsqTKU3W",
)
.into(),
),
(
public_from_ss58::<sr25519::Public>(
"2Jhqi21p3UdGu1SBJzeUyQM9FudC5iC7e4KryAuJ4NZMhYPe",
)
.into(),
public_from_ss58::<ed25519::Public>(
"2LCKNXvVSWpL6rBusK2RUkYaFV1wv9MnWG2UpGQecsrKpp4R",
)
.into(),
),
(
public_from_ss58::<sr25519::Public>(
"2JwCMVvx8DgzpRD7sF1PKpzCDbmGiB2oa67ka2SuUe2TSJgB",
)
.into(),
public_from_ss58::<ed25519::Public>(
"2P4Bbk7edF41ny7FSMrQ6u2UsjoTaDhD1DARzwdkeDwBiZfn",
)
.into(),
),
],
// Sudo account
sudo_account,
// Pre-funded accounts
allocations,
// println
false,
)
},
// Bootnodes
vec![
"/ip4/142.93.162.173/tcp/30333/p2p/12D3KooWNUBDZuDGcmxRGHHHsBwnyZYAY9v2C3vpXjNngzoxYMf3",
"/ip4/142.93.169.101/tcp/30333/p2p/12D3KooWRu78Bb6M4KCPjUJZ3QX13JbniUaW6eXhFJ5jPH1nvF8M"
],
// Telemetry
vec![["/dns/telemetry.polkadot.io/tcp/443/x-parity-wss/%2Fsubmit%2F", 0]],
// Protocol ID
Some("teer"),
// Properties
Some(serde_json::from_str(
r#"{
"ss58Format": 13,
"tokenDecimals": 12,
"tokenSymbol": "TEER"
}"#
).unwrap()),
// Extensions
None,
))
}

pub fn cranny_fresh_config() -> Result<ChainSpec, String> {
Expand All @@ -318,13 +411,6 @@ pub fn cranny_fresh_config() -> Result<ChainSpec, String> {
)
}

pub fn integritee_mainnet_config() -> Result<ChainSpec, String> {
ChainSpec::from_json_bytes(&include_bytes!("../res/integritee-mainnet.json")[..])
}

pub fn cranny_config() -> Result<ChainSpec, String> {
ChainSpec::from_json_bytes(&include_bytes!("../res/cranny.json")[..])
}

pub fn integritee_chain_spec(
chain_name: &str,
Expand All @@ -350,40 +436,23 @@ pub fn integritee_chain_spec(
token_specs,
))
}

/// Configure initial storage state for FRAME modules.
///
fn genesis_config(
wasm_binary: &[u8],
initial_authorities: Vec<(AuraId, GrandpaId)>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
initial_token_allocation: Vec<(AccountId, Balance)>,
_enable_println: bool,
) -> GenesisConfig {
let treasury_funding =
(endowed_accounts.len() as u128 - 1u128) * ENDOWED_FUNDING * TREASURY_FUNDING_PERCENT /
100u128;
GenesisConfig {
system: SystemConfig {
// Add Wasm runtime to storage.
code: wasm_binary.to_vec(),
changes_trie_config: Default::default(),
},
balances: BalancesConfig {
// Configure endowed accounts with initial balance of ENDOWED_FUNDING and allocate the treasury TREASURY_FUNDING_PERCENT of total supply .
balances: endowed_accounts
.iter()
.cloned()
.map(|k| {
if k == treasury_account_id() {
(k, treasury_funding)
} else if k == CrannyKeys::root() {
(k, 10_000_000__000_000_000_000)
} else {
(k, ENDOWED_FUNDING)
}
})
.collect(),
balances: initial_token_allocation,
},
aura: AuraConfig {
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
Expand All @@ -400,3 +469,13 @@ fn genesis_config(
vesting: Default::default(),
}
}

/// hard-coded configs

pub fn integritee_mainnet_config() -> Result<ChainSpec, String> {
ChainSpec::from_json_bytes(&include_bytes!("../res/integritee-mainnet.json")[..])
}

pub fn cranny_config() -> Result<ChainSpec, String> {
ChainSpec::from_json_bytes(&include_bytes!("../res/cranny.json")[..])
}