Skip to content
4 changes: 2 additions & 2 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
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 @@ -131,7 +131,9 @@ mod hooks {
// Migrate CRV3 add commit_block
.saturating_add(migrations::migrate_crv3_commits_add_block::migrate_crv3_commits_add_block::<T>())
//Migrate CRV3 to TimelockedCommits
.saturating_add(migrations::migrate_crv3_v2_to_timelocked::migrate_crv3_v2_to_timelocked::<T>());
.saturating_add(migrations::migrate_crv3_v2_to_timelocked::migrate_crv3_v2_to_timelocked::<T>())
// Migrate to fix root counters
.saturating_add(migrations::migrate_fix_root_tao_and_alpha_in::migrate_fix_root_tao_and_alpha_in::<T>());
weight
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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<T: Config>() -> Weight {
let migration_name = b"migrate_fix_root_tao_and_alpha_in".to_vec();
let mut weight = T::DbWeight::get().reads(1);

if HasMigrationRun::<T>::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 (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::<T>::mutate(NetUid::ROOT, |amount| {
*amount = amount.saturating_sub(TaoCurrency::from(reserve_diff));
});
SubnetAlphaIn::<T>::mutate(NetUid::ROOT, |amount| {
*amount = amount.saturating_add(AlphaCurrency::from(reserve_diff));
});
SubnetAlphaOut::<T>::mutate(NetUid::ROOT, |amount| {
*amount = amount.saturating_sub(AlphaCurrency::from(reserve_diff));
});
SubnetVolume::<T>::mutate(NetUid::ROOT, |amount| {
*amount = amount.saturating_add(volume_diff);
});
TotalStake::<T>::mutate(|amount| {
*amount = amount.saturating_sub(TaoCurrency::from(reserve_diff));
});

weight = weight.saturating_add(T::DbWeight::get().writes(5));

HasMigrationRun::<T>::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::<T>().saturating_add(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 @@ -15,6 +15,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;
Expand Down
41 changes: 40 additions & 1 deletion pallets/subtensor/src/tests/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>::get_subnet_owner(1), );
//assert_eq!(SubtensorModule::<Test>::get_subnet_owner(1), );

// Run the migration to transfer ownership
let hex =
Expand Down Expand Up @@ -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::<Test>::insert(NetUid::ROOT, TaoCurrency::from(initial_value));
SubnetAlphaIn::<Test>::insert(NetUid::ROOT, AlphaCurrency::from(initial_value));
SubnetAlphaOut::<Test>::insert(NetUid::ROOT, AlphaCurrency::from(initial_value));
SubnetVolume::<Test>::insert(NetUid::ROOT, initial_value as u128);
TotalStake::<Test>::set(TaoCurrency::from(initial_value));

assert!(
!HasMigrationRun::<Test>::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::<Test>();

// Verify the migration ran correctly
assert!(
HasMigrationRun::<Test>::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::<Test>::get(NetUid::ROOT) != initial_value.into());
assert!(SubnetAlphaIn::<Test>::get(NetUid::ROOT) != initial_value.into());
assert!(SubnetAlphaOut::<Test>::get(NetUid::ROOT) != initial_value.into());
assert!(SubnetVolume::<Test>::get(NetUid::ROOT) != initial_value as u128);
assert!(TotalStake::<Test>::get() != initial_value.into());
});
}

#[test]
fn test_migrate_subnet_symbols() {
new_test_ext(1).execute_with(|| {
Expand Down