Skip to content
Open
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
18 changes: 4 additions & 14 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,27 +577,17 @@ pub mod pallet {
/// It is only callable by the root account or subnet owner.
/// The extrinsic will call the Subtensor pallet to set the kappa.
#[pallet::call_index(16)]
#[pallet::weight(Weight::from_parts(26_210_000, 0)
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(3_u64))
#[pallet::weight(Weight::from_parts(15_390_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_kappa(origin: OriginFor<T>, netuid: NetUid, kappa: u16) -> DispatchResult {
let maybe_owner = pallet_subtensor::Pallet::<T>::ensure_sn_owner_or_root_with_limits(
origin,
netuid,
&[Hyperparameter::Kappa.into()],
)?;

ensure_root(origin)?;
ensure!(
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),
Error::<T>::SubnetDoesNotExist
);
pallet_subtensor::Pallet::<T>::set_kappa(netuid, kappa);
log::debug!("KappaSet( netuid: {netuid:?} kappa: {kappa:?} ) ");
pallet_subtensor::Pallet::<T>::record_owner_rl(
maybe_owner,
netuid,
&[Hyperparameter::Kappa.into()],
);
Ok(())
}

Expand Down Expand Up @@ -1252,7 +1242,7 @@ pub mod pallet {
/// The extrinsic will call the Subtensor pallet to set the minimum delegate take.
#[pallet::call_index(46)]
#[pallet::weight((
Weight::from_parts(7_885_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)),
Weight::from_parts(7_214_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)),
DispatchClass::Operational,
Pays::Yes
))]
Expand Down
28 changes: 16 additions & 12 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,7 @@ fn test_freeze_window_blocks_root_and_owner() {
let owner: U256 = U256::from(9);
SubnetOwner::<Test>::insert(netuid, owner);
assert_noop!(
AdminUtils::sudo_set_kappa(
AdminUtils::sudo_set_commit_reveal_weights_interval(
<<Test as Config>::RuntimeOrigin>::signed(owner),
netuid,
77
Expand Down Expand Up @@ -2145,14 +2145,14 @@ fn test_owner_hyperparam_update_rate_limit_enforced() {
));

// First update succeeds
assert_ok!(AdminUtils::sudo_set_kappa(
assert_ok!(AdminUtils::sudo_set_commit_reveal_weights_interval(
<<Test as Config>::RuntimeOrigin>::signed(owner),
netuid,
11
));
// Immediate second update fails due to TxRateLimitExceeded
assert_noop!(
AdminUtils::sudo_set_kappa(
AdminUtils::sudo_set_commit_reveal_weights_interval(
<<Test as Config>::RuntimeOrigin>::signed(owner),
netuid,
12
Expand All @@ -2163,7 +2163,7 @@ fn test_owner_hyperparam_update_rate_limit_enforced() {
// Advance less than limit still fails
run_to_block(SubtensorModule::get_current_block_as_u64() + 1);
assert_noop!(
AdminUtils::sudo_set_kappa(
AdminUtils::sudo_set_commit_reveal_weights_interval(
<<Test as Config>::RuntimeOrigin>::signed(owner),
netuid,
13
Expand All @@ -2173,7 +2173,7 @@ fn test_owner_hyperparam_update_rate_limit_enforced() {

// Advance one more block to pass the limit; should succeed
run_to_block(SubtensorModule::get_current_block_as_u64() + 1);
assert_ok!(AdminUtils::sudo_set_kappa(
assert_ok!(AdminUtils::sudo_set_commit_reveal_weights_interval(
<<Test as Config>::RuntimeOrigin>::signed(owner),
netuid,
14
Expand All @@ -2200,21 +2200,25 @@ fn test_hyperparam_rate_limit_enforced_by_tempo() {
));

// First owner update should succeed
assert_ok!(AdminUtils::sudo_set_kappa(
assert_ok!(AdminUtils::sudo_set_commit_reveal_weights_interval(
<<Test as Config>::RuntimeOrigin>::signed(owner),
netuid,
1
));

// Immediate second update should fail due to tempo-based RL
assert_noop!(
AdminUtils::sudo_set_kappa(<<Test as Config>::RuntimeOrigin>::signed(owner), netuid, 2),
AdminUtils::sudo_set_commit_reveal_weights_interval(
<<Test as Config>::RuntimeOrigin>::signed(owner),
netuid,
2
),
SubtensorError::<Test>::TxRateLimitExceeded
);

// Advance 2 blocks (2 tempos with tempo=1) then succeed
run_to_block(SubtensorModule::get_current_block_as_u64() + 2);
assert_ok!(AdminUtils::sudo_set_kappa(
assert_ok!(AdminUtils::sudo_set_commit_reveal_weights_interval(
<<Test as Config>::RuntimeOrigin>::signed(owner),
netuid,
3
Expand Down Expand Up @@ -2244,15 +2248,15 @@ fn test_owner_hyperparam_rate_limit_independent_per_param() {
));

// First update to kappa should succeed
assert_ok!(AdminUtils::sudo_set_kappa(
assert_ok!(AdminUtils::sudo_set_commit_reveal_weights_interval(
<<Test as Config>::RuntimeOrigin>::signed(owner),
netuid,
10
));

// Immediate second update to the SAME param (kappa) should be blocked by RL
assert_noop!(
AdminUtils::sudo_set_kappa(
AdminUtils::sudo_set_commit_reveal_weights_interval(
<<Test as Config>::RuntimeOrigin>::signed(owner),
netuid,
11
Expand All @@ -2269,7 +2273,7 @@ fn test_owner_hyperparam_rate_limit_independent_per_param() {

// kappa should still be blocked until its own RL window passes
assert_noop!(
AdminUtils::sudo_set_kappa(
AdminUtils::sudo_set_commit_reveal_weights_interval(
<<Test as Config>::RuntimeOrigin>::signed(owner),
netuid,
12
Expand All @@ -2287,7 +2291,7 @@ fn test_owner_hyperparam_rate_limit_independent_per_param() {
run_to_block(SubtensorModule::get_current_block_as_u64() + 2);

// Now both hyperparameters can be updated again
assert_ok!(AdminUtils::sudo_set_kappa(
assert_ok!(AdminUtils::sudo_set_commit_reveal_weights_interval(
<<Test as Config>::RuntimeOrigin>::signed(owner),
netuid,
13
Expand Down
Loading