diff --git a/pallets/admin-utils/src/benchmarking.rs b/pallets/admin-utils/src/benchmarking.rs index d10f36f7fe..7e6e17dd5c 100644 --- a/pallets/admin-utils/src/benchmarking.rs +++ b/pallets/admin-utils/src/benchmarking.rs @@ -12,13 +12,13 @@ use frame_benchmarking::v2::*; use frame_support::BoundedVec; use frame_system::RawOrigin; use pallet_subtensor::SubnetworkN; -use subtensor_runtime_common::NetUid; use super::*; #[benchmarks] mod benchmarks { use super::*; + use subtensor_runtime_common::NetUid; #[benchmark] fn swap_authorities(a: Linear<0, 32>) { @@ -420,6 +420,187 @@ mod benchmarks { _(RawOrigin::Root, 5u16/*version*/)/*sudo_set_commit_reveal_version()*/; } + #[benchmark] + fn sudo_set_tx_rate_limit() { + #[extrinsic_call] + _(RawOrigin::Root, 100u64); + } + + #[benchmark] + fn sudo_set_total_issuance() { + #[extrinsic_call] + _(RawOrigin::Root, 100u64.into()); + } + + #[benchmark] + fn sudo_set_rao_recycled() { + let netuid = NetUid::from(1); + pallet_subtensor::Pallet::::init_new_network( + netuid, 1u16, // tempo + ); + + #[extrinsic_call] + _(RawOrigin::Root, netuid, 100u64.into()); + } + + #[benchmark] + fn sudo_set_stake_threshold() { + #[extrinsic_call] + _(RawOrigin::Root, 100u64); + } + + #[benchmark] + fn sudo_set_nominator_min_required_stake() { + #[extrinsic_call] + _(RawOrigin::Root, 100u64); + } + + #[benchmark] + fn sudo_set_tx_delegate_take_rate_limit() { + #[extrinsic_call] + _(RawOrigin::Root, 100u64); + } + + #[benchmark] + fn sudo_set_min_delegate_take() { + #[extrinsic_call] + _(RawOrigin::Root, 100u16); + } + + #[benchmark] + fn sudo_set_liquid_alpha_enabled() { + let netuid = NetUid::from(1); + pallet_subtensor::Pallet::::set_admin_freeze_window(0); + pallet_subtensor::Pallet::::init_new_network( + netuid, 1u16, // tempo + ); + + #[extrinsic_call] + _(RawOrigin::Root, netuid, true); + } + + #[benchmark] + fn sudo_set_alpha_values() { + let netuid = NetUid::from(1); + pallet_subtensor::Pallet::::set_admin_freeze_window(0); + pallet_subtensor::Pallet::::init_new_network( + netuid, 1u16, // tempo + ); + pallet_subtensor::Pallet::::set_liquid_alpha_enabled(netuid, true); + + #[extrinsic_call] + _(RawOrigin::Root, netuid, 2000u16, 3000u16); + } + + #[benchmark] + fn sudo_set_coldkey_swap_schedule_duration() { + #[extrinsic_call] + _(RawOrigin::Root, 100u32.into()); + } + + #[benchmark] + fn sudo_set_dissolve_network_schedule_duration() { + #[extrinsic_call] + _(RawOrigin::Root, 100u32.into()); + } + + #[benchmark] + fn sudo_set_toggle_transfer() { + let netuid = NetUid::from(1); + pallet_subtensor::Pallet::::set_admin_freeze_window(0); + pallet_subtensor::Pallet::::init_new_network( + netuid, 1u16, // tempo + ); + + #[extrinsic_call] + _(RawOrigin::Root, netuid, true); + } + + #[benchmark] + fn sudo_toggle_evm_precompile() { + #[extrinsic_call] + _(RawOrigin::Root, PrecompileEnum::Staking, true); + } + + #[benchmark] + fn sudo_set_subnet_moving_alpha() { + #[extrinsic_call] + _(RawOrigin::Root, 100u64.into()); + } + + #[benchmark] + fn sudo_set_ema_price_halving_period() { + let netuid = NetUid::from(1); + + pallet_subtensor::Pallet::::init_new_network( + netuid, 1u16, // tempo + ); + + #[extrinsic_call] + _(RawOrigin::Root, netuid, 100u64); + } + + #[benchmark] + fn sudo_set_alpha_sigmoid_steepness() { + let netuid = NetUid::from(1); + pallet_subtensor::Pallet::::set_admin_freeze_window(0); + pallet_subtensor::Pallet::::init_new_network( + netuid, 1u16, // tempo + ); + + #[extrinsic_call] + _(RawOrigin::Root, netuid, 100i16); + } + + #[benchmark] + fn sudo_set_yuma3_enabled() { + let netuid = NetUid::from(1); + pallet_subtensor::Pallet::::set_admin_freeze_window(0); + pallet_subtensor::Pallet::::init_new_network( + netuid, 1u16, // tempo + ); + + #[extrinsic_call] + _(RawOrigin::Root, netuid, true); + } + + #[benchmark] + fn sudo_set_bonds_reset_enabled() { + let netuid = NetUid::from(1); + pallet_subtensor::Pallet::::set_admin_freeze_window(0); + pallet_subtensor::Pallet::::init_new_network( + netuid, 1u16, // tempo + ); + + #[extrinsic_call] + _(RawOrigin::Root, netuid, true); + } + + #[benchmark] + fn sudo_set_sn_owner_hotkey() { + let netuid = NetUid::from(1); + let hotkey: T::AccountId = account("Alice", 0, 1); + + pallet_subtensor::Pallet::::init_new_network( + netuid, 1u16, // tempo + ); + + #[extrinsic_call] + _(RawOrigin::Root, netuid, hotkey); + } + + #[benchmark] + fn sudo_set_subtoken_enabled() { + let netuid = NetUid::from(1); + pallet_subtensor::Pallet::::set_admin_freeze_window(0); + pallet_subtensor::Pallet::::init_new_network( + netuid, 1u16, // tempo + ); + + #[extrinsic_call] + _(RawOrigin::Root, netuid, true); + } + #[benchmark] fn sudo_set_admin_freeze_window() { #[extrinsic_call] diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 7d8a97ba98..9295978495 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -204,7 +204,12 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the transaction rate limit. #[pallet::call_index(2)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + #[pallet::weight( + (Weight::from_parts(5_400_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Operational, + Pays::Yes) + )] pub fn sudo_set_tx_rate_limit(origin: OriginFor, tx_rate_limit: u64) -> DispatchResult { ensure_root(origin)?; pallet_subtensor::Pallet::::set_tx_rate_limit(tx_rate_limit); @@ -366,7 +371,7 @@ pub mod pallet { /// It is only callable by the root account, not changeable by the subnet owner. /// The extrinsic will call the Subtensor pallet to set the adjustment interval. #[pallet::call_index(8)] - #[pallet::weight(Weight::from_parts(15_100_000, 0) + #[pallet::weight(Weight::from_parts(21_320_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_adjustment_interval( @@ -673,7 +678,7 @@ pub mod pallet { .saturating_add(::DbWeight::get().reads(0)) .saturating_add(::DbWeight::get().writes(1)), DispatchClass::Operational, - Pays::No + Pays::Yes ))] pub fn sudo_set_network_registration_allowed( origin: OriginFor, @@ -729,7 +734,7 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the target registrations per interval. #[pallet::call_index(21)] - #[pallet::weight(Weight::from_parts(25_860_000, 0) + #[pallet::weight(Weight::from_parts(44_320_000, 0) .saturating_add(::DbWeight::get().reads(3_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_target_registrations_per_interval( @@ -996,7 +1001,7 @@ pub mod pallet { Weight::from_parts(14_000_000, 0) .saturating_add(::DbWeight::get().writes(1)), DispatchClass::Operational, - Pays::No + Pays::Yes ))] pub fn sudo_set_subnet_owner_cut( origin: OriginFor, @@ -1016,7 +1021,7 @@ pub mod pallet { Weight::from_parts(14_000_000, 0) .saturating_add(::DbWeight::get().writes(1)), DispatchClass::Operational, - Pays::No + Pays::Yes ))] pub fn sudo_set_network_rate_limit( origin: OriginFor, @@ -1050,7 +1055,12 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the issuance for the network. #[pallet::call_index(33)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + #[pallet::weight(( + Weight::from_parts(2_875_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Operational, + Pays::Yes + ))] pub fn sudo_set_total_issuance( origin: OriginFor, total_issuance: TaoCurrency, @@ -1070,7 +1080,7 @@ pub mod pallet { Weight::from_parts(14_000_000, 0) .saturating_add(::DbWeight::get().writes(1)), DispatchClass::Operational, - Pays::No + Pays::Yes ))] pub fn sudo_set_network_immunity_period( origin: OriginFor, @@ -1093,7 +1103,7 @@ pub mod pallet { Weight::from_parts(14_000_000, 0) .saturating_add(::DbWeight::get().writes(1)), DispatchClass::Operational, - Pays::No + Pays::Yes ))] pub fn sudo_set_network_min_lock_cost( origin: OriginFor, @@ -1133,7 +1143,7 @@ pub mod pallet { Weight::from_parts(14_000_000, 0) .saturating_add(::DbWeight::get().writes(1)), DispatchClass::Operational, - Pays::No + Pays::Yes ))] pub fn sudo_set_lock_reduction_interval( origin: OriginFor, @@ -1152,7 +1162,13 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the recycled RAO. #[pallet::call_index(39)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + #[pallet::weight(( + Weight::from_parts(15_060_000, 4045) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Operational, + Pays::Yes + ))] pub fn sudo_set_rao_recycled( origin: OriginFor, netuid: NetUid, @@ -1171,7 +1187,11 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the weights min stake. #[pallet::call_index(42)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + #[pallet::weight(( + Weight::from_parts(5_000_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Operational, + Pays::Yes + ))] pub fn sudo_set_stake_threshold(origin: OriginFor, min_stake: u64) -> DispatchResult { ensure_root(origin)?; pallet_subtensor::Pallet::::set_stake_threshold(min_stake); @@ -1182,7 +1202,13 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the minimum stake required for nominators. #[pallet::call_index(43)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + #[pallet::weight(( + Weight::from_parts(28_050_000, 6792) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Operational, + Pays::Yes + ))] pub fn sudo_set_nominator_min_required_stake( origin: OriginFor, // The minimum stake required for nominators. @@ -1204,7 +1230,11 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the rate limit for delegate take transactions. #[pallet::call_index(45)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + #[pallet::weight(( + Weight::from_parts(5_019_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Operational, + Pays::Yes + ))] pub fn sudo_set_tx_delegate_take_rate_limit( origin: OriginFor, tx_rate_limit: u64, @@ -1221,7 +1251,11 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the minimum delegate take. #[pallet::call_index(46)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + #[pallet::weight(( + Weight::from_parts(5_000_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Operational, + Pays::Yes + ))] pub fn sudo_set_min_delegate_take(origin: OriginFor, take: u16) -> DispatchResult { ensure_root(origin)?; pallet_subtensor::Pallet::::set_min_delegate_take(take); @@ -1272,7 +1306,12 @@ 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(50)] - #[pallet::weight((1_000_000, DispatchClass::Normal, Pays::Yes))] // TODO: add proper weights + #[pallet::weight(( + Weight::from_parts(18_300_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Normal, + Pays::Yes + ))] pub fn sudo_set_liquid_alpha_enabled( origin: OriginFor, netuid: NetUid, @@ -1295,7 +1334,13 @@ pub mod pallet { /// Sets values for liquid alpha #[pallet::call_index(51)] - #[pallet::weight((1_000_000, DispatchClass::Normal, Pays::Yes))] // TODO: add proper weights + #[pallet::weight(( + Weight::from_parts(25_280_000, 4089) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Normal, + Pays::Yes + ))] pub fn sudo_set_alpha_values( origin: OriginFor, netuid: NetUid, @@ -1335,7 +1380,12 @@ pub mod pallet { /// # Weight /// Weight is handled by the `#[pallet::weight]` attribute. #[pallet::call_index(54)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + #[pallet::weight(( + Weight::from_parts(5_000_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Operational, + Pays::Yes + ))] pub fn sudo_set_coldkey_swap_schedule_duration( origin: OriginFor, duration: BlockNumberFor, @@ -1367,7 +1417,12 @@ pub mod pallet { /// # Weight /// Weight is handled by the `#[pallet::weight]` attribute. #[pallet::call_index(55)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + #[pallet::weight(( + Weight::from_parts(5_000_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Operational, + Pays::Yes + ))] pub fn sudo_set_dissolve_network_schedule_duration( origin: OriginFor, duration: BlockNumberFor, @@ -1495,7 +1550,12 @@ 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(61)] - #[pallet::weight((1_000_000, DispatchClass::Normal, Pays::Yes))] // TODO: add proper weights + #[pallet::weight(( + Weight::from_parts(20_460_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Normal, + Pays::Yes + ))] pub fn sudo_set_toggle_transfer( origin: OriginFor, netuid: NetUid, @@ -1562,7 +1622,12 @@ pub mod pallet { /// # Weight /// Weight is handled by the `#[pallet::weight]` attribute. #[pallet::call_index(62)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + #[pallet::weight(( + Weight::from_parts(6_392_000, 3507) + .saturating_add(T::DbWeight::get().reads(1_u64)), + DispatchClass::Operational, + Pays::Yes + ))] pub fn sudo_toggle_evm_precompile( origin: OriginFor, precompile_id: PrecompileEnum, @@ -1591,7 +1656,12 @@ pub mod pallet { /// # Weight /// Weight is handled by the `#[pallet::weight]` attribute. #[pallet::call_index(63)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + #[pallet::weight(( + Weight::from_parts(3_000_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Operational, + Pays::Yes + ))] pub fn sudo_set_subnet_moving_alpha(origin: OriginFor, alpha: I96F32) -> DispatchResult { ensure_root(origin)?; pallet_subtensor::SubnetMovingAlpha::::set(alpha); @@ -1638,7 +1708,12 @@ pub mod pallet { /// # Weight /// Weight is handled by the `#[pallet::weight]` attribute. #[pallet::call_index(65)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + #[pallet::weight(( + Weight::from_parts(3_918_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Operational, + Pays::Yes + ))] pub fn sudo_set_ema_price_halving_period( origin: OriginFor, netuid: NetUid, @@ -1669,7 +1744,13 @@ pub mod pallet { /// # Weight /// Weight is handled by the `#[pallet::weight]` attribute. #[pallet::call_index(68)] - #[pallet::weight((1_000_000, DispatchClass::Normal, Pays::Yes))] // TODO: add proper weights + #[pallet::weight(( + Weight::from_parts(23_140_000, 4045) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Normal, + Pays::Yes + ))] pub fn sudo_set_alpha_sigmoid_steepness( origin: OriginFor, netuid: NetUid, @@ -1713,7 +1794,12 @@ 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(69)] - #[pallet::weight((1_000_000, DispatchClass::Normal, Pays::Yes))] // TODO: add proper weights + #[pallet::weight(( + Weight::from_parts(20_460_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Normal, + Pays::Yes + ))] pub fn sudo_set_yuma3_enabled( origin: OriginFor, netuid: NetUid, @@ -1746,7 +1832,12 @@ 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(70)] - #[pallet::weight((1_000_000, DispatchClass::Normal, Pays::Yes))] // TODO: add proper weights + #[pallet::weight(( + Weight::from_parts(22_340_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Normal, + Pays::Yes + ))] pub fn sudo_set_bonds_reset_enabled( origin: OriginFor, netuid: NetUid, @@ -1800,7 +1891,13 @@ pub mod pallet { /// # Rate Limiting /// This function is rate-limited to one call per subnet per interval (e.g., one week). #[pallet::call_index(67)] - #[pallet::weight((1_000_000, DispatchClass::Normal, Pays::Yes))] // TODO: add proper weights + #[pallet::weight(( + Weight::from_parts(20_570_000, 4204) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)), + DispatchClass::Normal, + Pays::Yes + ))] pub fn sudo_set_sn_owner_hotkey( origin: OriginFor, netuid: NetUid, @@ -1822,7 +1919,12 @@ pub mod pallet { /// # Weight /// Weight is handled by the `#[pallet::weight]` attribute. #[pallet::call_index(66)] - #[pallet::weight((0, DispatchClass::Operational, Pays::No))] + #[pallet::weight(( + Weight::from_parts(17_980_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)), + DispatchClass::Operational, + Pays::Yes + ))] pub fn sudo_set_subtoken_enabled( origin: OriginFor, netuid: NetUid, @@ -1844,7 +1946,7 @@ pub mod pallet { .saturating_add(::DbWeight::get().writes(1)) .saturating_add(::DbWeight::get().reads(0_u64)), DispatchClass::Operational, - Pays::No + Pays::Yes ))] pub fn sudo_set_commit_reveal_version( origin: OriginFor, diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 233284a2c6..8c6a77c98b 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -1553,13 +1553,8 @@ impl Pallet { alpha_low: u16, alpha_high: u16, ) -> Result<(), DispatchError> { - // --- 1. Ensure the function caller is a signed user. - ensure_signed(origin.clone())?; - - // --- 2. Ensure the function caller is the subnet owner or root. Self::ensure_subnet_owner_or_root(origin, netuid)?; - // --- 3. Ensure liquid alpha is enabled ensure!( Self::get_liquid_alpha_enabled(netuid), Error::::LiquidAlphaDisabled @@ -1569,10 +1564,8 @@ impl Pallet { let min_alpha_low: u16 = (max_u16.safe_div(40)) as u16; // 1638 let min_alpha_high: u16 = min_alpha_low; - // --- 4. Ensure alpha high is greater than the minimum ensure!(alpha_high >= min_alpha_high, Error::::AlphaHighTooLow); - // -- 5. Ensure alpha low is within range ensure!( alpha_low >= min_alpha_low && alpha_low <= alpha_high, Error::::AlphaLowOutOfRange