Skip to content

Feature/luhn chain spec #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# These are backup files generated by rustfmt
**/*.rs.bk

**/node_modules

.DS_Store

# The cache for docker container dependency
Expand Down Expand Up @@ -32,3 +34,4 @@ gcloud-md5-ingress.yml
collator-data
relay-data
.vscode/settings.json

362 changes: 181 additions & 181 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions collator/src/chain_spec/hashed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn get_chain_spec() -> HashedChainSpec {
hex!["364e8e853de71a91892b8ce50308b4229c0c21863a7ec788d5e4f2f5f957e224"].into(),
],
hex!["364e8e853de71a91892b8ce50308b4229c0c21863a7ec788d5e4f2f5f957e224"].into(),
3000.into(),
2000.into(),
)
},
Vec::new(),
Expand Down Expand Up @@ -85,7 +85,7 @@ fn hashed_genesis(
.to_vec(),
},
balances: hashed_parachain_runtime::BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
balances: endowed_accounts.iter().cloned().map(|k| (k, 1000000000000000000000000000)).collect(),
},
sudo: SudoConfig { key: Some(root_key) },
council: Default::default(),
Expand Down
120 changes: 120 additions & 0 deletions collator/src/chain_spec/luhn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
use sc_service::ChainType;
// use sp_core::sr25519;
use sp_core::{crypto::UncheckedInto};

use hex_literal::hex;

use super::{
/*get_account_id_from_seed, get_collator_keys_from_seed,*/ session_keys, SAFE_XCM_VERSION, Extensions,
};

use cumulus_primitives_core::ParaId;
use hashed_parachain_runtime::{AccountId, AuraId, SudoConfig, EXISTENTIAL_DEPOSIT};

/// Specialized `ChainSpec` for Hashed Network
pub type HashedChainSpec =
sc_service::GenericChainSpec<hashed_parachain_runtime::GenesisConfig, Extensions>;

/// Gen HASH chain specification
pub fn get_chain_spec() -> HashedChainSpec {

let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "LUHN".into());
properties.insert("tokenDecimals".into(), 18.into());
properties.insert("ss58Format".into(), 11486.into());
properties.insert("prefix".into(), 11486.into());
properties.insert("network".into(), "luhn".into());
properties.insert("displayName".into(), "Luhn Network".into());
properties.insert("standardAccount".into(),"*25519".into());
properties.insert("website".into(), "https://luhn.network".into());

HashedChainSpec::from_genesis(
"Luhn Network",
"luhn",
ChainType::Live,
move || {
hashed_genesis(
// initial collators.
vec![
(
// Collator #1
// uhsPQGuXYwjnLvoJWWttQ6FEVtztHSvsjE7UFzxS8mSfoSmts
hex!["1cfc7e49e91696b84bf8e931c16375ea634c3997b36155657faf7dc4716e273e"].into(),
hex!["1cfc7e49e91696b84bf8e931c16375ea634c3997b36155657faf7dc4716e273e"].unchecked_into(),
),
(
// Collator #2
// uhujXWvqSqGrY3K62qeamwCGQd7tTo1hm1s9ZYrgxAZFBLyLv
hex!["84ce3f0bc9ae73d8497c6161927e9e04f39f4bc54579689532d048188c10a77c"].into(),
hex!["84ce3f0bc9ae73d8497c6161927e9e04f39f4bc54579689532d048188c10a77c"].unchecked_into(),
),
],
vec![
// PH
// uhtqJBJ9ZeKguyAG4GJ2S7cme5FvJ661P5NVdHTYKQgvDEQAR
hex!["5cf8957922e4058a953281f82fdced2e4d389fe37c77f41a0fd2379df0caf877"].into(),
],
// uhtqJBJ9ZeKguyAG4GJ2S7cme5FvJ661P5NVdHTYKQgvDEQAR
hex!["5cf8957922e4058a953281f82fdced2e4d389fe37c77f41a0fd2379df0caf877"].into(),
2232.into(),
)
},
Vec::new(),
None,
None,
None,
Some(properties),
Extensions {
relay_chain: "kusama".into(),
para_id: 2232,
},
)
}

fn hashed_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
root_key: AccountId,
id: ParaId,
) -> hashed_parachain_runtime::GenesisConfig {
hashed_parachain_runtime::GenesisConfig {
system: hashed_parachain_runtime::SystemConfig {
code: hashed_parachain_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
},
balances: hashed_parachain_runtime::BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, 1000000000000000000000000000)).collect(),
},
sudo: SudoConfig { key: Some(root_key) },
council: Default::default(),
treasury: Default::default(),
parachain_info: hashed_parachain_runtime::ParachainInfoConfig { parachain_id: id },
collator_selection: hashed_parachain_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
..Default::default()
},
session: hashed_parachain_runtime::SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
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(),
parachain_system: Default::default(),
polkadot_xcm: hashed_parachain_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
},
}
}

1 change: 1 addition & 0 deletions collator/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use sc_service::ChainType;
use sp_runtime::traits::{IdentifyAccount, Verify};

pub mod hashed;
pub mod luhn;
pub mod md5;

