Skip to content

Commit

Permalink
add sudo call to set tempo. (#94)
Browse files Browse the repository at this point in the history
* add sudo call to set tempo.

* Remove old benchmarking extrinsics from runtime

---------

Co-authored-by: Cameron Fairchild <cameron@opentensor.ai>
Co-authored-by: Ayden Brewer <dalegribble@riseup.net>
  • Loading branch information
3 people committed May 30, 2023
1 parent 2e79731 commit 3b27316
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
10 changes: 10 additions & 0 deletions pallets/subtensor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,5 +593,15 @@ benchmarks! {
assert_ok!( Subtensor::<T>::do_add_network( RawOrigin::Root.into(), netuid.try_into().unwrap(), tempo.into(), modality.into()));

}: sudo_set_min_burn(RawOrigin::<AccountIdOf<T>>::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::<T>::do_add_network( RawOrigin::Root.into(), netuid.try_into().unwrap(), tempo_default.into(), modality.into()));

}: sudo_set_tempo(RawOrigin::<AccountIdOf<T>>::Root, netuid, tempo)
}

15 changes: 12 additions & 3 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,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
RAORecycledForRegistrationSet( u16, u64 ), // Event created when setting the RAO recycled for registration.
}

Expand Down Expand Up @@ -1548,12 +1549,20 @@ pub mod pallet {
pub fn sudo_set_total_issuance(origin: OriginFor<T>, total_issuance: u64 ) -> DispatchResult {
Self::do_set_total_issuance(origin, total_issuance)
}

#[pallet::call_index(50)]

#[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<T>, netuid: u16, tempo: u16) -> DispatchResult {
Self::do_sudo_set_tempo(origin, netuid, tempo)
}

#[pallet::call_index(48)]
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
pub fn sudo_set_rao_recycled(origin: OriginFor<T>, netuid: u16, rao_recycled: u64 ) -> DispatchResult {
Self::do_set_rao_recycled(origin, netuid, rao_recycled)
}
}
}

// ---- Subtensor helper functions.
Expand Down
13 changes: 13 additions & 0 deletions pallets/subtensor/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,19 @@ impl<T: Config> Pallet<T> {
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::<T>::NetworkDoesNotExist);
ensure!( Self::if_tempo_is_valid( tempo ), Error::<T>::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::<T>::put( total_issuance );
Expand Down

0 comments on commit 3b27316

Please sign in to comment.