Skip to content

Commit bb73abf

Browse files
Merge branch 'development' into backport/dev_no_registration_no_emission
2 parents d3c487a + 396b035 commit bb73abf

File tree

18 files changed

+1520
-1434
lines changed

18 files changed

+1520
-1434
lines changed

Cargo.lock

Lines changed: 878 additions & 922 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ sc-consensus = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "
6565
sc-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.10.0" }
6666
sc-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.10.0" }
6767
sc-consensus-grandpa-rpc = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.10.0" }
68+
sc-chain-spec-derive = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.10.0" }
69+
sc-chain-spec = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.10.0" }
70+
sc-consensus-slots = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.10.0" }
6871
sc-executor = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.10.0" }
6972
sc-keystore = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.10.0" }
7073
sc-network = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.10.0" }

node/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ sc-consensus = { workspace = true }
4545
sc-consensus-grandpa = { workspace = true }
4646
sc-consensus-grandpa-rpc = { workspace = true }
4747
sp-consensus-grandpa = { workspace = true }
48+
sc-chain-spec-derive = { workspace = true }
49+
sc-chain-spec = { workspace = true }
50+
sc-consensus-slots = { workspace = true }
4851
sc-client-api = { workspace = true }
4952
sp-runtime = { workspace = true }
5053
sp-io = { workspace = true }

node/src/chain_spec.rs

Lines changed: 0 additions & 505 deletions
This file was deleted.

