From 2a9de2295e485f8c3362b0ef4baad49c96aa6383 Mon Sep 17 00:00:00 2001 From: Greg Zaitsev Date: Thu, 14 Aug 2025 16:25:09 -0400 Subject: [PATCH 1/8] Migration for root TAO counters --- .../migrate_fix_root_tao_and_alpha_in.rs | 53 +++++++++++++++++++ pallets/subtensor/src/migrations/mod.rs | 1 + pallets/subtensor/src/tests/migration.rs | 41 +++++++++++++- 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 pallets/subtensor/src/migrations/migrate_fix_root_tao_and_alpha_in.rs diff --git a/pallets/subtensor/src/migrations/migrate_fix_root_tao_and_alpha_in.rs b/pallets/subtensor/src/migrations/migrate_fix_root_tao_and_alpha_in.rs new file mode 100644 index 0000000000..8ebd8fd44a --- /dev/null +++ b/pallets/subtensor/src/migrations/migrate_fix_root_tao_and_alpha_in.rs @@ -0,0 +1,53 @@ +use super::migrate_init_total_issuance::migrate_init_total_issuance; +use super::*; +use alloc::string::String; + +pub fn migrate_fix_root_tao_and_alpha_in() -> Weight { + let migration_name = b"migrate_fix_root_tao_and_alpha_in".to_vec(); + let mut weight = T::DbWeight::get().reads(1); + + if HasMigrationRun::::get(&migration_name) { + log::info!( + "Migration '{:?}' has already run. Skipping.", + String::from_utf8_lossy(&migration_name) + ); + return weight; + } + + log::info!( + "Running migration '{}'", + String::from_utf8_lossy(&migration_name) + ); + + // Update counters + SubnetTAO::::mutate(NetUid::ROOT, |amount| { + *amount = amount.saturating_add(TaoCurrency::from(100_000_000_000)); + }); + SubnetAlphaIn::::mutate(NetUid::ROOT, |amount| { + *amount = amount.saturating_add(AlphaCurrency::from(100_000_000_000)); + }); + SubnetAlphaOut::::mutate(NetUid::ROOT, |amount| { + *amount = amount.saturating_add(AlphaCurrency::from(100_000_000_000)); + }); + SubnetVolume::::mutate(NetUid::ROOT, |amount| { + *amount = amount.saturating_add(100_000_000_000_u128); + }); + TotalStake::::mutate(|amount| { + *amount = amount.saturating_add(TaoCurrency::from(100_000_000_000)); + }); + + weight = weight.saturating_add(T::DbWeight::get().writes(5)); + + HasMigrationRun::::insert(&migration_name, true); + weight = weight.saturating_add(T::DbWeight::get().writes(1)); + + log::info!( + target: "runtime", + "Migration '{}' completed successfully.", + String::from_utf8_lossy(&migration_name) + ); + + // We need to run the total issuance migration to update the total issuance + // when the root subnet TAO has been updated. + migrate_init_total_issuance::().saturating_add(weight) +} diff --git a/pallets/subtensor/src/migrations/mod.rs b/pallets/subtensor/src/migrations/mod.rs index cdf142357b..ee23bd2e43 100644 --- a/pallets/subtensor/src/migrations/mod.rs +++ b/pallets/subtensor/src/migrations/mod.rs @@ -14,6 +14,7 @@ pub mod migrate_delete_subnet_3; pub mod migrate_disable_commit_reveal; pub mod migrate_fix_is_network_member; pub mod migrate_fix_root_subnet_tao; +pub mod migrate_fix_root_tao_and_alpha_in; pub mod migrate_identities_v2; pub mod migrate_init_total_issuance; pub mod migrate_orphaned_storage_items; diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index e62dacf89e..743f4dc5f3 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -64,7 +64,7 @@ fn test_migration_transfer_nets_to_foundation() { add_network(11.into(), 1, 0); log::info!("{:?}", SubtensorModule::get_subnet_owner(1.into())); - //assert_eq!(SubtensorModule::::get_subnet_owner(1), ); + //assert_eq!(SubtensorModule::::get_subnet_owner(1), ); // Run the migration to transfer ownership let hex = @@ -862,6 +862,45 @@ fn test_migrate_fix_root_subnet_tao() { }); } +// cargo test --package pallet-subtensor --lib -- tests::migration::test_migrate_fix_root_tao_and_alpha_in --exact --show-output +#[test] +fn test_migrate_fix_root_tao_and_alpha_in() { + new_test_ext(1).execute_with(|| { + const MIGRATION_NAME: &str = "migrate_fix_root_tao_and_alpha_in"; + + // Set counters initially + let initial_value = 1_000_000_000_000; + SubnetTAO::::insert(NetUid::ROOT, TaoCurrency::from(initial_value)); + SubnetAlphaIn::::insert(NetUid::ROOT, AlphaCurrency::from(initial_value)); + SubnetAlphaOut::::insert(NetUid::ROOT, AlphaCurrency::from(initial_value)); + SubnetVolume::::insert(NetUid::ROOT, initial_value as u128); + TotalStake::::set(TaoCurrency::from(initial_value)); + + assert!( + !HasMigrationRun::::get(MIGRATION_NAME.as_bytes().to_vec()), + "Migration should not have run yet" + ); + + // Run the migration + let weight = + crate::migrations::migrate_fix_root_tao_and_alpha_in::migrate_fix_root_tao_and_alpha_in::(); + + // Verify the migration ran correctly + assert!( + HasMigrationRun::::get(MIGRATION_NAME.as_bytes().to_vec()), + "Migration should be marked as run" + ); + assert!(!weight.is_zero(), "Migration weight should be non-zero"); + + // Verify counters have changed + assert!(SubnetTAO::::get(NetUid::ROOT) != initial_value.into()); + assert!(SubnetAlphaIn::::get(NetUid::ROOT) != initial_value.into()); + assert!(SubnetAlphaOut::::get(NetUid::ROOT) != initial_value.into()); + assert!(SubnetVolume::::get(NetUid::ROOT) != initial_value as u128); + assert!(TotalStake::::get() != initial_value.into()); + }); +} + #[test] fn test_migrate_subnet_symbols() { new_test_ext(1).execute_with(|| { From 3dab531be14a264a8140b7f20ee47c85ab39533a Mon Sep 17 00:00:00 2001 From: Greg Zaitsev Date: Thu, 14 Aug 2025 16:27:13 -0400 Subject: [PATCH 2/8] fmt --- pallets/subtensor/src/tests/migration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index 743f4dc5f3..f0a12dd5dd 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -862,7 +862,7 @@ fn test_migrate_fix_root_subnet_tao() { }); } -// cargo test --package pallet-subtensor --lib -- tests::migration::test_migrate_fix_root_tao_and_alpha_in --exact --show-output +// cargo test --package pallet-subtensor --lib -- tests::migration::test_migrate_fix_root_tao_and_alpha_in --exact --show-output #[test] fn test_migrate_fix_root_tao_and_alpha_in() { new_test_ext(1).execute_with(|| { From 742e23448a07af96704cbafc22ce0ec1a61cf5fe Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 14 Aug 2025 22:34:35 +0000 Subject: [PATCH 3/8] auto-update benchmark weights --- pallets/admin-utils/src/lib.rs | 58 ++++++++-------- pallets/commitments/src/lib.rs | 4 +- pallets/drand/src/lib.rs | 4 +- pallets/subtensor/src/macros/dispatches.rs | 80 +++++++++++----------- 4 files changed, 73 insertions(+), 73 deletions(-) diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index a8d0a080b5..e739890e47 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -161,7 +161,7 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Aura pallet to change the authorities. #[pallet::call_index(0)] - #[pallet::weight(Weight::from_parts(3_071_000, 0) + #[pallet::weight(Weight::from_parts(4_741_000, 0) .saturating_add(::DbWeight::get().reads(0_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn swap_authorities( @@ -182,7 +182,7 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the default take. #[pallet::call_index(1)] - #[pallet::weight(Weight::from_parts(3_590_000, 0) + #[pallet::weight(Weight::from_parts(5_290_000, 0) .saturating_add(::DbWeight::get().reads(0_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_default_take(origin: OriginFor, default_take: u16) -> DispatchResult { @@ -208,7 +208,7 @@ pub mod pallet { /// It is only callable by the root account or subnet owner. /// The extrinsic will call the Subtensor pallet to set the serving rate limit. #[pallet::call_index(3)] - #[pallet::weight(Weight::from_parts(4_470_000, 0) + #[pallet::weight(Weight::from_parts(6_301_000, 0) .saturating_add(::DbWeight::get().reads(0_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_serving_rate_limit( @@ -227,7 +227,7 @@ pub mod pallet { /// It is only callable by the root account or subnet owner. /// The extrinsic will call the Subtensor pallet to set the minimum difficulty. #[pallet::call_index(4)] - #[pallet::weight(Weight::from_parts(12_140_000, 0) + #[pallet::weight(Weight::from_parts(15_230_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_min_difficulty( @@ -252,7 +252,7 @@ pub mod pallet { /// It is only callable by the root account or subnet owner. /// The extrinsic will call the Subtensor pallet to set the maximum difficulty. #[pallet::call_index(5)] - #[pallet::weight(Weight::from_parts(12_840_000, 0) + #[pallet::weight(Weight::from_parts(15_530_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_max_difficulty( @@ -277,7 +277,7 @@ pub mod pallet { /// It is only callable by the root account or subnet owner. /// The extrinsic will call the Subtensor pallet to set the weights version key. #[pallet::call_index(6)] - #[pallet::weight(Weight::from_parts(12_560_000, 0) + #[pallet::weight(Weight::from_parts(15_630_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_weights_version_key( @@ -325,7 +325,7 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the weights set rate limit. #[pallet::call_index(7)] - #[pallet::weight(Weight::from_parts(12_230_000, 0) + #[pallet::weight(Weight::from_parts(15_690_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_weights_set_rate_limit( @@ -353,7 +353,7 @@ pub mod pallet { /// It is only callable by the root account, not changeable by the subnet owner. /// The extrinsic will call the Subtensor pallet to set the adjustment interval. #[pallet::call_index(8)] - #[pallet::weight(Weight::from_parts(12_200_000, 0) + #[pallet::weight(Weight::from_parts(15_350_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_adjustment_interval( @@ -405,7 +405,7 @@ pub mod pallet { /// It is only callable by the root account or subnet owner. /// The extrinsic will call the Subtensor pallet to set the adjustment beta. #[pallet::call_index(12)] - #[pallet::weight(Weight::from_parts(12_210_000, 0) + #[pallet::weight(Weight::from_parts(15_590_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_max_weight_limit( @@ -430,7 +430,7 @@ pub mod pallet { /// It is only callable by the root account or subnet owner. /// The extrinsic will call the Subtensor pallet to set the immunity period. #[pallet::call_index(13)] - #[pallet::weight(Weight::from_parts(12_330_000, 0) + #[pallet::weight(Weight::from_parts(15_440_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_immunity_period( @@ -455,7 +455,7 @@ pub mod pallet { /// It is only callable by the root account or subnet owner. /// The extrinsic will call the Subtensor pallet to set the minimum allowed weights. #[pallet::call_index(14)] - #[pallet::weight(Weight::from_parts(12_200_000, 0) + #[pallet::weight(Weight::from_parts(15_070_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_min_allowed_weights( @@ -480,7 +480,7 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the maximum allowed UIDs for a subnet. #[pallet::call_index(15)] - #[pallet::weight(Weight::from_parts(15_500_000, 0) + #[pallet::weight(Weight::from_parts(20_040_000, 0) .saturating_add(::DbWeight::get().reads(2_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_max_allowed_uids( @@ -508,7 +508,7 @@ pub mod pallet { /// It is only callable by the root account or subnet owner. /// The extrinsic will call the Subtensor pallet to set the kappa. #[pallet::call_index(16)] - #[pallet::weight(Weight::from_parts(12_530_000, 0) + #[pallet::weight(Weight::from_parts(15_240_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_kappa(origin: OriginFor, netuid: NetUid, kappa: u16) -> DispatchResult { @@ -527,7 +527,7 @@ pub mod pallet { /// It is only callable by the root account or subnet owner. /// The extrinsic will call the Subtensor pallet to set the rho. #[pallet::call_index(17)] - #[pallet::weight(Weight::from_parts(10_160_000, 0) + #[pallet::weight(Weight::from_parts(12_890_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_rho(origin: OriginFor, netuid: NetUid, rho: u16) -> DispatchResult { @@ -546,7 +546,7 @@ pub mod pallet { /// It is only callable by the root account or subnet owner. /// The extrinsic will call the Subtensor pallet to set the activity cutoff. #[pallet::call_index(18)] - #[pallet::weight(Weight::from_parts(14_160_000, 0) + #[pallet::weight(Weight::from_parts(17_800_000, 0) .saturating_add(::DbWeight::get().reads(2_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_activity_cutoff( @@ -578,7 +578,7 @@ pub mod pallet { /// The extrinsic will call the Subtensor pallet to set the network registration allowed. #[pallet::call_index(19)] #[pallet::weight(( - Weight::from_parts(4_600_000, 0) + Weight::from_parts(8_445_000, 0) .saturating_add(::DbWeight::get().reads(0)) .saturating_add(::DbWeight::get().writes(1)), DispatchClass::Operational, @@ -631,7 +631,7 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the target registrations per interval. #[pallet::call_index(21)] - #[pallet::weight(Weight::from_parts(12_400_000, 0) + #[pallet::weight(Weight::from_parts(15_320_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_target_registrations_per_interval( @@ -659,7 +659,7 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the minimum burn. #[pallet::call_index(22)] - #[pallet::weight(Weight::from_parts(12_590_000, 0) + #[pallet::weight(Weight::from_parts(16_660_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_min_burn( @@ -682,7 +682,7 @@ pub mod pallet { /// It is only callable by the root account or subnet owner. /// The extrinsic will call the Subtensor pallet to set the maximum burn. #[pallet::call_index(23)] - #[pallet::weight(Weight::from_parts(12_420_000, 0) + #[pallet::weight(Weight::from_parts(18_200_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_max_burn( @@ -705,7 +705,7 @@ pub mod pallet { /// It is only callable by the root account or subnet owner. /// The extrinsic will call the Subtensor pallet to set the difficulty. #[pallet::call_index(24)] - #[pallet::weight(Weight::from_parts(10_520_000, 0) + #[pallet::weight(Weight::from_parts(15_290_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_difficulty( @@ -727,7 +727,7 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the maximum allowed validators. #[pallet::call_index(25)] - #[pallet::weight(Weight::from_parts(13_860_000, 0) + #[pallet::weight(Weight::from_parts(19_680_000, 0) .saturating_add(::DbWeight::get().reads(2_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_max_allowed_validators( @@ -760,7 +760,7 @@ pub mod pallet { /// It is only callable by the root account or subnet owner. /// The extrinsic will call the Subtensor pallet to set the bonds moving average. #[pallet::call_index(26)] - #[pallet::weight(Weight::from_parts(12_450_000, 0) + #[pallet::weight(Weight::from_parts(15_320_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_bonds_moving_average( @@ -792,7 +792,7 @@ pub mod pallet { /// It is only callable by the root account or subnet owner. /// The extrinsic will call the Subtensor pallet to set the bonds penalty. #[pallet::call_index(60)] - #[pallet::weight(Weight::from_parts(12_940_000, 0) + #[pallet::weight(Weight::from_parts(16_260_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_bonds_penalty( @@ -815,7 +815,7 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the maximum registrations per block. #[pallet::call_index(27)] - #[pallet::weight(Weight::from_parts(12_180_000, 0) + #[pallet::weight(Weight::from_parts(15_580_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_max_registrations_per_block( @@ -883,7 +883,7 @@ pub mod pallet { /// It is only callable by the root account. /// The extrinsic will call the Subtensor pallet to set the tempo. #[pallet::call_index(30)] - #[pallet::weight(Weight::from_parts(12_310_000, 0) + #[pallet::weight(Weight::from_parts(16_720_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_tempo(origin: OriginFor, netuid: NetUid, tempo: u16) -> DispatchResult { @@ -1102,7 +1102,7 @@ pub mod pallet { /// It is only callable by the root account or subnet owner. /// The extrinsic will call the Subtensor pallet to set the value. #[pallet::call_index(49)] - #[pallet::weight(Weight::from_parts(12_180_000, 0) + #[pallet::weight(Weight::from_parts(15_750_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_commit_reveal_weights_enabled( @@ -1296,7 +1296,7 @@ pub mod pallet { /// # Weight /// Weight is handled by the `#[pallet::weight]` attribute. #[pallet::call_index(57)] - #[pallet::weight(Weight::from_parts(12_360_000, 0) + #[pallet::weight(Weight::from_parts(17_320_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn sudo_set_commit_reveal_weights_interval( @@ -1361,7 +1361,7 @@ pub mod pallet { /// No change should be signaled while any change is pending. Returns an error if a change /// is already pending. #[pallet::call_index(59)] - #[pallet::weight(Weight::from_parts(6_228_000, 0) + #[pallet::weight(Weight::from_parts(7_695_000, 0) .saturating_add(::DbWeight::get().reads(1_u64)) .saturating_add(::DbWeight::get().writes(1_u64)))] pub fn schedule_grandpa_change( @@ -1659,7 +1659,7 @@ pub mod pallet { /// Sets the commit-reveal weights version for all subnets #[pallet::call_index(71)] #[pallet::weight(( - Weight::from_parts(3_940_000, 0) + Weight::from_parts(6_402_000, 0) .saturating_add(::DbWeight::get().writes(1)) .saturating_add(::DbWeight::get().reads(0_u64)), DispatchClass::Operational, diff --git a/pallets/commitments/src/lib.rs b/pallets/commitments/src/lib.rs index 12356da08d..c4fe282a3b 100644 --- a/pallets/commitments/src/lib.rs +++ b/pallets/commitments/src/lib.rs @@ -205,7 +205,7 @@ pub mod pallet { /// Set the commitment for a given netuid #[pallet::call_index(0)] #[pallet::weight(( - Weight::from_parts(25_070_000, 0) + Weight::from_parts(31_160_000, 0) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)), DispatchClass::Operational, @@ -343,7 +343,7 @@ pub mod pallet { /// Sudo-set MaxSpace #[pallet::call_index(2)] #[pallet::weight(( - Weight::from_parts(1_660_000, 0) + Weight::from_parts(2_856_000, 0) .saturating_add(T::DbWeight::get().reads(0_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)), DispatchClass::Operational, diff --git a/pallets/drand/src/lib.rs b/pallets/drand/src/lib.rs index 9a0e3c04a4..a7cd61e5d8 100644 --- a/pallets/drand/src/lib.rs +++ b/pallets/drand/src/lib.rs @@ -404,7 +404,7 @@ pub mod pallet { /// * `origin`: the root user /// * `config`: the beacon configuration #[pallet::call_index(1)] - #[pallet::weight(Weight::from_parts(5_450_000, 0) + #[pallet::weight(Weight::from_parts(8_115_000, 0) .saturating_add(T::DbWeight::get().reads(0_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)))] pub fn set_beacon_config( @@ -425,7 +425,7 @@ pub mod pallet { /// allows the root user to set the oldest stored round #[pallet::call_index(2)] - #[pallet::weight(Weight::from_parts(3_350_000, 0) + #[pallet::weight(Weight::from_parts(5_370_000, 0) .saturating_add(T::DbWeight::get().reads(0_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn set_oldest_stored_round(origin: OriginFor, oldest_round: u64) -> DispatchResult { diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 76ae53905b..06912b52dc 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -120,7 +120,7 @@ mod dispatches { /// - On failure for each failed item in the batch. /// #[pallet::call_index(80)] - #[pallet::weight((Weight::from_parts(78_450_000, 0) + #[pallet::weight((Weight::from_parts(96_180_000, 0) .saturating_add(T::DbWeight::get().reads(14)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn batch_set_weights( @@ -186,7 +186,7 @@ mod dispatches { /// - On failure for each failed item in the batch. /// #[pallet::call_index(100)] - #[pallet::weight((Weight::from_parts(64_320_000, 0) + #[pallet::weight((Weight::from_parts(97_480_000, 0) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn batch_commit_weights( @@ -413,7 +413,7 @@ mod dispatches { /// - Attempting to set weights with max value exceeding limit. /// #[pallet::call_index(8)] - #[pallet::weight((Weight::from_parts(2_000_000, 0) + #[pallet::weight((Weight::from_parts(3_617_000, 0) .saturating_add(T::DbWeight::get().reads(0_u64)) .saturating_add(T::DbWeight::get().writes(0_u64)), DispatchClass::Normal, Pays::No))] pub fn set_tao_weights( @@ -454,7 +454,7 @@ mod dispatches { /// - The hotkey we are delegating is not owned by the calling coldket. /// #[pallet::call_index(1)] - #[pallet::weight((Weight::from_parts(2_363_000, 0) + #[pallet::weight((Weight::from_parts(3_637_000, 0) .saturating_add(T::DbWeight::get().reads(0)) .saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Normal, Pays::Yes))] pub fn become_delegate(_origin: OriginFor, _hotkey: T::AccountId) -> DispatchResult { @@ -498,7 +498,7 @@ mod dispatches { /// - The delegate is setting a take which is not lower than the previous. /// #[pallet::call_index(65)] - #[pallet::weight((Weight::from_parts(23_540_000, 0) + #[pallet::weight((Weight::from_parts(29_960_000, 0) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn decrease_take( @@ -540,7 +540,7 @@ mod dispatches { /// - The delegate is setting a take which is not greater than the previous. /// #[pallet::call_index(66)] - #[pallet::weight((Weight::from_parts(29_960_000, 0) + #[pallet::weight((Weight::from_parts(37_250_000, 0) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn increase_take( @@ -585,7 +585,7 @@ mod dispatches { /// - Errors stemming from transaction pallet. /// #[pallet::call_index(2)] - #[pallet::weight((Weight::from_parts(270_800_000, 0) + #[pallet::weight((Weight::from_parts(339_000_000, 0) .saturating_add(T::DbWeight::get().reads(26)) .saturating_add(T::DbWeight::get().writes(15)), DispatchClass::Normal, Pays::Yes))] pub fn add_stake( @@ -777,7 +777,7 @@ mod dispatches { /// - Attempting to set prometheus information withing the rate limit min. /// #[pallet::call_index(40)] - #[pallet::weight((Weight::from_parts(26_600_000, 0) + #[pallet::weight((Weight::from_parts(32_520_000, 0) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::No))] pub fn serve_axon_tls( @@ -827,7 +827,7 @@ mod dispatches { /// - The ip type v4 or v6. /// #[pallet::call_index(5)] - #[pallet::weight((Weight::from_parts(22_640_000, 0) + #[pallet::weight((Weight::from_parts(30_020_000, 0) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::No))] pub fn serve_prometheus( @@ -915,7 +915,7 @@ mod dispatches { /// Attempt to adjust the senate membership to include a hotkey #[pallet::call_index(63)] - #[pallet::weight((Weight::from_parts(48_160_000, 0) + #[pallet::weight((Weight::from_parts(80_490_000, 0) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(4)), DispatchClass::Normal, Pays::Yes))] pub fn adjust_senate(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { @@ -924,7 +924,7 @@ mod dispatches { /// User register a new subnetwork via burning token #[pallet::call_index(7)] - #[pallet::weight((Weight::from_parts(278_400_000, 0) + #[pallet::weight((Weight::from_parts(368_700_000, 0) .saturating_add(T::DbWeight::get().reads(49)) .saturating_add(T::DbWeight::get().writes(43)), DispatchClass::Normal, Pays::Yes))] pub fn burned_register( @@ -937,7 +937,7 @@ mod dispatches { /// The extrinsic for user to change its hotkey in subnet or all subnets. #[pallet::call_index(70)] - #[pallet::weight((Weight::from_parts(211_900_000, 0) + #[pallet::weight((Weight::from_parts(257_900_000, 0) .saturating_add(T::DbWeight::get().reads(47)) .saturating_add(T::DbWeight::get().writes(37)), DispatchClass::Operational, Pays::No))] pub fn swap_hotkey( @@ -1012,7 +1012,7 @@ mod dispatches { /// #[pallet::call_index(75)] #[pallet::weight(( - Weight::from_parts(36_590_000, 0) + Weight::from_parts(44_500_000, 0) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, @@ -1045,7 +1045,7 @@ mod dispatches { /// #[pallet::call_index(69)] #[pallet::weight(( - Weight::from_parts(3_475_000, 0) + Weight::from_parts(6_081_000, 0) .saturating_add(T::DbWeight::get().reads(0)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, @@ -1193,7 +1193,7 @@ mod dispatches { /// User register a new subnetwork #[pallet::call_index(59)] - #[pallet::weight((Weight::from_parts(191_600_000, 0) + #[pallet::weight((Weight::from_parts(250_500_000, 0) .saturating_add(T::DbWeight::get().reads(36)) .saturating_add(T::DbWeight::get().writes(52)), DispatchClass::Operational, Pays::No))] pub fn register_network(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { @@ -1327,7 +1327,7 @@ mod dispatches { /// - Consider adding checks to prevent scheduling too far into the future. /// TODO: Benchmark this call #[pallet::call_index(73)] - #[pallet::weight((Weight::from_parts(27_920_000, 0) + #[pallet::weight((Weight::from_parts(37_440_000, 0) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Operational, Pays::Yes))] pub fn schedule_swap_coldkey( @@ -1465,7 +1465,7 @@ mod dispatches { /// - The ip type v4 or v6. /// #[pallet::call_index(68)] - #[pallet::weight((Weight::from_parts(24_350_000, 0) + #[pallet::weight((Weight::from_parts(30_300_000, 0) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::Yes))] pub fn set_identity( @@ -1507,7 +1507,7 @@ mod dispatches { /// * `subnet_contact` (Vec): /// - The contact information for the subnet. #[pallet::call_index(78)] - #[pallet::weight((Weight::from_parts(15_000_000, 0) + #[pallet::weight((Weight::from_parts(19_050_000, 0) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::Yes))] pub fn set_subnet_identity( @@ -1538,7 +1538,7 @@ mod dispatches { /// User register a new subnetwork #[pallet::call_index(79)] - #[pallet::weight((Weight::from_parts(185_500_000, 0) + #[pallet::weight((Weight::from_parts(233_600_000, 0) .saturating_add(T::DbWeight::get().reads(35)) .saturating_add(T::DbWeight::get().writes(51)), DispatchClass::Operational, Pays::No))] pub fn register_network_with_identity( @@ -1575,7 +1575,7 @@ mod dispatches { /// * `TxRateLimitExceeded`: /// - Thrown if key has hit transaction rate limit #[pallet::call_index(83)] - #[pallet::weight((Weight::from_parts(22_070_000, 0) + #[pallet::weight((Weight::from_parts(29_910_000, 0) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Operational, Pays::Yes))] pub fn unstake_all(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { @@ -1608,9 +1608,9 @@ mod dispatches { /// * `TxRateLimitExceeded`: /// - Thrown if key has hit transaction rate limit #[pallet::call_index(84)] - #[pallet::weight((Weight::from_parts(294_800_000, 0) - .saturating_add(T::DbWeight::get().reads(33)) - .saturating_add(T::DbWeight::get().writes(16)), DispatchClass::Operational, Pays::Yes))] + #[pallet::weight((Weight::from_parts(360_000_000, 0) + .saturating_add(T::DbWeight::get().reads(38_u64)) + .saturating_add(T::DbWeight::get().writes(21_u64)), DispatchClass::Operational, Pays::Yes))] pub fn unstake_all_alpha(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { Self::do_unstake_all_alpha(origin, hotkey) } @@ -1637,7 +1637,7 @@ mod dispatches { /// - The alpha stake amount to move. /// #[pallet::call_index(85)] - #[pallet::weight((Weight::from_parts(123_700_000, 0) + #[pallet::weight((Weight::from_parts(161_300_000, 0) .saturating_add(T::DbWeight::get().reads(15_u64)) .saturating_add(T::DbWeight::get().writes(7_u64)), DispatchClass::Operational, Pays::Yes))] pub fn move_stake( @@ -1680,7 +1680,7 @@ mod dispatches { /// # Events /// May emit a `StakeTransferred` event on success. #[pallet::call_index(86)] - #[pallet::weight((Weight::from_parts(118_900_000, 0) + #[pallet::weight((Weight::from_parts(165_100_000, 0) .saturating_add(T::DbWeight::get().reads(13_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)), DispatchClass::Operational, Pays::Yes))] pub fn transfer_stake( @@ -1722,9 +1722,9 @@ mod dispatches { /// May emit a `StakeSwapped` event on success. #[pallet::call_index(87)] #[pallet::weight(( - Weight::from_parts(274_400_000, 0) - .saturating_add(T::DbWeight::get().reads(32)) - .saturating_add(T::DbWeight::get().writes(17)), + Weight::from_parts(376_100_000, 0) + .saturating_add(T::DbWeight::get().reads(37_u64)) + .saturating_add(T::DbWeight::get().writes(22_u64)), DispatchClass::Operational, Pays::Yes ))] @@ -1787,7 +1787,7 @@ mod dispatches { /// - Errors stemming from transaction pallet. /// #[pallet::call_index(88)] - #[pallet::weight((Weight::from_parts(316_400_000, 0) + #[pallet::weight((Weight::from_parts(385_800_000, 0) .saturating_add(T::DbWeight::get().reads(26)) .saturating_add(T::DbWeight::get().writes(15)), DispatchClass::Normal, Pays::Yes))] pub fn add_stake_limit( @@ -1851,7 +1851,7 @@ mod dispatches { /// - Thrown if there is not enough stake on the hotkey to withdwraw this amount. /// #[pallet::call_index(89)] - #[pallet::weight((Weight::from_parts(311_800_000, 0) + #[pallet::weight((Weight::from_parts(387_500_000, 0) .saturating_add(T::DbWeight::get().reads(30)) .saturating_add(T::DbWeight::get().writes(14)), DispatchClass::Normal, Pays::Yes))] pub fn remove_stake_limit( @@ -1895,9 +1895,9 @@ mod dispatches { /// May emit a `StakeSwapped` event on success. #[pallet::call_index(90)] #[pallet::weight(( - Weight::from_parts(330_400_000, 0) - .saturating_add(T::DbWeight::get().reads(32)) - .saturating_add(T::DbWeight::get().writes(17)), + Weight::from_parts(434_000_000, 0) + .saturating_add(T::DbWeight::get().reads(37_u64)) + .saturating_add(T::DbWeight::get().writes(22_u64)), DispatchClass::Operational, Pays::Yes ))] @@ -1931,7 +1931,7 @@ mod dispatches { /// Will charge based on the weight even if the hotkey is already associated with a coldkey. #[pallet::call_index(91)] #[pallet::weight(( - Weight::from_parts(19_930_000, 0).saturating_add(T::DbWeight::get().reads_writes(3, 3)), + Weight::from_parts(26_820_000, 0).saturating_add(T::DbWeight::get().reads_writes(3, 3)), DispatchClass::Operational, Pays::Yes ))] @@ -1956,7 +1956,7 @@ mod dispatches { /// Emits a `FirstEmissionBlockNumberSet` event on success. #[pallet::call_index(92)] #[pallet::weight(( - Weight::from_parts(24_370_000, 0).saturating_add(T::DbWeight::get().reads_writes(4, 2)), + Weight::from_parts(29_990_000, 0).saturating_add(T::DbWeight::get().reads_writes(4, 2)), DispatchClass::Operational, Pays::Yes ))] @@ -2020,7 +2020,7 @@ mod dispatches { /// Emits a `TokensRecycled` event on success. #[pallet::call_index(101)] #[pallet::weight(( - Weight::from_parts(76_470_000, 0).saturating_add(T::DbWeight::get().reads_writes(7, 4)), + Weight::from_parts(93_540_000, 0).saturating_add(T::DbWeight::get().reads_writes(7, 4)), DispatchClass::Operational, Pays::Yes ))] @@ -2045,7 +2045,7 @@ mod dispatches { /// Emits a `TokensBurned` event on success. #[pallet::call_index(102)] #[pallet::weight(( - Weight::from_parts(74_650_000, 0).saturating_add(T::DbWeight::get().reads_writes(7, 3)), + Weight::from_parts(92_050_000, 0).saturating_add(T::DbWeight::get().reads_writes(7, 3)), DispatchClass::Operational, Pays::Yes ))] @@ -2075,7 +2075,7 @@ mod dispatches { /// at which or better (higher) the staking should execute. /// Without limit_price it remove all the stake similar to `remove_stake` extrinsic #[pallet::call_index(103)] - #[pallet::weight((Weight::from_parts(315_200_000, 10142) + #[pallet::weight((Weight::from_parts(386_200_000, 10142) .saturating_add(T::DbWeight::get().reads(30_u64)) .saturating_add(T::DbWeight::get().writes(14_u64)), DispatchClass::Normal, Pays::Yes))] pub fn remove_stake_full_limit( @@ -2156,7 +2156,7 @@ mod dispatches { /// Emits a `SymbolUpdated` event on success. #[pallet::call_index(112)] #[pallet::weight(( - Weight::from_parts(19_550_000, 0).saturating_add(T::DbWeight::get().reads_writes(4, 1)), + Weight::from_parts(26_650_000, 0).saturating_add(T::DbWeight::get().reads_writes(4, 1)), DispatchClass::Operational, Pays::Yes ))] @@ -2201,7 +2201,7 @@ mod dispatches { /// * commit_reveal_version (`u16`): /// - The client (bittensor-drand) version #[pallet::call_index(113)] - #[pallet::weight((Weight::from_parts(52_290_000, 0) + #[pallet::weight((Weight::from_parts(66_090_000, 0) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn commit_timelocked_weights( From aac2c10fad6f41adeaa151ef1324acaf5d484e50 Mon Sep 17 00:00:00 2001 From: Greg Zaitsev Date: Tue, 19 Aug 2025 11:15:03 -0400 Subject: [PATCH 4/8] Comment on amount in migration --- .../src/migrations/migrate_fix_root_tao_and_alpha_in.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/pallets/subtensor/src/migrations/migrate_fix_root_tao_and_alpha_in.rs b/pallets/subtensor/src/migrations/migrate_fix_root_tao_and_alpha_in.rs index 8ebd8fd44a..f3c106d9d4 100644 --- a/pallets/subtensor/src/migrations/migrate_fix_root_tao_and_alpha_in.rs +++ b/pallets/subtensor/src/migrations/migrate_fix_root_tao_and_alpha_in.rs @@ -20,6 +20,7 @@ pub fn migrate_fix_root_tao_and_alpha_in() -> Weight { ); // Update counters + // TODO: Will be filled with real numbers once the runtime 302 is on mainnet SubnetTAO::::mutate(NetUid::ROOT, |amount| { *amount = amount.saturating_add(TaoCurrency::from(100_000_000_000)); }); From 51f78d37ce44f6bc49a39fef0074d455908c2ae3 Mon Sep 17 00:00:00 2001 From: Greg Zaitsev Date: Thu, 21 Aug 2025 12:14:38 -0400 Subject: [PATCH 5/8] Set numbers for migrate_fix_root_tao_and_alpha_in --- .../migrate_fix_root_tao_and_alpha_in.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pallets/subtensor/src/migrations/migrate_fix_root_tao_and_alpha_in.rs b/pallets/subtensor/src/migrations/migrate_fix_root_tao_and_alpha_in.rs index f3c106d9d4..f20d71c302 100644 --- a/pallets/subtensor/src/migrations/migrate_fix_root_tao_and_alpha_in.rs +++ b/pallets/subtensor/src/migrations/migrate_fix_root_tao_and_alpha_in.rs @@ -19,22 +19,25 @@ pub fn migrate_fix_root_tao_and_alpha_in() -> Weight { String::from_utf8_lossy(&migration_name) ); - // Update counters - // TODO: Will be filled with real numbers once the runtime 302 is on mainnet + // Update counters (unstaked more than stake) + let total_staked = 2_109_761_275_100_688_u64; + let total_unstaked = 2_179_659_173_851_658_u64; + let reserve_diff = total_unstaked.saturating_sub(total_staked); + let volume_diff = (total_unstaked as u128).saturating_add(total_staked as u128); SubnetTAO::::mutate(NetUid::ROOT, |amount| { - *amount = amount.saturating_add(TaoCurrency::from(100_000_000_000)); + *amount = amount.saturating_sub(TaoCurrency::from(reserve_diff)); }); SubnetAlphaIn::::mutate(NetUid::ROOT, |amount| { - *amount = amount.saturating_add(AlphaCurrency::from(100_000_000_000)); + *amount = amount.saturating_add(AlphaCurrency::from(reserve_diff)); }); SubnetAlphaOut::::mutate(NetUid::ROOT, |amount| { - *amount = amount.saturating_add(AlphaCurrency::from(100_000_000_000)); + *amount = amount.saturating_sub(AlphaCurrency::from(reserve_diff)); }); SubnetVolume::::mutate(NetUid::ROOT, |amount| { - *amount = amount.saturating_add(100_000_000_000_u128); + *amount = amount.saturating_add(volume_diff); }); TotalStake::::mutate(|amount| { - *amount = amount.saturating_add(TaoCurrency::from(100_000_000_000)); + *amount = amount.saturating_sub(TaoCurrency::from(reserve_diff)); }); weight = weight.saturating_add(T::DbWeight::get().writes(5)); From e2746c6e601a53ad4793c44f507fb13a72f9125d Mon Sep 17 00:00:00 2001 From: Greg Zaitsev Date: Thu, 21 Aug 2025 12:21:12 -0400 Subject: [PATCH 6/8] Spec version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 56a263a813..1d8e658f1c 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -215,7 +215,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: 302, + spec_version: 303, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From eae038f273d198b03fff1a9a8718a25611a31da8 Mon Sep 17 00:00:00 2001 From: Greg Zaitsev Date: Thu, 21 Aug 2025 12:52:22 -0400 Subject: [PATCH 7/8] Add migrate_fix_root_tao_and_alpha_in to migration hook --- pallets/subtensor/src/macros/hooks.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pallets/subtensor/src/macros/hooks.rs b/pallets/subtensor/src/macros/hooks.rs index 99d103e829..bec3155f2a 100644 --- a/pallets/subtensor/src/macros/hooks.rs +++ b/pallets/subtensor/src/macros/hooks.rs @@ -131,7 +131,9 @@ mod hooks { // Migrate CRV3 add commit_block .saturating_add(migrations::migrate_crv3_commits_add_block::migrate_crv3_commits_add_block::()) //Migrate CRV3 to TimelockedCommits - .saturating_add(migrations::migrate_crv3_v2_to_timelocked::migrate_crv3_v2_to_timelocked::()); + .saturating_add(migrations::migrate_crv3_v2_to_timelocked::migrate_crv3_v2_to_timelocked::()) + // Migrate to fix root counters + .saturating_add(migrations::migrate_fix_root_tao_and_alpha_in::migrate_fix_root_tao_and_alpha_in::()); weight } From b29bc7f53026feb7315f42005747a376cf094b21 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 21 Aug 2025 18:55:24 +0000 Subject: [PATCH 8/8] auto-update benchmark weights --- pallets/subtensor/src/macros/dispatches.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index aea2eac3f7..35439479ab 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -693,7 +693,7 @@ mod dispatches { /// - Attempting to set prometheus information withing the rate limit min. /// #[pallet::call_index(4)] - #[pallet::weight((Weight::from_parts(43_680_000, 0) + #[pallet::weight((Weight::from_parts(33_010_000, 0) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::No))] pub fn serve_axon( @@ -2201,7 +2201,7 @@ mod dispatches { /// * commit_reveal_version (`u16`): /// - The client (bittensor-drand) version #[pallet::call_index(113)] - #[pallet::weight((Weight::from_parts(81_920_000, 0) + #[pallet::weight((Weight::from_parts(64_530_000, 0) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn commit_timelocked_weights(