Skip to content

Commit

Permalink
Use share pool primitive in staking utils
Browse files Browse the repository at this point in the history
  • Loading branch information
gztensor committed Jan 7, 2025
1 parent e460cbe commit d2e2b5c
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 116 deletions.
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.

1 change: 1 addition & 0 deletions pallets/subtensor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pallet-transaction-payment = { workspace = true }
pallet-utility = { workspace = true }
ndarray = { workspace = true }
hex = { workspace = true }
share-pool = { default-features = false, path = "../../primitives/share-pool" }

pallet-collective = { version = "4.0.0-dev", default-features = false, path = "../collective" }
pallet-drand = { path = "../drand", default-features = false }
Expand Down
13 changes: 10 additions & 3 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub mod pallet {
use sp_std::collections::vec_deque::VecDeque;
use sp_std::vec;
use sp_std::vec::Vec;
use substrate_fixed::types::I64F64;
use subtensor_macros::freeze_struct;

#[cfg(not(feature = "std"))]
Expand Down Expand Up @@ -712,6 +713,12 @@ pub mod pallet {
T::InitialDissolveNetworkScheduleDuration::get()
}

#[pallet::type_value]
/// Default value for Share Pool variables
pub fn DefaultSharePoolZero<T: Config>() -> I64F64 {
I64F64::from_num(0)
}

#[pallet::storage]
pub type ColdkeySwapScheduleDuration<T: Config> =
StorageValue<_, BlockNumberFor<T>, ValueQuery, DefaultColdkeySwapScheduleDuration<T>>;
Expand Down Expand Up @@ -934,9 +941,9 @@ pub mod pallet {
T::AccountId,
Identity,
u16,
u64,
I64F64,
ValueQuery,
DefaultZeroU64<T>,
DefaultSharePoolZero<T>,
>;
#[pallet::storage] // --- NMAP ( hot, cold, netuid ) --> alpha | Returns the alpha shares for a hotkey, coldkey, netuid triplet.
pub type Alpha<T: Config> = StorageNMap<
Expand All @@ -946,7 +953,7 @@ pub mod pallet {
NMapKey<Blake2_128Concat, T::AccountId>, // cold
NMapKey<Identity, u16>, // subnet
),
u64, // Shares
I64F64, // Shares
ValueQuery,
>;
#[pallet::storage] // --- DMAP ( netuid ) --> token_symbol | Returns the token symbol for a subnet.
Expand Down
3 changes: 2 additions & 1 deletion pallets/subtensor/src/macros/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ mod genesis {
Alpha::<T>::insert(
// Lock the initial funds making this key the owner.
(hotkey.clone(), hotkey.clone(), netuid),
1_000_000_000,
I64F64::from_num(1_000_000_000),
);
TotalHotkeyAlpha::<T>::insert(hotkey.clone(), netuid, 1_000_000_000);
TotalHotkeyShares::<T>::insert(hotkey.clone(), netuid, I64F64::from_num(1_000_000_000));
// TotalColdkeyAlpha::<T>::insert(hotkey.clone(), netuid, 1_000_000_000);
SubnetAlphaOut::<T>::insert(netuid, 1_000_000_000);
let mut staking_hotkeys = StakingHotkeys::<T>::get(hotkey.clone());
Expand Down
5 changes: 3 additions & 2 deletions pallets/subtensor/src/migrations/migrate_rao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use frame_support::IterableStorageMap;
use frame_support::{traits::Get, weights::Weight};
use log;
use sp_runtime::format;
use substrate_fixed::types::I64F64;

pub fn migrate_rao<T: Config>() -> Weight {
let migration_name = b"migrate_rao".to_vec();
Expand Down Expand Up @@ -41,10 +42,10 @@ pub fn migrate_rao<T: Config>() -> Weight {
});
// Set all the stake on root 0 subnet.
Alpha::<T>::mutate((hotkey.clone(), coldkey.clone(), 0), |total| {
*total = total.saturating_add(stake)
*total = total.saturating_add(I64F64::from_num(stake))
});
TotalHotkeyShares::<T>::mutate(hotkey.clone(), 0, |total| {
*total = total.saturating_add(stake)
*total = total.saturating_add(I64F64::from_num(stake))
});
// Set the total stake on the hotkey
TotalHotkeyAlpha::<T>::mutate(hotkey.clone(), 0, |total| {
Expand Down
Loading

0 comments on commit d2e2b5c

Please sign in to comment.