node/src/chain_spec/finney.rs

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
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 finney_mainnet_config() -> Result<ChainSpec, String> {
7+
let path: PathBuf = std::path::PathBuf::from("./snapshot.json");
8+
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
9+
10+
// We mmap the file into memory first, as this is *a lot* faster than using
11+
// `serde_json::from_reader`. See https://github.com/serde-rs/json/issues/160
12+
let file = File::open(&path)
13+
.map_err(|e| format!("Error opening genesis file `{}`: {}", path.display(), e))?;
14+
15+
// SAFETY: `mmap` is fundamentally unsafe since technically the file can change
16+
// underneath us while it is mapped; in practice it's unlikely to be a problem
17+
let bytes = unsafe {
18+
memmap2::Mmap::map(&file)
19+
.map_err(|e| format!("Error mmaping genesis file `{}`: {}", path.display(), e))?
20+
};
21+
22+
let old_state: ColdkeyHotkeys =
23+
json::from_slice(&bytes).map_err(|e| format!("Error parsing genesis file: {}", e))?;
24+
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+
48+
let mut balances_issuance: u64 = 0;
49+
let mut processed_balances: Vec<(sp_runtime::AccountId32, u64)> = Vec::new();
50+
for (key_str, amount) in old_state.balances.iter() {
51+
let key =
52+
<sr25519::Public as Ss58Codec>::from_ss58check(key_str).map_err(|e| e.to_string())?;
53+
let key_account = sp_runtime::AccountId32::from(key);
54+
55+
processed_balances.push((key_account, *amount));
56+
balances_issuance += *amount;
57+
}
58+
59+
// Give front-ends necessary data to present to users
60+
let mut properties = sc_service::Properties::new();
61+
properties.insert("tokenSymbol".into(), "TAO".into());
62+
properties.insert("tokenDecimals".into(), 9.into());
63+
properties.insert("ss58Format".into(), 13116.into());
64+
65+
Ok(ChainSpec::builder(
66+
wasm_binary,
67+
Extensions {
68+
bad_blocks: Some(HashSet::new()),
69+
..Default::default()
70+
},
71+
)
72+
.with_name("Bittensor")
73+
.with_id("bittensor")
74+
.with_chain_type(ChainType::Live)
75+
.with_genesis_config_patch(finney_genesis(
76+
// Initial PoA authorities (Validators)
77+
// aura | grandpa
78+
vec![
79+
// Keys for debug
80+
authority_keys_from_ss58(
81+
"5EJUcFbe74FDQwPsZDbRVpdDxVZQQxjoGZA9ayJqJTbcRrGf",
82+
"5GRcfchgXZjkCfqgNvfjicjJw3vVGF4Ahqon2w8RfjXwyzy4",
83+
), // key 1
84+
authority_keys_from_ss58(
85+
"5H5oVSbQxDSw1TohAvLvp9CTAua6PN4yHme19UrG4c1ojS8J",
86+
"5FAEYaHLZmLRX4XFs2SBHbLhkysbSPrcTp51w6sQNaYLa7Tu",
87+
), // key 2
88+
authority_keys_from_ss58(
89+
"5CfBazEwCAsmscGj1J9rhXess9ZXZ5qYcuZvFWii9sxT977v",
90+
"5F6LgDAenzchE5tPmFHKGueYy1rj85oB2yxvm1xyKLVvk4gy",
91+
), // key 3
92+
authority_keys_from_ss58(
93+
"5HZDvVFWH3ifx1Sx8Uaaa7oiT6U4fAKrR3LKy9r1zFnptc1z",
94+
"5GJY6A1X8KNvqHcf42Cpr5HZzG95FZVJkTHJvnHSBGgshEWn",
95+
), // key 4
96+
authority_keys_from_ss58(
97+
"5H3v2VfQmsAAgj63EDaB1ZWmruTHHkJ4kci5wkt6SwMi2VW1",
98+
"5FXVk1gEsNweTB6AvS5jAWCivXQHTcyCWXs21wHvRU5UTZtb",
99+
), // key 5
100+
authority_keys_from_ss58(
101+
"5CPhKdvHmMqRmMUrpFnvLc6GUcduVwpNHsPPEhnYQ7QXjPdz",
102+
"5GAzG6PhVvpeoZVkKupa2uZDrhwsUmk5fCHgwq95cN9s3Dvi",
103+
), // key 6
104+
authority_keys_from_ss58(
105+
"5DZTjVhqVjHyhXLhommE4jqY9w1hJEKNQWJ8p6QnUWghRYS1",
106+
"5HmGN73kkcHaKNJrSPAxwiwAiiCkztDZ1AYi4gkpv6jaWaxi",
107+
), // key 7
108+
authority_keys_from_ss58(
109+
"5ETyBUhi3uVCzsk4gyTmtf41nheH7wALqQQxbUkmRPNqEMGS",
110+
"5Cq63ca5KM5qScJYmQi7PvFPhJ6Cxr6yw6Xg9dLYoRYg33rN",
111+
), // key 8
112+
authority_keys_from_ss58(
113+
"5DUSt6KiZWxA3tsiFkv3xYSNuox6PCfhyvqqM9x7N5kuHV2S",
114+
"5FF1kun4rb5B7C3tqh23XPVDDUJ3UchnaXxJeXu1i5n8KNHp",
115+
), // key 9
116+
authority_keys_from_ss58(
117+
"5GgsDz9yixsdHxFu52SN37f6TrUtU2RwmGJejbHVmN1ERXL4",
118+
"5EZiep2gMyV2cz9x54TQDb1cuyFYYcwGRGZ7J19Ua4YSAWCZ",
119+
), // key 10
120+
authority_keys_from_ss58(
121+
"5HjhkCMa89QJbFULs8WPZBgVg8kMq5qdX1nx7CnQpZgoyKAN",
122+
"5D5DL9sru2ep3AWoHvmEUbFLirVr7tJ6BxBWH5M8j3r9kUpe",
123+
), // key 11
124+
authority_keys_from_ss58(
125+
"5F257gHitacwDGvYm2Xm7dBE882auTU8wraG6w4T3r63wh9V",
126+
"5CovRCaioWENKejfaeccDQY4vCF8kTGtZ5fwagSCeDGmiSyh",
127+
), // key 12
128+
authority_keys_from_ss58(
129+
"5CtGLbiHWs6XVgNi9nW7oqSP4D4JMot7yHYuFokidZzAP6ny",
130+
"5DSxsR9aAiq33uSYXWt4zEibx6KT6xxtFGkT9S4GLaCavgDE",
131+
), // key 13
132+
authority_keys_from_ss58(
133+
"5DeVtxyiniPzoHo4iQiLhGfhED6RP3V73B5nGSYWr5Mgt82c",
134+
"5HaWL2AvLZHwyPXofWFTEZ6jHVmUG8U9cFATggKZonN1xZjm",
135+
), // key 14
136+
authority_keys_from_ss58(
137+
"5GF4a6pQ8TQuPhdkKqugzrZSW7YnpQtB4ihouKGZsVMwoTn6",
138+
"5DaEhFN8bWjvhDxavSWFBr962qoTAMB4b51QebdRZ75VA4h2",
139+
), // key 15
140+
authority_keys_from_ss58(
141+
"5DAC8Did2NgeVfZeNmEfZuU6t7UseJNf9J68XTvhLf5yCsBZ",
142+
"5G27pyXx9ieSRCTuDoqPgTvpCynH6yhum9HiQQ1iMj3rAeaP",
143+
), // key 16
144+
authority_keys_from_ss58(
145+
"5FmxaYznqMqiorPHQgKoRQgEHN7ud4yKsJWr6FvXuS6FS6be",
146+
"5Ch5XFMKETDiiPiuhUj9TumUtgsnVG1VzQRvBykP9bRdt4km",
147+
), // key 17
148+
authority_keys_from_ss58(
149+
"5GNAkfKYmFbVRAYm1tPr1yG6bHCapaY7WKRmzkEdendDXj1j",
150+
"5EC6JjwnE11qaRnjKM85eevQFV1EoaKPPtcBRmTp1XsR7Kx3",
151+
), // key 18
152+
authority_keys_from_ss58(
153+
"5GYk3B38R9F2TEcWoqCLojqPwx6AA1TsD3EovoTgggyRdzki",
154+
"5FjdhdAxujZVev6HYqQcTB6UBAKfKFKPoftgMLenoxbNWoe2",
155+
), // key 19
156+
authority_keys_from_ss58(
157+
"5D7fthS7zBDhwi2u2JYd74t7FpQuseDkUkTuaLZoenXNpXPK",
158+
"5DhAKQ4MFg39mQAYzndzbznLGqSV4VMUJUyRXe8QPDqD5G1D",
159+
), // key 20
160+
],
161+
// Sudo account
162+
Ss58Codec::from_ss58check("5FCM3DBXWiGcwYYQtT8z4ZD93TqYpYxjaAfgv6aMStV1FTCT").unwrap(),
163+
// Pre-funded accounts
164+
vec![],
165+
true,
166+
processed_stakes.clone(),
167+
processed_balances.clone(),
168+
balances_issuance,
169+
))
170+
.with_properties(properties)
171+
.build())
172+
}
173+
174+
// Configure initial storage state for FRAME modules.
175+
#[allow(clippy::too_many_arguments)]
176+
fn finney_genesis(
177+
initial_authorities: Vec<(AuraId, GrandpaId)>,
178+
_root_key: AccountId,
179+
_endowed_accounts: Vec<AccountId>,
180+
_enable_println: bool,
181+
stakes: Vec<(AccountId, Vec<(AccountId, (u64, u16))>)>,
182+
balances: Vec<(AccountId, u64)>,
183+
balances_issuance: u64,
184+
) -> serde_json::Value {
185+
serde_json::json!({
186+
"balances": { "balances": balances.to_vec() },
187+
"aura": { "authorities": initial_authorities.iter().map(|x| (x.0.clone())).collect::<Vec<_>>() },
188+
"grandpa": { "authorities": initial_authorities
189+
.iter()
190+
.map(|x| (x.1.clone(), 1))
191+
.collect::<Vec<_>>(),
192+
},
193+
"sudo": { "key": Some(<AccountId32 as Ss58Codec>::from_ss58check("5FCM3DBXWiGcwYYQtT8z4ZD93TqYpYxjaAfgv6aMStV1FTCT").unwrap()) },
194+
"subtensor_module": {
195+
"stakes": stakes,
196+
"balances_issuance": balances_issuance,
197+
}
198+
})
199+
}

