diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index ed54c0112..1cde576f5 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -997,56 +997,6 @@ pub mod pallet { Ok(()) } - /// Sets the lower bound for the alpha parameter for a given subnet. - /// - /// # Parameters - /// - `origin`: The origin of the call, which must be the root account or subnet owner. - /// - `netuid`: The unique identifier for the subnet. - /// - `alpha_low`: The new lower bound value for the alpha parameter. - /// - /// # Weight - /// This function has a fixed weight of 0 and is classified as an operational transaction that does not incur any fees. - #[pallet::call_index(50)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] - pub fn sudo_set_alpha_low( - origin: OriginFor, - netuid: u16, - alpha_low: u16, - ) -> DispatchResult { - T::Subtensor::ensure_subnet_owner_or_root(origin, netuid)?; - T::Subtensor::set_alpha_low(netuid, alpha_low)?; - log::info!( - "AlphaLowSet( netuid: {:?}, alpha_low: {:?} ) ", - netuid, - alpha_low - ); - Ok(()) - } - /// Sets the upper bound for the alpha parameter for a given subnet. - /// - /// # Parameters - /// - `origin`: The origin of the call, which must be the root account or subnet owner. - /// - `netuid`: The unique identifier for the subnet. - /// - `alpha_high`: The new upper bound value for the alpha parameter. - /// - /// # Weight - /// This function has a fixed weight of 0 and is classified as an operational transaction that does not incur any fees. - #[pallet::call_index(51)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] - pub fn sudo_set_alpha_high( - origin: OriginFor, - netuid: u16, - alpha_high: u16, - ) -> DispatchResult { - T::Subtensor::ensure_subnet_owner_or_root(origin, netuid)?; - T::Subtensor::set_alpha_high(netuid, alpha_high)?; - log::info!( - "AlphaHighSet( netuid: {:?}, alpha_high: {:?} ) ", - netuid, - alpha_high - ); - Ok(()) - } /// Enables or disables Liquid Alpha for a given subnet. /// /// # Parameters @@ -1056,7 +1006,7 @@ pub mod pallet { /// /// # Weight /// This function has a fixed weight of 0 and is classified as an operational transaction that does not incur any fees. - #[pallet::call_index(52)] + #[pallet::call_index(50)] #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_liquid_alpha_enabled( origin: OriginFor, @@ -1167,7 +1117,5 @@ pub trait SubtensorInterface { fn set_target_stakes_per_interval(target_stakes_per_interval: u64); fn set_commit_reveal_weights_interval(netuid: u16, interval: u64); fn set_commit_reveal_weights_enabled(netuid: u16, enabled: bool); - fn set_alpha_high(netuid: u16, alpha_high: u16) -> Result<(), DispatchError>; - fn set_alpha_low(netuid: u16, alpha_low: u16) -> Result<(), DispatchError>; fn set_liquid_alpha_enabled(netuid: u16, enabled: bool); } diff --git a/pallets/admin-utils/tests/mock.rs b/pallets/admin-utils/tests/mock.rs index 4945bd2b3..f7e2c543e 100644 --- a/pallets/admin-utils/tests/mock.rs +++ b/pallets/admin-utils/tests/mock.rs @@ -468,14 +468,6 @@ impl pallet_admin_utils::SubtensorInterface f SubtensorModule::set_commit_reveal_weights_enabled(netuid, enabled); } - fn set_alpha_high(netuid: u16, alpha_high: u16) -> Result<(), DispatchError> { - SubtensorModule::set_alpha_high(netuid, alpha_high) - } - - fn set_alpha_low(netuid: u16, alpha_low: u16) -> Result<(), DispatchError> { - SubtensorModule::set_alpha_low(netuid, alpha_low) - } - fn set_liquid_alpha_enabled(netuid: u16, enabled: bool) { SubtensorModule::set_liquid_alpha_enabled(netuid, enabled); } diff --git a/pallets/admin-utils/tests/tests.rs b/pallets/admin-utils/tests/tests.rs index f1842f40c..b080419ef 100644 --- a/pallets/admin-utils/tests/tests.rs +++ b/pallets/admin-utils/tests/tests.rs @@ -1180,154 +1180,6 @@ fn test_sudo_set_target_stakes_per_interval() { }); } -#[test] -fn alpha_low_can_only_be_called_by_admin() { - new_test_ext().execute_with(|| { - let netuid: u16 = 1; - let to_be_set: u16 = 52428; // 0.8 i.e. 0.8 x u16::MAX - assert_eq!( - AdminUtils::sudo_set_alpha_low( - <::RuntimeOrigin>::signed(U256::from(1)), - netuid, - to_be_set - ), - Err(DispatchError::BadOrigin) - ); - }); -} - -#[test] -fn sets_alpha_low_valid_value() { - new_test_ext().execute_with(|| { - let netuid: u16 = 1; - let to_be_set: u16 = 52428; // 0.8 i.e. 0.8 x u16::MAX - let init_value = SubtensorModule::get_alpha_low(netuid); - assert_eq!(SubtensorModule::get_alpha_low(netuid), init_value); - assert_ok!(AdminUtils::sudo_set_liquid_alpha_enabled( - <::RuntimeOrigin>::root(), - netuid, - true, - )); - assert_ok!(AdminUtils::sudo_set_alpha_low( - <::RuntimeOrigin>::root(), - netuid, - to_be_set - )); - assert_eq!(SubtensorModule::get_alpha_low(netuid), to_be_set); - }); -} - -#[test] -fn alpha_low_fails_if_liquid_alpha_disabled() { - new_test_ext().execute_with(|| { - let netuid: u16 = 1; - let to_be_set: u16 = 52428; // 0.8 i.e. 0.8 x u16::MAX - assert_eq!( - AdminUtils::sudo_set_alpha_low( - <::RuntimeOrigin>::root(), - netuid, - to_be_set - ), - Err(SubtensorError::::LiquidAlphaDisabled.into()) - ); - }); -} - -#[test] -fn alpha_low_fails_if_alpha_low_too_low() { - new_test_ext().execute_with(|| { - let netuid: u16 = 1; - let to_be_set: u16 = 0; // Invalid value - assert_ok!(AdminUtils::sudo_set_liquid_alpha_enabled( - <::RuntimeOrigin>::root(), - netuid, - true, - )); - assert_eq!( - AdminUtils::sudo_set_alpha_low( - <::RuntimeOrigin>::root(), - netuid, - to_be_set - ), - Err(SubtensorError::::AlphaLowTooLow.into()) - ); - }); -} - -#[test] -fn alpha_high_can_only_be_called_by_admin() { - new_test_ext().execute_with(|| { - let netuid: u16 = 1; - let to_be_set: u16 = 60000; // Valid value - assert_eq!( - AdminUtils::sudo_set_alpha_high( - <::RuntimeOrigin>::signed(U256::from(1)), - netuid, - to_be_set - ), - Err(DispatchError::BadOrigin) - ); - }); -} - -#[test] -fn sets_a_valid_value() { - new_test_ext().execute_with(|| { - let netuid: u16 = 1; - let to_be_set: u16 = 60000; // Valid value - let init_value = SubtensorModule::get_alpha_high(netuid); - assert_eq!(SubtensorModule::get_alpha_high(netuid), init_value); - assert_ok!(AdminUtils::sudo_set_liquid_alpha_enabled( - <::RuntimeOrigin>::root(), - netuid, - true, - )); - assert_ok!(AdminUtils::sudo_set_alpha_high( - <::RuntimeOrigin>::root(), - netuid, - to_be_set - )); - assert_eq!(SubtensorModule::get_alpha_high(netuid), to_be_set); - }); -} - -#[test] -fn alpha_high_fails_if_liquid_alpha_disabled() { - new_test_ext().execute_with(|| { - let netuid: u16 = 1; - let to_be_set: u16 = 60000; // Valid value - assert_eq!( - AdminUtils::sudo_set_alpha_high( - <::RuntimeOrigin>::root(), - netuid, - to_be_set - ), - Err(SubtensorError::::LiquidAlphaDisabled.into()) - ); - }); -} - -#[test] -fn fails_if_alpha_high_too_low() { - new_test_ext().execute_with(|| { - let netuid: u16 = 1; - let to_be_set: u16 = 50000; // Invalid value, less than 52428 - assert_ok!(AdminUtils::sudo_set_liquid_alpha_enabled( - <::RuntimeOrigin>::root(), - netuid, - true, - )); - assert_eq!( - AdminUtils::sudo_set_alpha_high( - <::RuntimeOrigin>::root(), - netuid, - to_be_set - ), - Err(SubtensorError::::AlphaHighTooLow.into()) - ); - }); -} - #[test] fn test_sudo_set_liquid_alpha_enabled() { new_test_ext().execute_with(|| { diff --git a/pallets/subtensor/src/epoch.rs b/pallets/subtensor/src/epoch.rs index e186ec496..2faae5eff 100644 --- a/pallets/subtensor/src/epoch.rs +++ b/pallets/subtensor/src/epoch.rs @@ -1082,10 +1082,8 @@ impl Pallet { log::trace!("Using Liquid Alpha"); // Get the high and low alpha values for the network. - let alpha_high = Self::get_alpha_high_32(netuid); - log::trace!("alpha_high: {:?}", alpha_high); - let alpha_low = Self::get_alpha_low_32(netuid); - log::trace!("alpha_low: {:?}", alpha_low); + let (alpha_low, alpha_high): (I32F32, I32F32) = Self::get_alpha_values_32(netuid); + log::trace!("alpha_low: {:?} alpha_high: {:?}", alpha_low, alpha_high); // Calculate the logistic function parameters 'a' and 'b' based on alpha and consensus values. let (a, b) = Self::calculate_logistic_params( @@ -1151,10 +1149,8 @@ impl Pallet { log::trace!("Using Liquid Alpha"); // Get the high and low alpha values for the network. - let alpha_high = Self::get_alpha_high_32(netuid); - log::trace!("alpha_high: {:?}", alpha_high); - let alpha_low = Self::get_alpha_low_32(netuid); - log::trace!("alpha_low: {:?}", alpha_low); + let (alpha_low, alpha_high): (I32F32, I32F32) = Self::get_alpha_values_32(netuid); + log::trace!("alpha_low: {:?} alpha_high: {:?}", alpha_low, alpha_high); // Calculate the logistic function parameters 'a' and 'b' based on alpha and consensus values. let (a, b) = Self::calculate_logistic_params( @@ -1185,4 +1181,30 @@ impl Pallet { Self::compute_ema_bonds_normal(&bonds_delta, &bonds, netuid) } } + + pub fn do_set_alpha_values(origin: T::RuntimeOrigin, netuid: u16, alpha_low: u16, alpha_high: u16) -> Result<(), DispatchError> { + // --- 1. Ensure the function caller is a signed user. + let _coldkey = ensure_signed(origin)?; + + let max_u16: u32 = u16::MAX as u32; // 65535 + let min_alpha_high: u16 = (max_u16.saturating_mul(4).saturating_div(5)) as u16; // 52428 + + // --- 2. Ensure liquid alpha is enabled + ensure!( + Self::get_liquid_alpha_enabled(netuid), + Error::::LiquidAlphaDisabled + ); + + // --- 3. Ensure alpha high is greater than the minimum + ensure!(alpha_high >= min_alpha_high, Error::::AlphaHighTooLow); + + // -- 4. Ensure alpha low is within range + ensure!( + alpha_low > 0 && alpha_low < min_alpha_high, + Error::::AlphaLowTooLow + ); + AlphaValues::::insert(netuid, (alpha_low, alpha_high)); + + Ok(()) + } } diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 711d7c8dd..da23f8572 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -866,14 +866,9 @@ pub mod pallet { /// Provides the default value for the upper bound of the alpha parameter. #[pallet::type_value] - pub fn DefaultAlphaHigh() -> u16 { - 58982 // Represents 0.9 as per the production default - } - /// Provides the default value for the lower bound of the alpha parameter. - #[pallet::type_value] - pub fn DefaultAlphaLow() -> u16 { - 45875 // Represents 0.7 as per the production default - } + pub fn DefaultAlphaValues() -> (u16, u16) { + (45875, 58982) // (alpha_low: 0.7, alpha_high: 0.9) + } #[pallet::storage] // ITEM( weights_min_stake ) pub type WeightsMinStake = StorageValue<_, u64, ValueQuery, DefaultWeightsMinStake>; @@ -944,12 +939,10 @@ pub mod pallet { #[pallet::storage] // --- DMAP ( netuid ) --> adjustment_alpha pub type AdjustmentAlpha = StorageMap<_, Identity, u16, u64, ValueQuery, DefaultAdjustmentAlpha>; - // MAP ( netuid ) --> alpha_high - #[pallet::storage] - pub type AlphaHigh = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultAlphaHigh>; - // MAP ( netuid ) --> alpha_low + + // MAP ( netuid ) --> (alpha_low, alpha_high) #[pallet::storage] - pub type AlphaLow = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultAlphaLow>; + pub type AlphaValues = StorageMap<_, Identity, u16, (u16, u16), ValueQuery, DefaultAlphaValues>; #[pallet::storage] // --- MAP (netuid, who) --> (hash, weight) | Returns the hash and weight committed by an account for a given netuid. pub type WeightCommits = StorageDoubleMap< @@ -2085,6 +2078,15 @@ pub mod pallet { pub fn dissolve_network(origin: OriginFor, netuid: u16) -> DispatchResult { Self::user_remove_network(origin, netuid) } + + /// Sets values for liquid alpha + #[pallet::call_index(88)] + #[pallet::weight((Weight::from_parts(119_000_000, 0) + .saturating_add(T::DbWeight::get().reads(0)) + .saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Operational, Pays::No))] + pub fn set_alpha_values(origin: OriginFor, netuid: u16, alpha_low: u16, alpha_high: u16) -> DispatchResult { + Self::do_set_alpha_values(origin, netuid, alpha_low, alpha_high) + } } // ---- Subtensor helper functions. diff --git a/pallets/subtensor/src/subnet_info.rs b/pallets/subtensor/src/subnet_info.rs index af09d166f..454311479 100644 --- a/pallets/subtensor/src/subnet_info.rs +++ b/pallets/subtensor/src/subnet_info.rs @@ -3,6 +3,7 @@ use frame_support::pallet_prelude::{Decode, Encode}; use frame_support::storage::IterableStorageMap; extern crate alloc; use codec::Compact; +use substrate_fixed::types::I32F32; #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] pub struct SubnetInfo { @@ -24,6 +25,7 @@ pub struct SubnetInfo { emission_values: Compact, burn: Compact, owner: T::AccountId, + alpha_values: (I32F32, I32F32), } #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] @@ -52,8 +54,6 @@ pub struct SubnetHyperparams { difficulty: Compact, commit_reveal_weights_interval: Compact, commit_reveal_weights_enabled: bool, - alpha_high: Compact, - alpha_low: Compact, liquid_alpha_enabled: bool, } @@ -104,6 +104,7 @@ impl Pallet { emission_values: emission_values.into(), burn, owner: Self::get_subnet_owner(netuid), + alpha_values: Self::get_alpha_values_32(netuid), }) } @@ -158,8 +159,6 @@ impl Pallet { let difficulty = Self::get_difficulty_as_u64(netuid); let commit_reveal_weights_interval = Self::get_commit_reveal_weights_interval(netuid); let commit_reveal_weights_enabled = Self::get_commit_reveal_weights_enabled(netuid); - let alpha_high = Self::get_alpha_high(netuid); - let alpha_low = Self::get_alpha_low(netuid); let liquid_alpha_enabled = Self::get_liquid_alpha_enabled(netuid); Some(SubnetHyperparams { @@ -187,8 +186,6 @@ impl Pallet { difficulty: difficulty.into(), commit_reveal_weights_interval: commit_reveal_weights_interval.into(), commit_reveal_weights_enabled, - alpha_high: alpha_high.into(), - alpha_low: alpha_low.into(), liquid_alpha_enabled, }) } diff --git a/pallets/subtensor/src/utils.rs b/pallets/subtensor/src/utils.rs index 9b96b0955..e97d29534 100644 --- a/pallets/subtensor/src/utils.rs +++ b/pallets/subtensor/src/utils.rs @@ -663,47 +663,16 @@ impl Pallet { NominatorMinRequiredStake::::put(min_stake); } - pub fn get_alpha_high(netuid: u16) -> u16 { - AlphaHigh::::get(netuid) + pub fn get_alpha_values(netuid: u16) -> (u16, u16) { + AlphaValues::::get(netuid) } - pub fn get_alpha_high_32(netuid: u16) -> I32F32 { - I32F32::from_num(AlphaHigh::::get(netuid)) / I32F32::from_num(u16::MAX) - } - - pub fn set_alpha_high(netuid: u16, alpha_high: u16) -> Result<(), DispatchError> { - // Ensure liquid alpha is enabled - ensure!( - Self::get_liquid_alpha_enabled(netuid), - Error::::LiquidAlphaDisabled - ); - // Ensure alpha high is greater than the minimum - ensure!(alpha_high >= 52428, Error::::AlphaHighTooLow); - AlphaHigh::::insert(netuid, alpha_high); - - Ok(()) - } - - pub fn get_alpha_low(netuid: u16) -> u16 { - AlphaLow::::get(netuid) - } + pub fn get_alpha_values_32(netuid: u16) -> (I32F32, I32F32) { + let (alpha_low, alpha_high): (u16, u16) = AlphaValues::::get(netuid); + let converted_low = I32F32::from_num(alpha_low) / I32F32::from_num(u16::MAX); + let converted_high = I32F32::from_num(alpha_high) / I32F32::from_num(u16::MAX); - pub fn get_alpha_low_32(netuid: u16) -> I32F32 { - I32F32::from_num(AlphaLow::::get(netuid)) / I32F32::from_num(u16::MAX) - } - - pub fn set_alpha_low(netuid: u16, alpha_low: u16) -> Result<(), DispatchError> { - ensure!( - Self::get_liquid_alpha_enabled(netuid), - Error::::LiquidAlphaDisabled - ); - ensure!( - alpha_low > 0 || alpha_low == 52428, - Error::::AlphaLowTooLow - ); - AlphaLow::::insert(netuid, alpha_low); - - Ok(()) + return (converted_low, converted_high); } pub fn set_liquid_alpha_enabled(netuid: u16, enabled: bool) { diff --git a/pallets/subtensor/tests/epoch.rs b/pallets/subtensor/tests/epoch.rs index 1852553d8..94a042a4f 100644 --- a/pallets/subtensor/tests/epoch.rs +++ b/pallets/subtensor/tests/epoch.rs @@ -1,5 +1,5 @@ use crate::mock::*; -use frame_support::{assert_err, assert_ok}; +use frame_support::{dispatch::{DispatchClass, GetDispatchInfo, Pays}, assert_err, assert_ok}; use frame_system::Config; use pallet_subtensor::*; use rand::{distributions::Uniform, rngs::StdRng, seq::SliceRandom, thread_rng, Rng, SeedableRng}; @@ -1482,22 +1482,18 @@ fn test_set_alpha_disabled() { new_test_ext(1).execute_with(|| { let netuid: u16 = 1; let tempo: u16 = u16::MAX - 1; + let signer: RuntimeOrigin = RuntimeOrigin::signed(U256::from(1)); add_network(netuid, tempo, 0); // Explicitly set to false SubtensorModule::set_liquid_alpha_enabled(netuid, false); assert_err!( - SubtensorModule::set_alpha_high(netuid, u16::MAX), - Error::::LiquidAlphaDisabled - ); - assert_err!( - SubtensorModule::set_alpha_low(netuid, 12_u16), + SubtensorModule::set_alpha_values(signer.clone(), netuid, 12_u16, u16::MAX), Error::::LiquidAlphaDisabled ); SubtensorModule::set_liquid_alpha_enabled(netuid, true); - assert_ok!(SubtensorModule::set_alpha_high(netuid, u16::MAX)); - assert_ok!(SubtensorModule::set_alpha_low(netuid, 12_u16)); + assert_ok!(SubtensorModule::set_alpha_values(signer.clone(), netuid, 12_u16, u16::MAX)); }); } @@ -2508,18 +2504,94 @@ fn test_compute_ema_bonds_with_liquid_alpha_sparse_empty() { } #[test] -fn test_get_alpha_low() { +fn test_get_set_alpha() { new_test_ext(1).execute_with(|| { let netuid: u16 = 1; - let alpha_low: u16 = 1000; + let alpha_low: u16 = 12_u16; + let alpha_high: u16 = u16::MAX - 10; + let signer: RuntimeOrigin = RuntimeOrigin::signed(U256::from(1)); + + // Enable liquid alpha and set alpha values SubtensorModule::set_liquid_alpha_enabled(netuid, true); - SubtensorModule::set_alpha_low(netuid, alpha_low).unwrap(); - log::info!("alpha_low: {:?}", SubtensorModule::get_alpha_low(netuid)); - assert_eq!(SubtensorModule::get_alpha_low(netuid), alpha_low); - assert_eq!( - SubtensorModule::get_alpha_low_32(netuid), - I32F32::from_num(0.015259022) + assert_ok!(SubtensorModule::set_alpha_values(signer.clone(), netuid, alpha_low, alpha_high)); + let (grabbed_alpha_low, grabbed_alpha_high): (u16, u16) = SubtensorModule::get_alpha_values(netuid); + + log::info!("alpha_low: {:?} alpha_high: {:?}", grabbed_alpha_low, grabbed_alpha_high); + assert_eq!(grabbed_alpha_low, alpha_low); + assert_eq!(grabbed_alpha_high, alpha_high); + + // Convert the u16 values to decimal values + fn unnormalize_u16_to_float(normalized_value: u16) -> f32 { + const MAX_U16: u16 = 65535; + normalized_value as f32 / MAX_U16 as f32 + } + + let alpha_low_decimal = unnormalize_u16_to_float(alpha_low); + let alpha_high_decimal = unnormalize_u16_to_float(alpha_high); + + let (alpha_low_32, alpha_high_32) = SubtensorModule::get_alpha_values_32(netuid); + + let tolerance: f32 = 1e-6; // 0.000001 + + // Check if the values are equal to the sixth decimal + assert!((alpha_low_32.to_num::() - alpha_low_decimal).abs() < tolerance, "alpha_low mismatch: {} != {}", alpha_low_32.to_num::(), alpha_low_decimal); + assert!((alpha_high_32.to_num::() - alpha_high_decimal).abs() < tolerance, "alpha_high mismatch: {} != {}", alpha_high_32.to_num::(), alpha_high_decimal); + + // Test error cases + + // 1. Liquid alpha disabled + SubtensorModule::set_liquid_alpha_enabled(netuid, false); + assert_err!( + SubtensorModule::set_alpha_values(signer.clone(), netuid, alpha_low, alpha_high), + Error::::LiquidAlphaDisabled ); + // Correct scenario after error + SubtensorModule::set_liquid_alpha_enabled(netuid, true); // Re-enable for further tests + assert_ok!(SubtensorModule::set_alpha_values(signer.clone(), netuid, alpha_low, alpha_high)); + + // 2. Alpha high too low + let alpha_high_too_low = (u16::MAX as u32 * 4 / 5) as u16 - 1; // One less than the minimum acceptable value + assert_err!( + SubtensorModule::set_alpha_values(signer.clone(), netuid, alpha_low, alpha_high_too_low), + Error::::AlphaHighTooLow + ); + // Correct scenario after error + assert_ok!(SubtensorModule::set_alpha_values(signer.clone(), netuid, alpha_low, alpha_high)); + + // 3. Alpha low too low or too high + let alpha_low_too_low = 0_u16; + assert_err!( + SubtensorModule::set_alpha_values(signer.clone(), netuid, alpha_low_too_low, alpha_high), + Error::::AlphaLowTooLow + ); + // Correct scenario after error + assert_ok!(SubtensorModule::set_alpha_values(signer.clone(), netuid, alpha_low, alpha_high)); + + let alpha_low_too_high = (u16::MAX as u32 * 4 / 5) as u16 + 1; // One more than the maximum acceptable value + assert_err!( + SubtensorModule::set_alpha_values(signer.clone(), netuid, alpha_low_too_high, alpha_high), + Error::::AlphaLowTooLow + ); + // Correct scenario after error + assert_ok!(SubtensorModule::set_alpha_values(signer.clone(), netuid, alpha_low, alpha_high)); + }); +} + +#[test] +fn test_set_alpha_values_dispatch_info_ok() { + new_test_ext(0).execute_with(|| { + let netuid: u16 = 1; + let alpha_low: u16 = 12_u16; + let alpha_high: u16 = u16::MAX - 10; + let call = RuntimeCall::SubtensorModule(SubtensorCall::set_alpha_values { + netuid, + alpha_low, + alpha_high, + }); + let dispatch_info = call.get_dispatch_info(); + + assert_eq!(dispatch_info.class, DispatchClass::Operational); + assert_eq!(dispatch_info.pays_fee, Pays::No); }); } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 7bd889de9..b77cf49c0 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1149,14 +1149,6 @@ impl SubtensorModule::set_commit_reveal_weights_enabled(netuid, enabled); } - fn set_alpha_high(netuid: u16, alpha_high: u16) -> Result<(), DispatchError> { - SubtensorModule::set_alpha_high(netuid, alpha_high) - } - - fn set_alpha_low(netuid: u16, alpha_low: u16) -> Result<(), DispatchError> { - SubtensorModule::set_alpha_low(netuid, alpha_low) - } - fn set_liquid_alpha_enabled(netuid: u16, enabled: bool) { SubtensorModule::set_liquid_alpha_enabled(netuid, enabled); }