Skip to content

Commit fff8d54

Browse files
committed
Configure devnet chain spec
1 parent 31d801e commit fff8d54

File tree

6 files changed

+249
-36
lines changed

6 files changed

+249
-36
lines changed

node/src/chain_spec/devnet.rs

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Allowed since it's actually better to panic during chain setup when there is an error
2+
#![allow(clippy::unwrap_used)]
3+
4+
use super::*;
5+
6+
pub fn devnet_config() -> Result<ChainSpec, String> {
7+
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
8+
9+
// Give front-ends necessary data to present to users
10+
let mut properties = sc_service::Properties::new();
11+
properties.insert("tokenSymbol".into(), "testTAO".into());
12+
properties.insert("tokenDecimals".into(), 9.into());
13+
properties.insert("ss58Format".into(), 42.into());
14+
15+
Ok(ChainSpec::builder(
16+
wasm_binary,
17+
Extensions {
18+
bad_blocks: Some(HashSet::new()),
19+
..Default::default()
20+
},
21+
)
22+
.with_name("Bittensor")
23+
.with_protocol_id("bittensor")
24+
.with_id("bittensor")
25+
.with_chain_type(ChainType::Development)
26+
.with_genesis_config_patch(testnet_genesis(
27+
// Initial PoA authorities (Validators)
28+
// aura | grandpa
29+
vec![
30+
// Keys for debug
31+
authority_keys_from_ss58(
32+
"5D5ABUyMsdmJdH7xrsz9vREq5eGXr5pXhHxix2dENQR62dEo",
33+
"5H3qMjQjoeZxZ98jzDmoCwbz2sugd5fDN1wrr8Phf49zemKL",
34+
), // key 1
35+
authority_keys_from_ss58(
36+
"5GbRc5sNDdhcPAU9suV2g9P5zyK1hjAQ9JHeeadY1mb8kXoM",
37+
"5GbkysfaCjK3cprKPhi3CUwaB5xWpBwcfrkzs6FmqHxej8HZ",
38+
), // key 1
39+
authority_keys_from_ss58(
40+
"5CoVWwBwXz2ndEChGcS46VfSTb3RMUZzZzAYdBKo263zDhEz",
41+
"5HTLp4BvPp99iXtd8YTBZA1sMfzo8pd4mZzBJf7HYdCn2boU",
42+
), // key 1
43+
authority_keys_from_ss58(
44+
"5EekcbqupwbgWqF8hWGY4Pczsxp9sbarjDehqk7bdyLhDCwC",
45+
"5GAemcU4Pzyfe8DwLwDFx3aWzyg3FuqYUCCw2h4sdDZhyFvE",
46+
), // key 1
47+
authority_keys_from_ss58(
48+
"5GgdEQyS5DZzUwKuyucEPEZLxFKGmasUFm1mqM3sx1MRC5RV",
49+
"5EibpMomXmgekxcfs25SzFBpGWUsG9Lc8ALNjXN3TYH5Tube",
50+
), // key 1
51+
authority_keys_from_ss58(
52+
"5Ek5JLCGk2PuoT1fS23GXiWYUT98HVUBERFQBu5g57sNf44x",
53+
"5Gyrc6b2mx1Af6zWJYHdx3gwgtXgZvD9YkcG9uTUPYry4V2a",
54+
), // key 1
55+
],
56+
// Sudo account
57+
Ss58Codec::from_ss58check("5GpzQgpiAKHMWNSH3RN4GLf96GVTDct9QxYEFAY7LWcVzTbx").unwrap(),
58+
// Pre-funded accounts
59+
vec![],
60+
true,
61+
vec![],
62+
vec![],
63+
0,
64+
))
65+
.with_properties(properties)
66+
.build())
67+
}
68+
69+
// Configure initial storage state for FRAME modules.
70+
#[allow(clippy::too_many_arguments)]
71+
fn testnet_genesis(
72+
initial_authorities: Vec<(AuraId, GrandpaId)>,
73+
root_key: AccountId,
74+
_endowed_accounts: Vec<AccountId>,
75+
_enable_println: bool,
76+
_stakes: Vec<(AccountId, Vec<(AccountId, (u64, u16))>)>,
77+
_balances: Vec<(AccountId, u64)>,
78+
_balances_issuance: u64,
79+
) -> serde_json::Value {
80+
serde_json::json!({
81+
"balances": {
82+
"balances": vec![(root_key.clone(), 1_000_000_000_000u128)],
83+
},
84+
"aura": {
85+
"authorities": initial_authorities.iter().map(|x| (x.0.clone())).collect::<Vec<_>>(),
86+
},
87+
"grandpa": {
88+
"authorities": initial_authorities
89+
.iter()
90+
.map(|x| (x.1.clone(), 1))
91+
.collect::<Vec<_>>(),
92+
},
93+
"sudo": {
94+
"key": Some(root_key),
95+
},
96+
})
97+
}

