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 2 commits
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)
}

11 changes: 10 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 @@ -1555,7 +1556,15 @@ pub mod pallet {
pub fn benchmark_drain_emission( _:OriginFor<T> ) -> DispatchResult {
Self::drain_emission( 11 );
Ok(())
}
}

#[pallet::call_index(50)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing tabs and spaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually use tabs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, and if I remember correctly tabs are more accessible too, but totally not critical and just something I couldn't help notice

Note; once everyone is rebased with recent origin/main updates such things should be less of oddity due to .cargo-husky/hooks/post-commit incrementally enforcing .rustfmt.toml configurations

#[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)
}
}

// ---- 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