Skip to content

Commit

Permalink
Merge branch 'devnet-ready' into feat/roman/no-purge-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-opentensor authored Jul 24, 2024
2 parents 562b19e + af50dd6 commit 7b04c49
Show file tree
Hide file tree
Showing 68 changed files with 7,489 additions and 8,748 deletions.
16 changes: 16 additions & 0 deletions pallets/admin-utils/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,21 @@ mod benchmarks {
_(RawOrigin::Root, 1u16/*netuid*/, true/*enabled*/)/*set_commit_reveal_weights_enabled*/;
}

#[benchmark]
fn sudo_set_hotkey_emission_tempo() {
T::Subtensor::init_new_network(1u16 /*netuid*/, 1u16 /*sudo_tempo*/);

#[extrinsic_call]
_(RawOrigin::Root, 1u64/*emission_tempo*/)/*set_hotkey_emission_tempo*/;
}

#[benchmark]
fn sudo_set_network_max_stake() {
T::Subtensor::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/);

#[extrinsic_call]
_(RawOrigin::Root, 1u16/*netuid*/, 1_000_000_000_000_000u64/*max_stake*/)/*sudo_set_network_max_stake*/;
}

//impl_benchmark_test_suite!(AdminUtils, crate::mock::new_test_ext(), crate::mock::Test);
}
83 changes: 83 additions & 0 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,87 @@ pub mod pallet {
T::Subtensor::ensure_subnet_owner_or_root(origin.clone(), netuid)?;
T::Subtensor::do_set_alpha_values(origin, netuid, alpha_low, alpha_high)
}

/// Sets the hotkey emission tempo.
///
/// This extrinsic allows the root account to set the hotkey emission tempo, which determines
/// the number of blocks before a hotkey drains accumulated emissions through to nominator staking accounts.
///
/// # Arguments
/// * `origin` - The origin of the call, which must be the root account.
/// * `emission_tempo` - The new emission tempo value to set.
///
/// # Emits
/// * `Event::HotkeyEmissionTempoSet` - When the hotkey emission tempo is successfully set.
///
/// # Errors
/// * `DispatchError::BadOrigin` - If the origin is not the root account.
// #[pallet::weight(T::WeightInfo::sudo_set_hotkey_emission_tempo())]
#[pallet::call_index(52)]
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
pub fn sudo_set_hotkey_emission_tempo(
origin: OriginFor<T>,
emission_tempo: u64,
) -> DispatchResult {
ensure_root(origin)?;
T::Subtensor::set_hotkey_emission_tempo(emission_tempo);
log::info!(
"HotkeyEmissionTempoSet( emission_tempo: {:?} )",
emission_tempo
);
Ok(())
}

/// Sets the maximum stake allowed for a specific network.
///
/// This function allows the root account to set the maximum stake for a given network.
/// It updates the network's maximum stake value and logs the change.
///
/// # Arguments
///
/// * `origin` - The origin of the call, which must be the root account.
/// * `netuid` - The unique identifier of the network.
/// * `max_stake` - The new maximum stake value to set.
///
/// # Returns
///
/// Returns `Ok(())` if the operation is successful, or an error if it fails.
///
/// # Example
///
///
/// # Notes
///
/// - This function can only be called by the root account.
/// - The `netuid` should correspond to an existing network.
///
/// # TODO
///
// - Consider adding a check to ensure the `netuid` corresponds to an existing network.
// - Implement a mechanism to gradually adjust the max stake to prevent sudden changes.
// #[pallet::weight(T::WeightInfo::sudo_set_network_max_stake())]
#[pallet::call_index(53)]
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
pub fn sudo_set_network_max_stake(
origin: OriginFor<T>,
netuid: u16,
max_stake: u64,
) -> DispatchResult {
// Ensure the call is made by the root account
ensure_root(origin)?;

// Set the new maximum stake for the specified network
T::Subtensor::set_network_max_stake(netuid, max_stake);

// Log the change
log::trace!(
"NetworkMaxStakeSet( netuid: {:?}, max_stake: {:?} )",
netuid,
max_stake
);

Ok(())
}
}
}

