From cd1678d64e25c8a4757bc581a31045c674350f5c Mon Sep 17 00:00:00 2001 From: SaMotlagh Date: Wed, 29 Mar 2023 19:00:56 -0400 Subject: [PATCH 1/2] add sudo call to set tempo. --- pallets/subtensor/src/benchmarks.rs | 10 ++++++++++ pallets/subtensor/src/lib.rs | 8 +++++++- pallets/subtensor/src/utils.rs | 13 +++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index b1b5ef92f3..df6775e7a1 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -661,5 +661,15 @@ benchmarks! { assert_ok!( Subtensor::::do_add_network( RawOrigin::Root.into(), netuid.try_into().unwrap(), tempo.into(), modality.into())); }: sudo_set_min_burn(RawOrigin::>::Root, netuid, min_burn) + + benchmark_sudo_set_tempo { + let netuid: u16 = 1; + let tempo_default: u16 = 1; + let tempo: u16 = 15; + let modality: u16 = 0; + + assert_ok!( Subtensor::::do_add_network( RawOrigin::Root.into(), netuid.try_into().unwrap(), tempo_default.into(), modality.into())); + + }: sudo_set_tempo(RawOrigin::>::Root, netuid, tempo) } diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index ce476cb161..e6af03b6b5 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -564,6 +564,7 @@ pub mod pallet { MaxBurnSet( u16, u64 ), // --- Event created when setting max burn on a network. MinBurnSet( u16, u64 ), // --- Event created when setting min burn on a network. TxRateLimitSet( u64 ), // --- Event created when setting the transaction rate limit. + TempoSet(u16, u16), // --- Event created when setting tempo on a network } // Errors inform users that something went wrong. @@ -1449,13 +1450,18 @@ pub mod pallet { pub fn sudo_set_max_registrations_per_block(origin: OriginFor, netuid: u16, max_registrations_per_block: u16 ) -> DispatchResult { Self::do_sudo_set_max_registrations_per_block(origin, netuid, max_registrations_per_block ) } + #[pallet::weight((Weight::from_ref_time(15_000_000) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] + pub fn sudo_set_tempo(origin:OriginFor, netuid: u16, tempo: u16) -> DispatchResult { + Self::do_sudo_set_tempo(origin, netuid, tempo) + } #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_total_issuance(origin: OriginFor, total_issuance: u64 ) -> DispatchResult { Self::do_set_total_issuance(origin, total_issuance) } - // Benchmarking functions. #[pallet::weight((0, DispatchClass::Normal, Pays::No))] pub fn create_network( _: OriginFor, netuid: u16, n: u16, tempo: u16 ) -> DispatchResult { diff --git a/pallets/subtensor/src/utils.rs b/pallets/subtensor/src/utils.rs index 65106a9521..81e3b7df2a 100644 --- a/pallets/subtensor/src/utils.rs +++ b/pallets/subtensor/src/utils.rs @@ -476,6 +476,19 @@ impl Pallet { Self::deposit_event( Event::MaxRegistrationsPerBlockSet( netuid, max_registrations_per_block) ); Ok(()) } + pub fn do_sudo_set_tempo ( + origin: T::RuntimeOrigin, + netuid: u16, + tempo: u16 + ) -> DispatchResult { + ensure_root( origin )?; + ensure!(Self::if_subnet_exist(netuid), Error::::NetworkDoesNotExist); + ensure!( Self::if_tempo_is_valid( tempo ), Error::::InvalidTempo ); + Self::set_tempo(netuid, tempo); + log::info!("TempoSet( netuid: {:?} tempo: {:?} ) ", netuid, tempo ); + Self::deposit_event( Event::TempoSet(netuid, tempo) ); + Ok(()) + } pub fn do_set_total_issuance(origin: T::RuntimeOrigin, total_issuance: u64) -> DispatchResult{ ensure_root( origin )?; TotalIssuance::::put( total_issuance ); From d77fad0b233c20863b5819d1236e1e32821f8611 Mon Sep 17 00:00:00 2001 From: Rubberbandits Date: Tue, 30 May 2023 17:01:12 +0000 Subject: [PATCH 2/2] Remove old benchmarking extrinsics from runtime --- pallets/subtensor/src/lib.rs | 39 ++++-------------------------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 6f996c26f1..31bb2aa89a 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -1549,51 +1549,20 @@ pub mod pallet { pub fn sudo_set_total_issuance(origin: OriginFor, total_issuance: u64 ) -> DispatchResult { Self::do_set_total_issuance(origin, total_issuance) } - - #[pallet::call_index(47)] - #[pallet::weight((Weight::from_ref_time(49_882_000_000) - .saturating_add(T::DbWeight::get().reads(8303)) - .saturating_add(T::DbWeight::get().writes(110)), DispatchClass::Normal, Pays::No))] - pub fn benchmark_epoch_with_weights( _:OriginFor ) -> DispatchResult { - ensure!( cfg!(feature = "runtime-benchmarks"), Error::::BenchmarkingOnly ); - - Self::epoch( 11, 1_000_000_000 ); - Ok(()) - } - - #[pallet::call_index(48)] - #[pallet::weight((Weight::from_ref_time(117_586_465_000 as u64) - .saturating_add(T::DbWeight::get().reads(12299 as u64)) - .saturating_add(T::DbWeight::get().writes(110 as u64)), DispatchClass::Normal, Pays::No))] - pub fn benchmark_epoch_without_weights( _:OriginFor ) -> DispatchResult { - ensure!( cfg!(feature = "runtime-benchmarks"), Error::::BenchmarkingOnly ); - - let _: Vec<(T::AccountId, u64)> = Self::epoch( 11, 1_000_000_000 ); - Ok(()) - } - - #[pallet::call_index(49)] - #[pallet::weight((0, DispatchClass::Normal, Pays::No))] - pub fn benchmark_drain_emission( _:OriginFor ) -> DispatchResult { - ensure!( cfg!(feature = "runtime-benchmarks"), Error::::BenchmarkingOnly ); - - Self::drain_emission( 11 ); - Ok(()) - } - #[pallet::call_index(50)] - #[pallet::weight((Weight::from_ref_time(15_000_000) + #[pallet::call_index(47)] + #[pallet::weight((Weight::from_ref_time(15_000_000) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] pub fn sudo_set_tempo(origin:OriginFor, netuid: u16, tempo: u16) -> DispatchResult { Self::do_sudo_set_tempo(origin, netuid, tempo) } - #[pallet::call_index(51)] + #[pallet::call_index(48)] #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_rao_recycled(origin: OriginFor, netuid: u16, rao_recycled: u64 ) -> DispatchResult { Self::do_set_rao_recycled(origin, netuid, rao_recycled) - } + } } // ---- Subtensor helper functions.