Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pallets/subtensor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
25 changes: 25 additions & 0 deletions pallets/subtensor/src/macros/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config> BuildGenesisConfig for GenesisConfig<T> {
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::<T>::get(), alice_account);
let subnet_root_owner_hotkey =
prod_or_fast!(DefaultSubnetOwner::<T>::get(), alice_hk_account);

// Set initial total issuance from balances
TotalIssuance::<T>::put(self.balances_issuance);

Expand All @@ -17,6 +36,12 @@ mod genesis {
// Increment the number of total networks.
TotalNetworks::<T>::mutate(|n| *n = n.saturating_add(1));

// Set the root network owner.
SubnetOwner::<T>::insert(NetUid::ROOT, subnet_root_owner);

// Set the root network owner hotkey.
SubnetOwnerHotkey::<T>::insert(NetUid::ROOT, subnet_root_owner_hotkey);

// Set the number of validators to 1.
SubnetworkN::<T>::insert(NetUid::ROOT, 0);

Expand Down
Loading