Expand Down Expand Up @@ -1137,4 +1218,6 @@ pub trait SubtensorInterface<AccountId, Balance, RuntimeOrigin> {
alpha_low: u16,
alpha_high: u16,
) -> Result<(), DispatchError>;
fn set_hotkey_emission_tempo(emission_tempo: u64);
fn set_network_max_stake(netuid: u16, max_stake: u64);
}
1 change: 0 additions & 1 deletion pallets/admin-utils/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ pub trait WeightInfo {
fn sudo_set_tempo() -> Weight;
fn sudo_set_commit_reveal_weights_interval() -> Weight;
fn sudo_set_commit_reveal_weights_enabled() -> Weight;

}

/// Weights for `pallet_admin_utils` using the Substrate node and recommended hardware.
Expand Down
13 changes: 11 additions & 2 deletions pallets/admin-utils/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ parameter_types! {
pub const InitialAlphaHigh: u16 = 58982; // Represents 0.9 as per the production default
pub const InitialAlphaLow: u16 = 45875; // Represents 0.7 as per the production default
pub const InitialLiquidAlphaOn: bool = false; // Default value for LiquidAlphaOn
pub const InitialBaseDifficulty: u64 = 10_000; // Base difficulty
pub const InitialHotkeyEmissionTempo: u64 = 1;
pub const InitialNetworkMaxStake: u64 = 500_000_000_000_000; // 500_000 TAO
}

impl pallet_subtensor::Config for Test {
Expand Down Expand Up @@ -170,7 +171,8 @@ impl pallet_subtensor::Config for Test {
type AlphaHigh = InitialAlphaHigh;
type AlphaLow = InitialAlphaLow;
type LiquidAlphaOn = InitialLiquidAlphaOn;
type InitialBaseDifficulty = InitialBaseDifficulty;
type InitialHotkeyEmissionTempo = InitialHotkeyEmissionTempo;
type InitialNetworkMaxStake = InitialNetworkMaxStake;
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
Expand Down Expand Up @@ -477,6 +479,13 @@ impl pallet_admin_utils::SubtensorInterface<AccountId, Balance, RuntimeOrigin> f
fn set_liquid_alpha_enabled(netuid: u16, enabled: bool) {
SubtensorModule::set_liquid_alpha_enabled(netuid, enabled);
}
fn set_hotkey_emission_tempo(emission_tempo: u64) {
SubtensorModule::set_hotkey_emission_tempo(emission_tempo)
}
fn set_network_max_stake(netuid: u16, max_stake: u64) {
SubtensorModule::set_network_max_stake(netuid, max_stake)
}

fn do_set_alpha_values(
origin: RuntimeOrigin,
netuid: u16,
Expand Down
4 changes: 2 additions & 2 deletions pallets/admin-utils/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use frame_support::{
use frame_system::Config;
use pallet_admin_utils::Error;
use pallet_subtensor::Error as SubtensorError;
use pallet_subtensor::{migration, Event};
use pallet_subtensor::{migrations, Event};
use sp_core::U256;

mod mock;
Expand Down Expand Up @@ -1232,7 +1232,7 @@ fn test_sudo_get_set_alpha() {

// Enable Liquid Alpha and setup
SubtensorModule::set_liquid_alpha_enabled(netuid, true);
migration::migrate_create_root_network::<Test>();
migrations::migrate_create_root_network::migrate_create_root_network::<Test>();
SubtensorModule::add_balance_to_coldkey_account(&coldkey, 1_000_000_000_000_000);
assert_ok!(SubtensorModule::root_register(signer.clone(), hotkey,));
assert_ok!(SubtensorModule::add_stake(signer.clone(), hotkey, 1000));
Expand Down
Loading

0 comments on commit 7b04c49

Please sign in to comment.