Skip to content

Commit

Permalink
Merge pull request opentensor#209 from opentensor/utils/admin-pallet
Browse files Browse the repository at this point in the history
Remove old Y1 hyperparam extrinsics, limit some subnet hyperparams access
  • Loading branch information
shibshib authored Dec 12, 2023
2 parents 950593d + 2b0c3ae commit 2765fa9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 130 deletions.
18 changes: 0 additions & 18 deletions pallets/admin-utils/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,6 @@ mod benchmarks {
_(RawOrigin::Root, 1u16/*netuid*/, 10u16/*max_allowed_uids*/)/*sudo_set_min_allowed_weights*/;
}

#[benchmark]
fn sudo_set_validator_prune_len()
{
T::Subtensor::init_new_network(1u16/*netuid*/, 1u16/*tempo*/);

#[extrinsic_call]
_(RawOrigin::Root, 1u16/*netuid*/, 10u64/*prune_len*/)/*sudo_set_validator_prune_len*/;
}

#[benchmark]
fn sudo_set_scaling_law_power()
{
T::Subtensor::init_new_network(1u16/*netuid*/, 1u16/*tempo*/);

#[extrinsic_call]
_(RawOrigin::Root, 1u16/*netuid*/, 100u16/*scaling_law_power*/)/*sudo_set_scaling_law_power*/;
}

