Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ pub mod pallet {
netuid: u16,
difficulty: u64,
) -> DispatchResult {
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin, netuid)?;
ensure_root(origin)?;
ensure!(
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),
Error::<T>::SubnetDoesNotExist
Expand Down
12 changes: 12 additions & 0 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,18 @@ fn test_sudo_set_difficulty() {
to_be_set
));
assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), to_be_set);

// Test that SN owner can't set difficulty
pallet_subtensor::SubnetOwner::<Test>::insert(netuid, U256::from(1));
assert_eq!(
AdminUtils::sudo_set_difficulty(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
netuid,
init_value
),
Err(DispatchError::BadOrigin)
);
assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), to_be_set); // no change
});
}

Expand Down
4 changes: 3 additions & 1 deletion pallets/subtensor/src/macros/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ mod hooks {
// Upgrade identities to V2
.saturating_add(migrations::migrate_identities_v2::migrate_identities_to_v2::<T>())
// Set the min burn across all subnets to a new minimum
.saturating_add(migrations::migrate_set_min_burn::migrate_set_min_burn::<T>());
.saturating_add(migrations::migrate_set_min_burn::migrate_set_min_burn::<T>())
// Set the min difficulty across all subnets to a new minimum
.saturating_add(migrations::migrate_set_min_difficulty::migrate_set_min_difficulty::<T>());
weight
}

Expand Down
52 changes: 52 additions & 0 deletions pallets/subtensor/src/migrations/migrate_set_min_difficulty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use alloc::string::String;

use frame_support::IterableStorageMap;
use frame_support::{traits::Get, weights::Weight};

use super::*;

pub fn migrate_set_min_difficulty<T: Config>() -> Weight {
let migration_name = b"migrate_set_min_difficulty".to_vec();

// Initialize the weight with one read operation.
let mut weight = T::DbWeight::get().reads(1);

// Check if the migration has already run
if HasMigrationRun::<T>::get(&migration_name) {
log::info!(
"Migration '{:?}' has already run. Skipping.",
migration_name
);
return weight;
}
log::info!(
"Running migration '{}'",
String::from_utf8_lossy(&migration_name)
);

let netuids: Vec<u16> = <NetworksAdded<T> as IterableStorageMap<u16, bool>>::iter()
.map(|(netuid, _)| netuid)
.collect();
weight = weight.saturating_add(T::DbWeight::get().reads(netuids.len() as u64));

for netuid in netuids.iter().clone() {
if *netuid == 0 {
continue;
}
// Set min difficulty to 10 million for all subnets
Pallet::<T>::set_min_difficulty(*netuid, 10_000_000);
weight = weight.saturating_add(T::DbWeight::get().writes(1));
}

// Mark the migration as completed
HasMigrationRun::<T>::insert(&migration_name, true);
weight = weight.saturating_add(T::DbWeight::get().writes(1));

log::info!(
"Migration '{:?}' completed.",
String::from_utf8_lossy(&migration_name)
);

// Return the migration weight.
weight
}
1 change: 1 addition & 0 deletions pallets/subtensor/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod migrate_populate_owned_hotkeys;
pub mod migrate_populate_staking_hotkeys;
pub mod migrate_rao;
pub mod migrate_set_min_burn;
pub mod migrate_set_min_difficulty;
pub mod migrate_stake_threshold;
pub mod migrate_subnet_volume;
pub mod migrate_to_v1_separate_emission;
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 236,
spec_version: 237,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
Loading