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
32 changes: 16 additions & 16 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub mod time {
pub const DAYS: BlockNumber = HOURS * 24;
}

#[freeze_struct("8e576b32bb1bb664")]
#[freeze_struct("7e5202d7f18b39d4")]
#[repr(transparent)]
#[derive(
Deserialize,
Expand All @@ -244,43 +244,43 @@ pub mod time {
RuntimeDebug,
)]
#[serde(transparent)]
pub struct SubId(u8);
pub struct MechId(u8);

impl SubId {
pub const MAIN: SubId = Self(0);
impl MechId {
pub const MAIN: MechId = Self(0);
}

impl From<u8> for SubId {
impl From<u8> for MechId {
fn from(value: u8) -> Self {
Self(value)
}
}

impl From<SubId> for u16 {
fn from(val: SubId) -> Self {
impl From<MechId> for u16 {
fn from(val: MechId) -> Self {
u16::from(val.0)
}
}

impl From<SubId> for u64 {
fn from(val: SubId) -> Self {
impl From<MechId> for u64 {
fn from(val: MechId) -> Self {
u64::from(val.0)
}
}

impl From<SubId> for u8 {
fn from(val: SubId) -> Self {
impl From<MechId> for u8 {
fn from(val: MechId) -> Self {
u8::from(val.0)
}
}

impl Display for SubId {
impl Display for MechId {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Display::fmt(&self.0, f)
}
}

impl CompactAs for SubId {
impl CompactAs for MechId {
type As = u8;

fn encode_as(&self) -> &Self::As {
Expand All @@ -292,13 +292,13 @@ impl CompactAs for SubId {
}
}

impl From<Compact<SubId>> for SubId {
fn from(c: Compact<SubId>) -> Self {
impl From<Compact<MechId>> for MechId {
fn from(c: Compact<MechId>) -> Self {
c.0
}
}

impl TypeInfo for SubId {
impl TypeInfo for MechId {
type Identity = <u8 as TypeInfo>::Identity;
fn type_info() -> scale_info::Type {
<u8 as TypeInfo>::type_info()
Expand Down
22 changes: 11 additions & 11 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mod pallet {
use pallet_subtensor::utils::rate_limiting::{Hyperparameter, TransactionType};
use sp_runtime::BoundedVec;
use substrate_fixed::types::I96F32;
use subtensor_runtime_common::{NetUid, SubId, TaoCurrency};
use subtensor_runtime_common::{MechId, NetUid, TaoCurrency};

/// The main data structure of the module.
#[pallet::pallet]
Expand Down Expand Up @@ -1872,54 +1872,54 @@ pub mod pallet {
Ok(())
}

/// Sets the desired number of subsubnets in a subnet
/// Sets the desired number of mechanisms in a subnet
#[pallet::call_index(76)]
#[pallet::weight(Weight::from_parts(15_000_000, 0)
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(1_u64))
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1_u64)))]
pub fn sudo_set_subsubnet_count(
pub fn sudo_set_mechanism_count(
origin: OriginFor<T>,
netuid: NetUid,
subsub_count: SubId,
mechanism_count: MechId,
) -> DispatchResult {
let maybe_owner = pallet_subtensor::Pallet::<T>::ensure_sn_owner_or_root_with_limits(
origin,
netuid,
&[TransactionType::SubsubnetCountUpdate],
&[TransactionType::MechanismCountUpdate],
)?;

pallet_subtensor::Pallet::<T>::do_set_subsubnet_count(netuid, subsub_count)?;
pallet_subtensor::Pallet::<T>::do_set_mechanism_count(netuid, mechanism_count)?;

pallet_subtensor::Pallet::<T>::record_owner_rl(
maybe_owner,
netuid,
&[TransactionType::SubsubnetCountUpdate],
&[TransactionType::MechanismCountUpdate],
);
Ok(())
}

/// Sets the emission split between subsubnets in a subnet
/// Sets the emission split between mechanisms in a subnet
#[pallet::call_index(77)]
#[pallet::weight(Weight::from_parts(15_000_000, 0)
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(1_u64))
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1_u64)))]
pub fn sudo_set_subsubnet_emission_split(
pub fn sudo_set_mechanism_emission_split(
origin: OriginFor<T>,
netuid: NetUid,
maybe_split: Option<Vec<u16>>,
) -> DispatchResult {
let maybe_owner = pallet_subtensor::Pallet::<T>::ensure_sn_owner_or_root_with_limits(
origin,
netuid,
&[TransactionType::SubsubnetEmission],
&[TransactionType::MechanismEmission],
)?;

pallet_subtensor::Pallet::<T>::do_set_emission_split(netuid, maybe_split)?;

pallet_subtensor::Pallet::<T>::record_owner_rl(
maybe_owner,
netuid,
&[TransactionType::SubsubnetEmission],
&[TransactionType::MechanismEmission],
);
Ok(())
}
Expand Down
64 changes: 32 additions & 32 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use pallet_subtensor::{Event, utils::rate_limiting::TransactionType};
use sp_consensus_grandpa::AuthorityId as GrandpaId;
use sp_core::{Get, Pair, U256, ed25519};
use substrate_fixed::types::I96F32;
use subtensor_runtime_common::{Currency, NetUid, SubId, TaoCurrency};
use subtensor_runtime_common::{Currency, MechId, NetUid, TaoCurrency};

use crate::Error;
use crate::pallet::PrecompileEnable;
Expand Down Expand Up @@ -2322,66 +2322,66 @@ fn test_sudo_set_max_burn() {
}

#[test]
fn test_sudo_set_subsubnet_count() {
fn test_sudo_set_mechanism_count() {
new_test_ext().execute_with(|| {
let netuid = NetUid::from(1);
let ss_count_ok = SubId::from(8);
let ss_count_bad = SubId::from(9);
let ss_count_ok = MaxMechanismCount::<Test>::get();
let ss_count_bad = MechId::from(u8::from(ss_count_ok) + 1);

let sn_owner = U256::from(1324);
add_network(netuid, 10);
// Set the Subnet Owner
SubnetOwner::<Test>::insert(netuid, sn_owner);

assert_eq!(
AdminUtils::sudo_set_subsubnet_count(
AdminUtils::sudo_set_mechanism_count(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
netuid,
ss_count_ok
),
Err(DispatchError::BadOrigin)
);
assert_noop!(
AdminUtils::sudo_set_subsubnet_count(RuntimeOrigin::root(), netuid, ss_count_bad),
AdminUtils::sudo_set_mechanism_count(RuntimeOrigin::root(), netuid, ss_count_bad),
pallet_subtensor::Error::<Test>::InvalidValue
);

assert_ok!(AdminUtils::sudo_set_subsubnet_count(
assert_ok!(AdminUtils::sudo_set_mechanism_count(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
ss_count_ok
));

assert_ok!(AdminUtils::sudo_set_subsubnet_count(
assert_ok!(AdminUtils::sudo_set_mechanism_count(
<<Test as Config>::RuntimeOrigin>::signed(sn_owner),
netuid,
ss_count_ok
));
});
}

// cargo test --package pallet-admin-utils --lib -- tests::test_sudo_set_subsubnet_count_and_emissions --exact --show-output
// cargo test --package pallet-admin-utils --lib -- tests::test_sudo_set_mechanism_count_and_emissions --exact --show-output
#[test]
fn test_sudo_set_subsubnet_count_and_emissions() {
fn test_sudo_set_mechanism_count_and_emissions() {
new_test_ext().execute_with(|| {
let netuid = NetUid::from(1);
let ss_count_ok = SubId::from(2);
let ss_count_ok = MechId::from(2);

let sn_owner = U256::from(1324);
add_network(netuid, 10);
// Set the Subnet Owner
SubnetOwner::<Test>::insert(netuid, sn_owner);

assert_ok!(AdminUtils::sudo_set_subsubnet_count(
assert_ok!(AdminUtils::sudo_set_mechanism_count(
<<Test as Config>::RuntimeOrigin>::signed(sn_owner),
netuid,
ss_count_ok
));

// Cannot set emission split with wrong number of entries
// With two subsubnets the size of the split vector should be 2, not 3
// With two mechanisms the size of the split vector should be 2, not 3
assert_noop!(
AdminUtils::sudo_set_subsubnet_emission_split(
AdminUtils::sudo_set_mechanism_emission_split(
<<Test as Config>::RuntimeOrigin>::signed(sn_owner),
netuid,
Some(vec![0xFFFF / 5 * 2, 0xFFFF / 5 * 2, 0xFFFF / 5])
Expand All @@ -2392,7 +2392,7 @@ fn test_sudo_set_subsubnet_count_and_emissions() {
// Cannot set emission split with wrong total of entries
// Split vector entries should sum up to exactly 0xFFFF
assert_noop!(
AdminUtils::sudo_set_subsubnet_emission_split(
AdminUtils::sudo_set_mechanism_emission_split(
<<Test as Config>::RuntimeOrigin>::signed(sn_owner),
netuid,
Some(vec![0xFFFF / 5 * 4, 0xFFFF / 5 - 1])
Expand All @@ -2401,17 +2401,17 @@ fn test_sudo_set_subsubnet_count_and_emissions() {
);

// Can set good split ok
// We also verify here that it can happen in the same block as setting subsubnet counts
// We also verify here that it can happen in the same block as setting mechanism counts
// or soon, without rate limiting
assert_ok!(AdminUtils::sudo_set_subsubnet_emission_split(
assert_ok!(AdminUtils::sudo_set_mechanism_emission_split(
<<Test as Config>::RuntimeOrigin>::signed(sn_owner),
netuid,
Some(vec![0xFFFF / 5, 0xFFFF / 5 * 4])
));

// Cannot set it again due to rate limits
assert_noop!(
AdminUtils::sudo_set_subsubnet_emission_split(
AdminUtils::sudo_set_mechanism_emission_split(
<<Test as Config>::RuntimeOrigin>::signed(sn_owner),
netuid,
Some(vec![0xFFFF / 5 * 4, 0xFFFF / 5])
Expand All @@ -2436,9 +2436,9 @@ fn test_trim_to_max_allowed_uids() {
ImmuneOwnerUidsLimit::<Test>::insert(netuid, 2);
// We set a low value here to make testing easier
MinAllowedUids::<Test>::set(netuid, 4);
// We define 4 subsubnets
let subsubnet_count = SubId::from(4);
SubsubnetCountCurrent::<Test>::insert(netuid, subsubnet_count);
// We define 4 mechanisms
let mechanism_count = MechId::from(4);
MechanismCountCurrent::<Test>::insert(netuid, mechanism_count);

// Add some neurons
let max_n = 16;
Expand Down Expand Up @@ -2480,9 +2480,9 @@ fn test_trim_to_max_allowed_uids() {
ValidatorPermit::<Test>::insert(netuid, bool_values.clone());
Active::<Test>::insert(netuid, bool_values);

for subid in 0..subsubnet_count.into() {
for mecid in 0..mechanism_count.into() {
let netuid_index =
SubtensorModule::get_subsubnet_storage_index(netuid, SubId::from(subid));
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mecid));
Incentive::<Test>::insert(netuid_index, values.clone());
LastUpdate::<Test>::insert(netuid_index, u64_values.clone());
}
Expand Down Expand Up @@ -2515,9 +2515,9 @@ fn test_trim_to_max_allowed_uids() {
}
}

for subid in 0..subsubnet_count.into() {
for mecid in 0..mechanism_count.into() {
let netuid_index =
SubtensorModule::get_subsubnet_storage_index(netuid, SubId::from(subid));
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mecid));
Weights::<Test>::insert(netuid_index, uid, weights.clone());
Bonds::<Test>::insert(netuid_index, uid, bonds.clone());
}
Expand Down Expand Up @@ -2563,9 +2563,9 @@ fn test_trim_to_max_allowed_uids() {
assert_eq!(ValidatorPermit::<Test>::get(netuid), expected_bools);
assert_eq!(StakeWeight::<Test>::get(netuid), expected_values);

for subid in 0..subsubnet_count.into() {
for mecid in 0..mechanism_count.into() {
let netuid_index =
SubtensorModule::get_subsubnet_storage_index(netuid, SubId::from(subid));
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mecid));
assert_eq!(Incentive::<Test>::get(netuid_index), expected_values);
assert_eq!(LastUpdate::<Test>::get(netuid_index), expected_u64_values);
}
Expand All @@ -2574,9 +2574,9 @@ fn test_trim_to_max_allowed_uids() {
for uid in new_max_n..max_n {
assert!(!Keys::<Test>::contains_key(netuid, uid));
assert!(!BlockAtRegistration::<Test>::contains_key(netuid, uid));
for subid in 0..subsubnet_count.into() {
for mecid in 0..mechanism_count.into() {
let netuid_index =
SubtensorModule::get_subsubnet_storage_index(netuid, SubId::from(subid));
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mecid));
assert!(!Weights::<Test>::contains_key(netuid_index, uid));
assert!(!Bonds::<Test>::contains_key(netuid_index, uid));
}
Expand Down Expand Up @@ -2610,9 +2610,9 @@ fn test_trim_to_max_allowed_uids() {

// Ensure trimmed uids weights and bonds connections have been trimmed correctly
for uid in 0..new_max_n {
for subid in 0..subsubnet_count.into() {
for mecid in 0..mechanism_count.into() {
let netuid_index =
SubtensorModule::get_subsubnet_storage_index(netuid, SubId::from(subid));
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mecid));
assert!(
Weights::<Test>::get(netuid_index, uid)
.iter()
Expand All @@ -2638,7 +2638,7 @@ fn test_trim_to_max_allowed_uids() {
NetUid::from(42),
new_max_n
),
pallet_subtensor::Error::<Test>::SubNetworkDoesNotExist
pallet_subtensor::Error::<Test>::MechanismDoesNotExist
);

// New max n less than lower bound
Expand Down
Loading
Loading