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
8 changes: 4 additions & 4 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,15 +1860,15 @@ pub mod pallet {
let maybe_owner = pallet_subtensor::Pallet::<T>::ensure_sn_owner_or_root_with_limits(
origin,
netuid,
&[TransactionType::SubsubnetParameterUpdate],
&[TransactionType::SubsubnetCountUpdate],
)?;

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

pallet_subtensor::Pallet::<T>::record_owner_rl(
maybe_owner,
netuid,
&[TransactionType::SubsubnetParameterUpdate],
&[TransactionType::SubsubnetCountUpdate],
);
Ok(())
}
Expand All @@ -1886,15 +1886,15 @@ pub mod pallet {
let maybe_owner = pallet_subtensor::Pallet::<T>::ensure_sn_owner_or_root_with_limits(
origin,
netuid,
&[TransactionType::SubsubnetParameterUpdate],
&[TransactionType::SubsubnetEmission],
)?;

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

pallet_subtensor::Pallet::<T>::record_owner_rl(
maybe_owner,
netuid,
&[TransactionType::SubsubnetParameterUpdate],
&[TransactionType::SubsubnetEmission],
);
Ok(())
}
Expand Down
61 changes: 61 additions & 0 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2269,3 +2269,64 @@ fn test_sudo_set_subsubnet_count() {
));
});
}

// cargo test --package pallet-admin-utils --lib -- tests::test_sudo_set_subsubnet_count_and_emissions --exact --show-output
#[test]
fn test_sudo_set_subsubnet_count_and_emissions() {
new_test_ext().execute_with(|| {
let netuid = NetUid::from(1);
let ss_count_ok = SubId::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(
<<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
assert_noop!(
AdminUtils::sudo_set_subsubnet_emission_split(
<<Test as Config>::RuntimeOrigin>::signed(sn_owner),
netuid,
Some(vec![0xFFFF / 5 * 2, 0xFFFF / 5 * 2, 0xFFFF / 5])
),
pallet_subtensor::Error::<Test>::InvalidValue
);

// 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(
<<Test as Config>::RuntimeOrigin>::signed(sn_owner),
netuid,
Some(vec![0xFFFF / 5 * 4, 0xFFFF / 5 - 1])
),
pallet_subtensor::Error::<Test>::InvalidValue
);

// Can set good split ok
// We also verify here that it can happen in the same block as setting subsubnet counts
// or soon, without rate limiting
assert_ok!(AdminUtils::sudo_set_subsubnet_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(
<<Test as Config>::RuntimeOrigin>::signed(sn_owner),
netuid,
Some(vec![0xFFFF / 5 * 4, 0xFFFF / 5])
),
pallet_subtensor::Error::<Test>::TxRateLimitExceeded
);
});
}
7 changes: 6 additions & 1 deletion pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,12 @@ pub mod pallet {
#[pallet::type_value]
/// -- ITEM (Rate limit for subsubnet count updates)
pub fn SubsubnetCountSetRateLimit<T: Config>() -> u64 {
prod_or_fast!(7_200, 0)
prod_or_fast!(7_200, 1)
}
#[pallet::type_value]
/// -- ITEM (Rate limit for subsubnet emission distribution updates)
pub fn SubsubnetEmissionRateLimit<T: Config>() -> u64 {
prod_or_fast!(7_200, 1)
}
#[pallet::storage]
/// --- MAP ( netuid ) --> Current number of sub-subnets
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/subnets/subsubnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl<T: Config> Pallet<T> {

// Check that values add up to 65535
let total: u64 = split.iter().map(|s| *s as u64).sum();
ensure!(total <= u16::MAX as u64, Error::<T>::InvalidValue);
ensure!(total == u16::MAX as u64, Error::<T>::InvalidValue);

SubsubnetEmissionSplit::<T>::insert(netuid, split);
} else {
Expand Down
12 changes: 8 additions & 4 deletions pallets/subtensor/src/utils/rate_limiting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pub enum TransactionType {
SetWeightsVersionKey,
SetSNOwnerHotkey,
OwnerHyperparamUpdate,
SubsubnetParameterUpdate,
SubsubnetCountUpdate,
SubsubnetEmission,
}

/// Implement conversion from TransactionType to u16
Expand All @@ -26,7 +27,8 @@ impl From<TransactionType> for u16 {
TransactionType::SetWeightsVersionKey => 4,
TransactionType::SetSNOwnerHotkey => 5,
TransactionType::OwnerHyperparamUpdate => 6,
TransactionType::SubsubnetParameterUpdate => 7,
TransactionType::SubsubnetCountUpdate => 7,
TransactionType::SubsubnetEmission => 8,
}
}
}
Expand All @@ -41,7 +43,8 @@ impl From<u16> for TransactionType {
4 => TransactionType::SetWeightsVersionKey,
5 => TransactionType::SetSNOwnerHotkey,
6 => TransactionType::OwnerHyperparamUpdate,
7 => TransactionType::SubsubnetParameterUpdate,
7 => TransactionType::SubsubnetCountUpdate,
8 => TransactionType::SubsubnetEmission,
_ => TransactionType::Unknown,
}
}
Expand All @@ -57,7 +60,8 @@ impl<T: Config> Pallet<T> {
TransactionType::SetChildkeyTake => TxChildkeyTakeRateLimit::<T>::get(),
TransactionType::RegisterNetwork => NetworkRateLimit::<T>::get(),
TransactionType::OwnerHyperparamUpdate => OwnerHyperparamRateLimit::<T>::get(),
TransactionType::SubsubnetParameterUpdate => SubsubnetCountSetRateLimit::<T>::get(),
TransactionType::SubsubnetCountUpdate => SubsubnetCountSetRateLimit::<T>::get(),
TransactionType::SubsubnetEmission => SubsubnetEmissionRateLimit::<T>::get(),

TransactionType::Unknown => 0, // Default to no limit for unknown types (no limit)
_ => 0,
Expand Down
Loading