/// Specialized `ChainSpec` for the normal parachain runtime.
Expand Down
14 changes: 7 additions & 7 deletions collator/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
Ok(match id {
"dev" => Box::new(chain_spec::development_config()),
"hashed" => Box::new(chain_spec::hashed::get_chain_spec()),
// "luhn" => Box::new(chain_spec::luhn::get_chain_spec()),
"luhn" => Box::new(chain_spec::luhn::get_chain_spec()),
"md5" => Box::new(chain_spec::md5::get_chain_spec()),
"" | "local" => Box::new(chain_spec::local_testnet_config()),
path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
Expand All @@ -36,7 +36,7 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {

impl SubstrateCli for Cli {
fn impl_name() -> String {
"Hashed Network Parachain Collator".into()
"Luhn Network Parachain Collator".into()
}

fn impl_version() -> String {
Expand All @@ -45,7 +45,7 @@ impl SubstrateCli for Cli {

fn description() -> String {
format!(
"Hashed Network Parachain Collator\n\nThe command-line arguments provided first will be \
"Luhn Network Parachain Collator\n\nThe command-line arguments provided first will be \
passed to the parachain node, while the arguments provided after -- will be passed \
to the relay chain node.\n\n\
{} <parachain-args> -- <relay-chain-args>",
Expand All @@ -58,7 +58,7 @@ impl SubstrateCli for Cli {
}

fn support_url() -> String {
"https://github.com/hashed-io/hashed-parachain/issues/new".into()
"https://github.com/hashed-io/hashed-substrate/issues/new".into()
}

fn copyright_start_year() -> i32 {
Expand All @@ -76,7 +76,7 @@ impl SubstrateCli for Cli {

impl SubstrateCli for RelayChainCli {
fn impl_name() -> String {
"Hashed Network Parachain Collator".into()
"Luhn Network Parachain Collator".into()
}

fn impl_version() -> String {
Expand All @@ -85,7 +85,7 @@ impl SubstrateCli for RelayChainCli {

fn description() -> String {
format!(
"Hashed Network Parachain Collator\n\nThe command-line arguments provided first will be \
"Luhn Network Parachain Collator\n\nThe command-line arguments provided first will be \
passed to the parachain node, while the arguments provided after -- will be passed \
to the relay chain node.\n\n\
{} <parachain-args> -- <relay-chain-args>",
Expand All @@ -98,7 +98,7 @@ impl SubstrateCli for RelayChainCli {
}

fn support_url() -> String {
"https://github.com/hashed-io/hashed-parachain/issues/new".into()
"https://github.com/hashed-io/hashed-substrate/issues/new".into()
}

fn copyright_start_year() -> i32 {
Expand Down
52 changes: 47 additions & 5 deletions docs/parachain/quick-start-hashed.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ cd hashed-substrate

cargo build --release

./target/release/hashed-parachain build-spec --chain hashed --disable-default-bootnode > hashed-local-parachain.json

./target/release/hashed-parachain build-spec --chain hashed --disable-default-bootnode > hashed-local-parachain.json
```

Expand All @@ -51,6 +53,12 @@ Update `md5-local-parachain.json` and change the parachain ID to 2000 in two pla
// --snip--
```

# Change amount for endowed account to

1000000000000000000000000000

1 billion with 18 decimal places

# Build the Raw Spec File
```bash
# build raw spec
Expand All @@ -61,17 +69,23 @@ Update `md5-local-parachain.json` and change the parachain ID to 2000 in two pla
```bash
./target/release/hashed-parachain export-genesis-state --chain hashed-local-parachain-raw.json > hashed-genesis-head

./target/release/hashed-parachain export-genesis-wasm --chain hashed-local-parachain-raw.json > hashed-wasm
./target/release/hashed-parachain export-genesis-wasm --chain hashed-local-parachain-raw.json > hashed-wasm-upgrade
```

# Building genesis state and wasm files
```bash
./target/release/hashed-parachain export-genesis-state --chain hashed > hashed-genesis-head

./target/release/hashed-parachain export-genesis-wasm --chain hashed > hashed-wasm
```

# Start Collator
# Start Collator #1
```bash
./target/release/hashed-parachain \
--alice \
--collator \
--force-authoring \
--chain hashed-local-parachain-raw.json \
--base-path /tmp/parachain/alice \
--chain hashed \
--base-path /tmp/parachain/hashed-local \
--port 40333 \
--ws-port 8844 \
-- \
Expand All @@ -86,6 +100,34 @@ Update `md5-local-parachain.json` and change the parachain ID to 2000 in two pla
![image](https://user-images.githubusercontent.com/2915325/99548884-1be13580-2987-11eb-9a8b-20be658d34f9.png)


# Generate new WASM
```bash
./target/release/hashed-parachain export-genesis-wasm --chain hashed > hashed-wasm-upgrade
```

# Start Second Collator
```bash
./target/release/hashed-parachain \
--bob \
--collator \
--force-authoring \
--chain hashed \
--base-path /tmp/parachain/bob \
--port 40334 \
--ws-port 8845 \
-- \
--execution wasm \
--chain ~/github.com/paritytech/polkadot/rococo-custom-2-raw.json \
--port 30344 \
--ws-port 9978

```

## Insert second collator key
```bash
./target/release/hashed key insert --scheme sr25519 --keystore-path /tmp/parachain/hashed-local/chains/hashed/keystore --key-type aura --suri ""
```

### Purging the Chains
```bash
# Purge a chain
Expand Down
Loading