use frame_support::pallet_macros::pallet_section; /// A [`pallet_section`] that defines the errors for a pallet. /// This can later be imported into the pallet using [`import_section`]. #[pallet_section] mod genesis { use sp_core::crypto::Pair; use sp_core::sr25519::Pair as Sr25519Pair; #[pallet::genesis_build] impl BuildGenesisConfig for GenesisConfig { fn build(&self) { // Alice's public key let alice_bytes = sp_keyring::Sr25519Keyring::Alice.public(); // Create Alice's hotkey from seed string let pair = Sr25519Pair::from_string("//Alice_hk", None) .expect("Alice hotkey pair should be valid"); let alice_hk_bytes = pair.public().0; let alice_account = T::AccountId::decode(&mut &alice_bytes[..]).expect("Alice account should decode"); let alice_hk_account = T::AccountId::decode(&mut &alice_hk_bytes[..]) .expect("Alice hotkey account should decode"); let subnet_root_owner = prod_or_fast!(DefaultSubnetOwner::::get(), alice_account); let subnet_root_owner_hotkey = prod_or_fast!(DefaultSubnetOwner::::get(), alice_hk_account); // Set initial total issuance from balances TotalIssuance::::put(self.balances_issuance); // Set start call delay if provided in genesis config if let Some(delay) = self.start_call_delay { StartCallDelay::::put(delay); } // Set the root network as added. NetworksAdded::::insert(NetUid::ROOT, true); // Increment the number of total networks. TotalNetworks::::mutate(|n| *n = n.saturating_add(1)); // Set the root network owner. SubnetOwner::::insert(NetUid::ROOT, subnet_root_owner); // Set the root network owner hotkey. SubnetOwnerHotkey::::insert(NetUid::ROOT, subnet_root_owner_hotkey); // Set the number of validators to 1. SubnetworkN::::insert(NetUid::ROOT, 0); // Set the maximum number to the number of senate members. MaxAllowedUids::::insert(NetUid::ROOT, 64u16); // Set the maximum number to the number of validators to all members. MaxAllowedValidators::::insert(NetUid::ROOT, 64u16); // Set the min allowed weights to zero, no weights restrictions. MinAllowedWeights::::insert(NetUid::ROOT, 0); // Add default root tempo. Tempo::::insert(NetUid::ROOT, 100); // Set the root network as open. NetworkRegistrationAllowed::::insert(NetUid::ROOT, true); // Set target registrations for validators as 1 per block. TargetRegistrationsPerInterval::::insert(NetUid::ROOT, 1); // Set token symbol for root TokenSymbol::::insert( NetUid::ROOT, Pallet::::get_symbol_for_subnet(NetUid::ROOT), ); let netuid = NetUid::from(1); let hotkey = DefaultAccount::::get(); SubnetMechanism::::insert(netuid, 1); // Make dynamic. Owner::::insert(hotkey.clone(), hotkey.clone()); SubnetAlphaIn::::insert(netuid, AlphaBalance::from(10_000_000_000_u64)); SubnetTAO::::insert(netuid, TaoBalance::from(10_000_000_000_u64)); NetworksAdded::::insert(netuid, true); TotalNetworks::::mutate(|n| *n = n.saturating_add(1)); SubnetworkN::::insert(netuid, 0); MaxAllowedUids::::insert(netuid, 256u16); MaxAllowedValidators::::insert(netuid, 64u16); MinAllowedWeights::::insert(netuid, 0); Tempo::::insert(netuid, 100); NetworkRegistrationAllowed::::insert(netuid, true); SubnetOwner::::insert(netuid, hotkey.clone()); SubnetLocked::::insert(netuid, TaoBalance::from(1)); LargestLocked::::insert(netuid, 1); AlphaV2::::insert( // Lock the initial funds making this key the owner. (hotkey.clone(), hotkey.clone(), netuid), SafeFloat::from(1_000_000_000), ); TotalHotkeyAlpha::::insert( hotkey.clone(), netuid, AlphaBalance::from(1_000_000_000), ); TotalHotkeySharesV2::::insert( hotkey.clone(), netuid, SafeFloat::from(1_000_000_000), ); SubnetAlphaOut::::insert(netuid, AlphaBalance::from(1_000_000_000)); let mut staking_hotkeys = StakingHotkeys::::get(hotkey.clone()); if !staking_hotkeys.contains(&hotkey) { staking_hotkeys.push(hotkey.clone()); StakingHotkeys::::insert(hotkey.clone(), staking_hotkeys.clone()); } let block_number = Pallet::::get_current_block_as_u64(); SubnetworkN::::insert(netuid, 1); Active::::mutate(netuid, |v| v.push(true)); Emission::::mutate(netuid, |v| v.push(0.into())); Consensus::::mutate(netuid, |v| v.push(PerU16::zero())); Incentive::::mutate(NetUidStorageIndex::from(netuid), |v| v.push(PerU16::zero())); Dividends::::mutate(netuid, |v| v.push(PerU16::zero())); LastUpdate::::mutate(NetUidStorageIndex::from(netuid), |v| v.push(block_number)); ValidatorTrust::::mutate(netuid, |v| v.push(PerU16::zero())); ValidatorPermit::::mutate(netuid, |v| v.push(false)); Keys::::insert(netuid, 0, hotkey.clone()); // Make hotkey - uid association. Uids::::insert(netuid, hotkey.clone(), 0); // Make uid - hotkey association. BlockAtRegistration::::insert(netuid, 0, block_number); // Fill block at registration. IsNetworkMember::::insert(hotkey.clone(), netuid, true); // Fill network is member. TokenSymbol::::insert(netuid, Pallet::::get_symbol_for_subnet(netuid)); } } }