node/src/chain_spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Allowed since it's actually better to panic during chain setup when there is an error
22
#![allow(clippy::unwrap_used)]
33

4+
pub mod devnet;
45
pub mod finney;
56
pub mod localnet;
67
pub mod testnet;

node/src/chain_spec/testnet.rs

+6-36
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,6 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
2222
let old_state: ColdkeyHotkeys =
2323
json::from_slice(&bytes).map_err(|e| format!("Error parsing genesis file: {e}"))?;
2424

25-
let mut processed_stakes: Vec<(
26-
sp_runtime::AccountId32,
27-
Vec<(sp_runtime::AccountId32, (u64, u16))>,
28-
)> = Vec::new();
29-
for (coldkey_str, hotkeys) in old_state.stakes.iter() {
30-
let coldkey = <sr25519::Public as Ss58Codec>::from_ss58check(coldkey_str)
31-
.map_err(|e| e.to_string())?;
32-
let coldkey_account = sp_runtime::AccountId32::from(coldkey);
33-
34-
let mut processed_hotkeys: Vec<(sp_runtime::AccountId32, (u64, u16))> = Vec::new();
35-
36-
for (hotkey_str, amount_uid) in hotkeys.iter() {
37-
let (amount, uid) = amount_uid;
38-
let hotkey = <sr25519::Public as Ss58Codec>::from_ss58check(hotkey_str)
39-
.map_err(|e| e.to_string())?;
40-
let hotkey_account = sp_runtime::AccountId32::from(hotkey);
41-
42-
processed_hotkeys.push((hotkey_account, (*amount, *uid)));
43-
}
44-
45-
processed_stakes.push((coldkey_account, processed_hotkeys));
46-
}
47-
4825
let mut balances_issuance: u64 = 0;
4926
let mut processed_balances: Vec<(sp_runtime::AccountId32, u64)> = Vec::new();
5027
for (key_str, amount) in old_state.balances.iter() {
@@ -60,7 +37,7 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
6037

6138
// Give front-ends necessary data to present to users
6239
let mut properties = sc_service::Properties::new();
63-
properties.insert("tokenSymbol".into(), "TAO".into());
40+
properties.insert("tokenSymbol".into(), "testTAO".into());
6441
properties.insert("tokenDecimals".into(), 9.into());
6542
properties.insert("ss58Format".into(), 42.into());
6643

@@ -116,8 +93,8 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
11693
// Pre-funded accounts
11794
vec![],
11895
true,
119-
processed_stakes.clone(),
120-
processed_balances.clone(),
96+
vec![],
97+
processed_balances,
12198
balances_issuance,
12299
))
123100
.with_properties(properties)
@@ -128,7 +105,7 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
128105
#[allow(clippy::too_many_arguments)]
129106
fn testnet_genesis(
130107
initial_authorities: Vec<(AuraId, GrandpaId)>,
131-
_root_key: AccountId,
108+
root_key: AccountId,
132109
_endowed_accounts: Vec<AccountId>,
133110
_enable_println: bool,
134111
_stakes: Vec<(AccountId, Vec<(AccountId, (u64, u16))>)>,
@@ -138,11 +115,7 @@ fn testnet_genesis(
138115
serde_json::json!({
139116
"balances": {
140117
// Configure sudo balance
141-
"balances": vec![(
142-
<AccountId32 as Ss58Codec>::from_ss58check("5GpzQgpiAKHMWNSH3RN4GLf96GVTDct9QxYEFAY7LWcVzTbx")
143-
.unwrap(),
144-
1000000000000u128,
145-
)],
118+
"balances": vec![(root_key.clone(), 1_000_000_000_000u128)],
146119
},
147120
"aura": {
148121
"authorities": initial_authorities.iter().map(|x| (x.0.clone())).collect::<Vec<_>>(),
@@ -154,10 +127,7 @@ fn testnet_genesis(
154127
.collect::<Vec<_>>(),
155128
},
156129
"sudo": {
157-
"key": Some(
158-
<AccountId32 as Ss58Codec>::from_ss58check("5GpzQgpiAKHMWNSH3RN4GLf96GVTDct9QxYEFAY7LWcVzTbx")
159-
.unwrap(),
160-
),
130+
"key": Some(root_key),
161131
},
162132
})
163133
}

node/src/command.rs

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ impl SubstrateCli for Cli {
4343
Ok(match id {
4444
"local" => Box::new(chain_spec::localnet::localnet_config()?),
4545
"finney" => Box::new(chain_spec::finney::finney_mainnet_config()?),
46+
"devnet" => Box::new(chain_spec::devnet::devnet_config()?),
4647
"" | "test_finney" => Box::new(chain_spec::testnet::finney_testnet_config()?),
4748
path => Box::new(chain_spec::ChainSpec::from_json_file(
4849
std::path::PathBuf::from(path),

plain_spec_devnet.json

+72
Large diffs are not rendered by default.

raw_spec_devnet.json

+72
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)