Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sudo call to set tempo. #94

Merged
merged 5 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pallets/subtensor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,5 +661,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)
}

8 changes: 7 additions & 1 deletion pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1449,13 +1450,18 @@ pub mod pallet {
pub fn sudo_set_max_registrations_per_block(origin: OriginFor<T>, 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<T>, 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<T>, 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<T>, netuid: u16, n: u16, tempo: u16 ) -> DispatchResult {
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