#[benchmark]
fn sudo_set_immunity_period()
{
Expand Down
52 changes: 7 additions & 45 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::sudo_set_adjustment_interval())]
pub fn sudo_set_adjustment_interval(origin: OriginFor<T>, netuid: u16, adjustment_interval: u16) -> DispatchResult
{
T::Subtensor::ensure_subnet_owner_or_root(origin, netuid)?;
ensure_root(origin)?;

ensure!(
T::Subtensor::if_subnet_exist(netuid),
Expand All @@ -228,7 +228,7 @@ pub mod pallet {
))]
pub fn sudo_set_adjustment_alpha(origin: OriginFor<T>, netuid: u16, adjustment_alpha: u64) -> DispatchResult
{
T::Subtensor::ensure_subnet_owner_or_root(origin, netuid)?;
ensure_root(origin)?;

ensure!(
T::Subtensor::if_subnet_exist(netuid),
Expand All @@ -242,44 +242,6 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(10)]
#[pallet::weight(T::WeightInfo::sudo_set_validator_prune_len())]
pub fn sudo_set_validator_prune_len(origin: OriginFor<T>, netuid: u16, validator_prune_len: u64) -> DispatchResult {
T::Subtensor::ensure_subnet_owner_or_root(origin, netuid)?;

ensure!(
T::Subtensor::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
T::Subtensor::set_validator_prune_len(netuid, validator_prune_len);
log::info!(
"ValidatorPruneLenSet( netuid: {:?} validator_prune_len: {:?} ) ",
netuid,
validator_prune_len
);
Ok(())
}

#[pallet::call_index(11)]
#[pallet::weight(T::WeightInfo::sudo_set_scaling_law_power())]
pub fn sudo_set_scaling_law_power(origin: OriginFor<T>, netuid: u16, scaling_law_power: u16) -> DispatchResult
{
T::Subtensor::ensure_subnet_owner_or_root(origin, netuid)?;

ensure!(
T::Subtensor::if_subnet_exist(netuid),
Error::<T>::NetworkDoesNotExist
);
ensure!(scaling_law_power <= 100, Error::<T>::StorageValueOutOfRange); // The scaling law power must be between 0 and 100 => 0% and 100%
T::Subtensor::set_scaling_law_power(netuid, scaling_law_power);
log::info!(
"ScalingLawPowerSet( netuid: {:?} scaling_law_power: {:?} ) ",
netuid,
scaling_law_power
);
Ok(())
}

#[pallet::call_index(12)]
#[pallet::weight(T::WeightInfo::sudo_set_max_weight_limit())]
pub fn sudo_set_max_weight_limit(origin: OriginFor<T>, netuid: u16, max_weight_limit: u16) -> DispatchResult {
Expand Down Expand Up @@ -362,7 +324,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::sudo_set_kappa())]
pub fn sudo_set_kappa(origin: OriginFor<T>, netuid: u16, kappa: u16) -> DispatchResult
{
T::Subtensor::ensure_subnet_owner_or_root(origin, netuid)?;
ensure_root(origin)?;

ensure!(
T::Subtensor::if_subnet_exist(netuid),
Expand All @@ -377,7 +339,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::sudo_set_rho())]
pub fn sudo_set_rho(origin: OriginFor<T>, netuid: u16, rho: u16) -> DispatchResult
{
T::Subtensor::ensure_subnet_owner_or_root(origin, netuid)?;
ensure_root(origin)?;

ensure!(
T::Subtensor::if_subnet_exist(netuid),
Expand Down Expand Up @@ -450,7 +412,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::sudo_set_target_registrations_per_interval())]
pub fn sudo_set_target_registrations_per_interval(origin: OriginFor<T>, netuid: u16, target_registrations_per_interval: u16) -> DispatchResult
{
T::Subtensor::ensure_subnet_owner_or_root(origin, netuid)?;
ensure_root(origin)?;

ensure!(
T::Subtensor::if_subnet_exist(netuid),
Expand Down Expand Up @@ -549,7 +511,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::sudo_set_bonds_moving_average())]
pub fn sudo_set_bonds_moving_average(origin: OriginFor<T>, netuid: u16, bonds_moving_average: u64) -> DispatchResult
{
T::Subtensor::ensure_subnet_owner_or_root(origin, netuid)?;
ensure_root(origin)?;

ensure!(
T::Subtensor::if_subnet_exist(netuid),
Expand All @@ -568,7 +530,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::sudo_set_max_registrations_per_block())]
pub fn sudo_set_max_registrations_per_block(origin: OriginFor<T>, netuid: u16, max_registrations_per_block: u16) -> DispatchResult
{
T::Subtensor::ensure_subnet_owner_or_root(origin, netuid)?;
ensure_root(origin)?;

ensure!(
T::Subtensor::if_subnet_exist(netuid),
Expand Down
66 changes: 0 additions & 66 deletions pallets/admin-utils/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,72 +286,6 @@ fn test_sudo_subnet_owner_cut() {
});
}

#[test]
fn test_sudo_validator_prune_len() {
new_test_ext().execute_with(|| {
let netuid: u16 = 1;
let to_be_set: u64 = 10;
add_network(netuid, 10, 0);
let init_value: u64 = SubtensorModule::get_validator_prune_len(netuid);
assert_eq!(
AdminUtils::sudo_set_validator_prune_len(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
netuid,
to_be_set
),
Err(DispatchError::BadOrigin.into())
);
assert_eq!(
AdminUtils::sudo_set_validator_prune_len(
<<Test as Config>::RuntimeOrigin>::root(),
netuid + 1,
to_be_set
),
Err(Error::<Test>::NetworkDoesNotExist.into())
);
assert_eq!(SubtensorModule::get_validator_prune_len(netuid), init_value);
assert_ok!(AdminUtils::sudo_set_validator_prune_len(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
to_be_set
));
assert_eq!(SubtensorModule::get_validator_prune_len(netuid), to_be_set);
});
}

#[test]
fn test_sudo_set_scaling_law_power() {
new_test_ext().execute_with(|| {
let netuid: u16 = 1;
let to_be_set: u16 = 50;
add_network(netuid, 10, 0);
let init_value: u16 = SubtensorModule::get_scaling_law_power(netuid);
assert_eq!(
AdminUtils::sudo_set_scaling_law_power(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
netuid,
to_be_set
),
Err(DispatchError::BadOrigin.into())
);
assert_eq!(
AdminUtils::sudo_set_scaling_law_power(
<<Test as Config>::RuntimeOrigin>::root(),
netuid + 1,
to_be_set
),
Err(Error::<Test>::NetworkDoesNotExist.into())
);
assert_eq!(SubtensorModule::get_scaling_law_power(netuid), init_value);
assert_ok!(AdminUtils::sudo_set_scaling_law_power(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
to_be_set
));
assert_eq!(SubtensorModule::get_scaling_law_power(netuid), to_be_set);
});
}

#[test]
fn test_sudo_set_max_weight_limit() {
new_test_ext().execute_with(|| {
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 136,
spec_version: 139,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down

0 comments on commit 2765fa9

Please sign in to comment.