node/src/chain_spec/localnet.rs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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 localnet_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(), "TAO".into());
12+
properties.insert("tokenDecimals".into(), 9.into());
13+
properties.insert("ss58Format".into(), 13116.into());
14+
15+
Ok(ChainSpec::builder(
16+
wasm_binary,
17+
Extensions {
18+
bad_blocks: Some(HashSet::from_iter(vec![
19+
// Example bad block
20+
H256::from_str(
21+
"0xc174d485de4bc3813ac249fe078af605c74ff91d07b0a396cf75fa04f81fa312",
22+
)
23+
.unwrap(),
24+
])),
25+
..Default::default()
26+
},
27+
)
28+
.with_name("Bittensor")
29+
.with_id("bittensor")
30+
.with_chain_type(ChainType::Development)
31+
.with_genesis_config_patch(localnet_genesis(
32+
// Initial PoA authorities (Validators)
33+
// aura | grandpa
34+
vec![
35+
// Keys for debug
36+
authority_keys_from_seed("Alice"),
37+
authority_keys_from_seed("Bob"),
38+
],
39+
// Pre-funded accounts
40+
true,
41+
))
42+
.with_properties(properties)
43+
.build())
44+
}
45+
46+
fn localnet_genesis(
47+
initial_authorities: Vec<(AuraId, GrandpaId)>,
48+
_enable_println: bool,
49+
) -> serde_json::Value {
50+
let mut balances = vec![
51+
(
52+
get_account_id_from_seed::<sr25519::Public>("Alice"),
53+
1000000000000000u128,
54+
),
55+
(
56+
get_account_id_from_seed::<sr25519::Public>("Bob"),
57+
1000000000000000u128,
58+
),
59+
(
60+
get_account_id_from_seed::<sr25519::Public>("Charlie"),
61+
1000000000000000u128,
62+
),
63+
(
64+
get_account_id_from_seed::<sr25519::Public>("Dave"),
65+
2000000000000u128,
66+
),
67+
(
68+
get_account_id_from_seed::<sr25519::Public>("Eve"),
69+
2000000000000u128,
70+
),
71+
(
72+
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
73+
2000000000000u128,
74+
),
75+
];
76+
77+
// Check if the environment variable is set
78+
if let Ok(bt_wallet) = env::var("BT_DEFAULT_TOKEN_WALLET") {
79+
if let Ok(decoded_wallet) = Ss58Codec::from_ss58check(&bt_wallet) {
80+
balances.push((decoded_wallet, 1_000_000_000_000_000u128));
81+
} else {
82+
eprintln!("Invalid format for BT_DEFAULT_TOKEN_WALLET.");
83+
}
84+
}
85+
86+
let trimvirate_members: Vec<AccountId> = bounded_vec![
87+
get_account_id_from_seed::<sr25519::Public>("Alice"),
88+
get_account_id_from_seed::<sr25519::Public>("Bob"),
89+
get_account_id_from_seed::<sr25519::Public>("Charlie"),
90+
];
91+
92+
let senate_members: Vec<AccountId> = bounded_vec![
93+
get_account_id_from_seed::<sr25519::Public>("Dave"),
94+
get_account_id_from_seed::<sr25519::Public>("Eve"),
95+
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
96+
];
97+
98+
serde_json::json!({
99+
"balances": { "balances": balances },
100+
"aura": {
101+
"authorities": initial_authorities.iter().map(|x| (x.0.clone())).collect::<Vec<_>>()
102+
},
103+
"grandpa": {
104+
"authorities": initial_authorities
105+
.iter()
106+
.map(|x| (x.1.clone(), 1))
107+
.collect::<Vec<_>>()
108+
},
109+
"sudo": {
110+
"key": Some(get_account_id_from_seed::<sr25519::Public>("Alice"))
111+
},
112+
"triumvirateMembers": {
113+
"members": trimvirate_members
114+
},
115+
"senateMembers": {
116+
"members": senate_members,
117+
},
118+
})
119+
}

0 commit comments

Comments
 (0)