diff --git a/Cargo.lock b/Cargo.lock index 78c1f9d102..296ae30919 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10677,6 +10677,7 @@ dependencies = [ "share-pool", "sp-core", "sp-io", + "sp-keyring", "sp-runtime", "sp-std", "sp-tracing", diff --git a/pallets/subtensor/Cargo.toml b/pallets/subtensor/Cargo.toml index 281f226683..fdd5e5f9ab 100644 --- a/pallets/subtensor/Cargo.toml +++ b/pallets/subtensor/Cargo.toml @@ -42,6 +42,7 @@ approx.workspace = true subtensor-swap-interface.workspace = true runtime-common.workspace = true subtensor-runtime-common = { workspace = true, features = ["approx"] } +sp-keyring.workspace = true pallet-drand.workspace = true pallet-commitments.workspace = true @@ -105,6 +106,7 @@ std = [ "sp-std/std", "sp-tracing/std", "sp-version/std", + "sp-keyring/std", "subtensor-runtime-common/std", "pallet-commitments/std", "pallet-crowdloan/std", diff --git a/pallets/subtensor/src/macros/genesis.rs b/pallets/subtensor/src/macros/genesis.rs index 9d830e36ad..7bf8ba2a53 100644 --- a/pallets/subtensor/src/macros/genesis.rs +++ b/pallets/subtensor/src/macros/genesis.rs @@ -4,10 +4,29 @@ use frame_support::pallet_macros::pallet_section; /// 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); @@ -17,6 +36,12 @@ mod genesis { // 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);