|
| 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 | +} |
0 commit comments