From 32301364e1352f38955419e1565937a83eebfa33 Mon Sep 17 00:00:00 2001 From: unconst Date: Fri, 7 Feb 2025 16:36:34 -0500 Subject: [PATCH 1/6] moving price init from emission --- pallets/subtensor/src/migrations/migrate_rao.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pallets/subtensor/src/migrations/migrate_rao.rs b/pallets/subtensor/src/migrations/migrate_rao.rs index d6183c2d1d..0e0e725945 100644 --- a/pallets/subtensor/src/migrations/migrate_rao.rs +++ b/pallets/subtensor/src/migrations/migrate_rao.rs @@ -3,6 +3,7 @@ use alloc::string::String; use frame_support::IterableStorageMap; use frame_support::{traits::Get, weights::Weight}; use sp_runtime::format; +use substrate_fixed::types::I96F32; use substrate_fixed::types::U64F64; use super::*; @@ -88,6 +89,7 @@ pub fn migrate_rao() -> Weight { let remaining_lock = lock.saturating_sub(pool_initial_tao); // Refund the owner for the remaining lock. + SubnetMovingPrice::::insert(netuid, I96F32::from_num( EmissionValues::::get(netuid) ) ); Pallet::::add_balance_to_coldkey_account(&owner, remaining_lock); SubnetLocked::::insert(netuid, 0); // Clear lock amount. SubnetTAO::::insert(netuid, pool_initial_tao); From b0bdb1621017e340ab5d49aac4c92edc90b792f7 Mon Sep 17 00:00:00 2001 From: unconst Date: Fri, 7 Feb 2025 16:42:02 -0500 Subject: [PATCH 2/6] cargo fmt --- pallets/subtensor/src/migrations/migrate_rao.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/migrations/migrate_rao.rs b/pallets/subtensor/src/migrations/migrate_rao.rs index 0e0e725945..e09d408f93 100644 --- a/pallets/subtensor/src/migrations/migrate_rao.rs +++ b/pallets/subtensor/src/migrations/migrate_rao.rs @@ -89,7 +89,7 @@ pub fn migrate_rao() -> Weight { let remaining_lock = lock.saturating_sub(pool_initial_tao); // Refund the owner for the remaining lock. - SubnetMovingPrice::::insert(netuid, I96F32::from_num( EmissionValues::::get(netuid) ) ); + SubnetMovingPrice::::insert(netuid, I96F32::from_num(EmissionValues::::get(netuid))); Pallet::::add_balance_to_coldkey_account(&owner, remaining_lock); SubnetLocked::::insert(netuid, 0); // Clear lock amount. SubnetTAO::::insert(netuid, pool_initial_tao); From 5c27d88e593033b7d9ae190eeca83433bcac2095 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 7 Feb 2025 16:42:15 -0500 Subject: [PATCH 3/6] bump 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 03ade34d32..40e5c54f02 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -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: 231, + spec_version: 232, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 551a69ffa6cc7a4f363f1fe81b06327b682692c7 Mon Sep 17 00:00:00 2001 From: unconst Date: Fri, 7 Feb 2025 16:59:23 -0500 Subject: [PATCH 4/6] commit Cargo.lock --- .../subtensor/src/migrations/migrate_rao.rs | 2 +- pallets/subtensor/src/tests/migration.rs | 388 ++---------------- 2 files changed, 28 insertions(+), 362 deletions(-) diff --git a/pallets/subtensor/src/migrations/migrate_rao.rs b/pallets/subtensor/src/migrations/migrate_rao.rs index e09d408f93..d45a5a04c3 100644 --- a/pallets/subtensor/src/migrations/migrate_rao.rs +++ b/pallets/subtensor/src/migrations/migrate_rao.rs @@ -89,7 +89,7 @@ pub fn migrate_rao() -> Weight { let remaining_lock = lock.saturating_sub(pool_initial_tao); // Refund the owner for the remaining lock. - SubnetMovingPrice::::insert(netuid, I96F32::from_num(EmissionValues::::get(netuid))); + SubnetMovingPrice::::insert(netuid, I96F32::from_num(EmissionValues::::get(netuid)).checked_div( I96F32::from_num(1_000_000_000) ).unwrap_or( I96F32::from_num(0.0) ) ); Pallet::::add_balance_to_coldkey_account(&owner, remaining_lock); SubnetLocked::::insert(netuid, 0); // Clear lock amount. SubnetTAO::::insert(netuid, pool_initial_tao); diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index 025f77e981..9f31ad90d7 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -14,8 +14,20 @@ use frame_system::Config; use sp_core::{crypto::Ss58Codec, H256, U256}; use sp_io::hashing::twox_128; use sp_runtime::traits::Zero; +use substrate_fixed::types::I96F32; use substrate_fixed::types::extra::U2; +#[allow(clippy::arithmetic_side_effects)] +fn close(value: u64, target: u64, eps: u64) { + assert!( + (value as i64 - target as i64).abs() < eps as i64, + "Assertion failed: value = {}, target = {}, eps = {}", + value, + target, + eps + ) +} + #[test] fn test_initialise_ti() { use frame_support::traits::OnRuntimeUpgrade; @@ -39,226 +51,6 @@ fn test_initialise_ti() { }); } -// #[test] -// fn test_migration_fix_total_stake_maps() { -// new_test_ext(1).execute_with(|| { - -// let ck1 = U256::from(1); -// let ck2 = U256::from(2); -// let ck3 = U256::from(3); - -// let hk1 = U256::from(1 + 100); -// let hk2 = U256::from(2 + 100); - -// let mut total_stake_amount = 0; - -// // Give each coldkey some stake in the maps -// SubtensorModule::increase_stake_on_coldkey_hotkey_account(&ck1, &hk1, 100); -// total_stake_amount += 100; - -// SubtensorModule::increase_stake_on_coldkey_hotkey_account(&ck2, &hk1, 10_101); -// total_stake_amount += 10_101; - -// SubtensorModule::increase_stake_on_coldkey_hotkey_account(&ck3, &hk2, 100_000_000); -// total_stake_amount += 100_000_000; - -// SubtensorModule::increase_stake_on_coldkey_hotkey_account(&ck1, &hk2, 1_123_000_000); -// total_stake_amount += 1_123_000_000; - -// // Check that the total stake is correct -// assert_eq!(SubtensorModule::get_total_stake(), total_stake_amount); - -// // Check that the total coldkey stake is correct -// assert_eq!( -// SubtensorModule::get_total_stake_for_coldkey(&ck1), -// 100 + 1_123_000_000 -// ); -// assert_eq!(SubtensorModule::get_total_stake_for_coldkey(&ck2), 10_101); -// assert_eq!( -// SubtensorModule::get_total_stake_for_coldkey(&ck3), -// 100_000_000 -// ); - -// // Check that the total hotkey stake is correct -// assert_eq!( -// SubtensorModule::get_total_stake_for_hotkey(&hk1), -// 100 + 10_101 -// ); -// assert_eq!( -// SubtensorModule::get_total_stake_for_hotkey(&hk2), -// 100_000_000 + 1_123_000_000 -// ); - -// // Mess up the total coldkey stake -// crate::TotalColdkeyStake::::insert(ck1, 0); -// // Verify that the total coldkey stake is now 0 for ck1 -// assert_eq!(SubtensorModule::get_total_stake_for_coldkey(&ck1), 0); - -// // Mess up the total stake -// crate::TotalStake::::put(123_456_789); -// // Verify that the total stake is now wrong -// assert_ne!(SubtensorModule::get_total_stake(), total_stake_amount); - -// // Run the migration to fix the total stake maps -// crate::migrations::migrate_to_v2_fixed_total_stake::migrate_to_v2_fixed_total_stake::( -// ); - -// // Verify that the total stake is now correct -// assert_eq!(SubtensorModule::get_total_stake(), total_stake_amount); -// // Verify that the total coldkey stake is now correct for each coldkey -// assert_eq!( -// SubtensorModule::get_total_stake_for_coldkey(&ck1), -// 100 + 1_123_000_000 -// ); -// assert_eq!(SubtensorModule::get_total_stake_for_coldkey(&ck2), 10_101); -// assert_eq!( -// SubtensorModule::get_total_stake_for_coldkey(&ck3), -// 100_000_000 -// ); - -// // Verify that the total hotkey stake is STILL correct for each hotkey -// assert_eq!( -// SubtensorModule::get_total_stake_for_hotkey(&hk1), -// 100 + 10_101 -// ); -// assert_eq!( -// SubtensorModule::get_total_stake_for_hotkey(&hk2), -// 100_000_000 + 1_123_000_000 -// ); - -// // Verify that the Stake map has no extra entries -// assert_eq!(crate::Stake::::iter().count(), 4); // 4 entries total -// assert_eq!(crate::Stake::::iter_key_prefix(hk1).count(), 2); // 2 stake entries for hk1 -// assert_eq!(crate::Stake::::iter_key_prefix(hk2).count(), 2); // 2 stake entries for hk2 -// }) -// } - -// #[test] -// // To run this test with cargo, use the following command: -// // cargo test --package pallet-subtensor --test migration test_migrate_total_issuance -// fn test_migrate_total_issuance() { -// new_test_ext(1).execute_with(|| { -// // Run the migration to check total issuance. -// let test: bool = true; - -// assert_eq!(SubtensorModule::get_total_issuance(), 0); -// crate::migrations::migrate_total_issuance::migrate_total_issuance::(test); -// assert_eq!(SubtensorModule::get_total_issuance(), 0); - -// SubtensorModule::add_balance_to_coldkey_account(&U256::from(1), 10000); -// assert_eq!(SubtensorModule::get_total_issuance(), 0); -// crate::migrations::migrate_total_issuance::migrate_total_issuance::(test); -// assert_eq!(SubtensorModule::get_total_issuance(), 10000); - -// SubtensorModule::increase_stake_on_coldkey_hotkey_account( -// &U256::from(1), -// &U256::from(1), -// 30000, -// ); -// assert_eq!(SubtensorModule::get_total_issuance(), 10000); -// crate::migrations::migrate_total_issuance::migrate_total_issuance::(test); -// assert_eq!(SubtensorModule::get_total_issuance(), 10000 + 30000); -// }) -// } - -//#[test] -// To run this test with cargo, use the following command: -// cargo test --package pallet-subtensor --test migration test_total_issuance_global -// fn test_total_issuance_global() { -// new_test_ext(0).execute_with(|| { - -// // Initialize network unique identifier and keys for testing. -// let netuid: u16 = 1; // Network unique identifier set to 1 for testing. -// let coldkey = U256::from(0); // Coldkey initialized to 0, representing an account's public key for non-transactional operations. -// let hotkey = U256::from(0); // Hotkey initialized to 0, representing an account's public key for transactional operations. -// let owner: U256 = U256::from(0); - -// let lockcost: u64 = SubtensorModule::get_network_lock_cost(); -// SubtensorModule::add_balance_to_coldkey_account(&owner, lockcost); // Add a balance of 20000 to the coldkey account. -// assert_eq!(SubtensorModule::get_total_issuance(), 0); // initial is zero. -// assert_ok!(SubtensorModule::register_network( -// <::RuntimeOrigin>::signed(owner), -// )); -// SubtensorModule::set_max_allowed_uids(netuid, 1); // Set the maximum allowed unique identifiers for the network to 1. -// assert_eq!(SubtensorModule::get_total_issuance(), 0); // initial is zero. -// crate::migrations::migrate_total_issuance::migrate_total_issuance::(true); // Pick up lock. -// assert_eq!(SubtensorModule::get_total_issuance(), lockcost); // Verify the total issuance is updated to 20000 after migration. -// assert!(SubtensorModule::if_subnet_exist(netuid)); - -// // Test the migration's effect on total issuance after adding balance to a coldkey account. -// let account_balance: u64 = 20000; -// let _hotkey_account_id_1 = U256::from(1); // Define a hotkey account ID for further operations. -// let _coldkey_account_id_1 = U256::from(1); // Define a coldkey account ID for further operations. -// assert_eq!(SubtensorModule::get_total_issuance(), lockcost); // Ensure the total issuance starts at 0 before the migration. -// SubtensorModule::add_balance_to_coldkey_account(&coldkey, account_balance); // Add a balance of 20000 to the coldkey account. -// crate::migrations::migrate_total_issuance::migrate_total_issuance::(true); // Execute the migration to update total issuance. -// assert_eq!( -// SubtensorModule::get_total_issuance(), -// account_balance + lockcost -// ); // Verify the total issuance is updated to 20000 after migration. - -// // Test the effect of burning on total issuance. -// let burn_cost: u64 = 10000; -// SubtensorModule::set_burn(netuid, burn_cost); // Set the burn amount to 10000 for the network. -// assert_eq!( -// SubtensorModule::get_total_issuance(), -// account_balance + lockcost -// ); // Confirm the total issuance remains 20000 before burning. -// assert_ok!(SubtensorModule::burned_register( -// <::RuntimeOrigin>::signed(hotkey), -// netuid, -// hotkey -// )); // Execute the burn operation, reducing the total issuance. -// assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); // Ensure the subnetwork count increases to 1 after burning -// assert_eq!( -// SubtensorModule::get_total_issuance(), -// account_balance + lockcost - burn_cost -// ); // Verify the total issuance is reduced to 10000 after burning. -// crate::migrations::migrate_total_issuance::migrate_total_issuance::(true); // Execute the migration to update total issuance. -// assert_eq!( -// SubtensorModule::get_total_issuance(), -// account_balance + lockcost - burn_cost -// ); // Verify the total issuance is updated to 10000 nothing changes - -// // Test staking functionality and its effect on total issuance. -// let new_stake: u64 = 10000; -// assert_eq!( -// SubtensorModule::get_total_issuance(), -// account_balance + lockcost - burn_cost -// ); // Same -// SubtensorModule::increase_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, new_stake); // Stake an additional 10000 to the coldkey-hotkey account. This is i -// assert_eq!( -// SubtensorModule::get_total_issuance(), -// account_balance + lockcost - burn_cost -// ); // Same -// crate::migrations::migrate_total_issuance::migrate_total_issuance::(true); // Fix issuance -// assert_eq!( -// SubtensorModule::get_total_issuance(), -// account_balance + lockcost - burn_cost + new_stake -// ); // New - -// // Set emission values for the network and verify. -// let emission: u64 = 1_000_000_000; -// SubtensorModule::set_tempo(netuid, 1); -// SubtensorModule::set_emission_values(&[netuid], vec![emission]).unwrap(); // Set the emission value for the network to 1_000_000_000. -// assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), emission); // Verify the emission value is set correctly for the network. -// assert_eq!( -// SubtensorModule::get_total_issuance(), -// account_balance + lockcost - burn_cost + new_stake -// ); -// run_to_block(2); // Advance to block number 2 to trigger the emission through the subnet. -// assert_eq!( -// SubtensorModule::get_total_issuance(), -// account_balance + lockcost - burn_cost + new_stake + emission -// ); // Verify the total issuance reflects the staked amount and emission value that has been put through the epoch. -// crate::migrations::migrate_total_issuance::migrate_total_issuance::(true); // Test migration does not change amount. -// assert_eq!( -// SubtensorModule::get_total_issuance(), -// account_balance + lockcost - burn_cost + new_stake + emission -// ); // Verify the total issuance reflects the staked amount and emission value that has been put through the epoch. -// }) -// } - #[test] fn test_migration_transfer_nets_to_foundation() { new_test_ext(1).execute_with(|| { @@ -307,147 +99,6 @@ fn test_migration_delete_subnet_21() { }) } -// SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test migration -- test_migrate_fix_total_coldkey_stake --exact --nocapture -// SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test migration -- test_migrate_fix_total_coldkey_stake --exact --nocapture -// Deprecated -// #[test] -// fn test_migrate_fix_total_coldkey_stake() { -// new_test_ext(1).execute_with(|| { -// assert!(false); - -// let _migration_name = "fix_total_coldkey_stake_v7"; -// let coldkey = U256::from(0); -// TotalColdkeyStake::::insert(coldkey, 0); -// StakingHotkeys::::insert(coldkey, vec![U256::from(1), U256::from(2), U256::from(3)]); -// Stake::::insert(U256::from(1), U256::from(0), 10000); -// Stake::::insert(U256::from(2), U256::from(0), 10000); -// Stake::::insert(U256::from(3), U256::from(0), 10000); -// crate::migrations::migrate_fix_total_coldkey_stake::do_migrate_fix_total_coldkey_stake::< -// Test, -// >(); -// assert_eq!(TotalColdkeyStake::::get(coldkey), 30000); -// }) -// } - -// SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test migration -- test_migrate_fix_total_coldkey_stake_value_already_in_total --exact --nocapture -// Deprecated -// #[test] -// fn test_migrate_fix_total_coldkey_stake_value_already_in_total() { -// new_test_ext(1).execute_with(|| { - -// let _migration_name = "fix_total_coldkey_stake_v7"; -// let coldkey = U256::from(0); -// TotalColdkeyStake::::insert(coldkey, 100000000); -// StakingHotkeys::::insert(coldkey, vec![U256::from(1), U256::from(2), U256::from(3)]); -// Stake::::insert(U256::from(1), U256::from(0), 10000); -// Stake::::insert(U256::from(2), U256::from(0), 10000); -// Stake::::insert(U256::from(3), U256::from(0), 10000); -// crate::migrations::migrate_fix_total_coldkey_stake::do_migrate_fix_total_coldkey_stake::< -// Test, -// >(); -// assert_eq!(TotalColdkeyStake::::get(coldkey), 30000); -// }) -// } - -// SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test migration -- test_migrate_fix_total_coldkey_stake_no_entry --exact --nocapture -// Deprecated -// #[test] -// fn test_migrate_fix_total_coldkey_stake_no_entry() { -// new_test_ext(1).execute_with(|| { - -// let _migration_name = "fix_total_coldkey_stake_v7"; -// let coldkey = U256::from(0); -// StakingHotkeys::::insert(coldkey, vec![U256::from(1), U256::from(2), U256::from(3)]); -// Stake::::insert(U256::from(1), U256::from(0), 10000); -// Stake::::insert(U256::from(2), U256::from(0), 10000); -// Stake::::insert(U256::from(3), U256::from(0), 10000); -// crate::migrations::migrate_fix_total_coldkey_stake::do_migrate_fix_total_coldkey_stake::< -// Test, -// >(); -// assert_eq!(TotalColdkeyStake::::get(coldkey), 30000); -// }) -// } - -// SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test migration -- test_migrate_fix_total_coldkey_stake_no_entry_in_hotkeys --exact --nocapture -// Deprecated -// #[test] -// fn test_migrate_fix_total_coldkey_stake_no_entry_in_hotkeys() { -// new_test_ext(1).execute_with(|| { -// let _migration_name = "fix_total_coldkey_stake_v7"; -// let coldkey = U256::from(0); -// TotalColdkeyStake::::insert(coldkey, 100000000); -// StakingHotkeys::::insert(coldkey, vec![U256::from(1), U256::from(2), U256::from(3)]); -// crate::migrations::migrate_fix_total_coldkey_stake::do_migrate_fix_total_coldkey_stake::< -// Test, -// >(); -// assert_eq!(TotalColdkeyStake::::get(coldkey), 0); -// }) -// } - -// SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test migration -- test_migrate_fix_total_coldkey_stake_one_hotkey_stake_missing --exact --nocapture -// Deprecated -// #[test] -// fn test_migrate_fix_total_coldkey_stake_one_hotkey_stake_missing() { -// new_test_ext(1).execute_with(|| { - -// let _migration_name = "fix_total_coldkey_stake_v7"; -// let coldkey = U256::from(0); -// TotalColdkeyStake::::insert(coldkey, 100000000); -// StakingHotkeys::::insert(coldkey, vec![U256::from(1), U256::from(2), U256::from(3)]); -// Stake::::insert(U256::from(1), U256::from(0), 10000); -// Stake::::insert(U256::from(2), U256::from(0), 10000); -// crate::migrations::migrate_fix_total_coldkey_stake::do_migrate_fix_total_coldkey_stake::< -// Test, -// >(); -// assert_eq!(TotalColdkeyStake::::get(coldkey), 20000); -// }) -// } - -// New test to check if migration runs only once -// SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test migration -- test_migrate_fix_total_coldkey_stake_runs_once --exact --nocapture -// Deprecated -// #[test] -// fn test_migrate_fix_total_coldkey_stake_runs_once() { -// new_test_ext(1).execute_with(|| { - -// let migration_name = "fix_total_coldkey_stake_v7"; -// let coldkey = U256::from(0); -// TotalColdkeyStake::::insert(coldkey, 0); -// StakingHotkeys::::insert(coldkey, vec![U256::from(1), U256::from(2), U256::from(3)]); -// Stake::::insert(U256::from(1), coldkey, 10000); -// Stake::::insert(U256::from(2), coldkey, 10000); -// Stake::::insert(U256::from(3), coldkey, 10000); - -// // First run -// let first_weight = run_migration_and_check(migration_name); -// assert!(first_weight != Weight::zero()); -// assert_eq!(TotalColdkeyStake::::get(coldkey), 30000); - -// // Second run -// let second_weight = run_migration_and_check(migration_name); -// assert_eq!(second_weight, Weight::zero()); -// assert_eq!(TotalColdkeyStake::::get(coldkey), 30000); -// }) -// } - -// SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test migration -- test_migrate_fix_total_coldkey_stake_starts_with_value_no_stake_map_entries --exact --nocapture -// Deprecated -// #[test] -// fn test_migrate_fix_total_coldkey_stake_starts_with_value_no_stake_map_entries() { -// new_test_ext(1).execute_with(|| { - -// let migration_name = "fix_total_coldkey_stake_v7"; -// let coldkey = U256::from(0); -// TotalColdkeyStake::::insert(coldkey, 123_456_789); - -// // Notably, coldkey has no stake map or staking_hotkeys map entries - -// let weight = run_migration_and_check(migration_name); -// assert!(weight != Weight::zero()); -// // Therefore 0 -// assert_eq!(TotalColdkeyStake::::get(coldkey), 123_456_789); -// }) -// } fn run_migration_and_check(migration_name: &'static str) -> frame_support::weights::Weight { // Execute the migration and store its weight @@ -558,6 +209,8 @@ fn test_migrate_rao() { // Setup initial state let netuid_0: u16 = 0; let netuid_1: u16 = 1; + let netuid_2: u16 = 2; + let netuid_3: u16 = 3; let hotkey1 = U256::from(1); let hotkey2 = U256::from(2); let coldkey1 = U256::from(3); @@ -570,11 +223,17 @@ fn test_migrate_rao() { // Add networks root and alpha add_network(netuid_0, 1, 0); add_network(netuid_1, 1, 0); + add_network(netuid_2, 1, 0); + add_network(netuid_3, 1, 0); // Set subnet lock SubnetLocked::::insert(netuid_1, lock_amount); // Add some initial stake + EmissionValues::::insert(netuid_1, 1_000_000_000 ); + EmissionValues::::insert(netuid_2, 2_000_000_000 ); + EmissionValues::::insert(netuid_3, 3_000_000_000 ); + Owner::::insert(hotkey1, coldkey1); Owner::::insert(hotkey2, coldkey2); Stake::::insert(hotkey1, coldkey1, stake_amount); @@ -710,6 +369,13 @@ fn test_migrate_rao() { SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey1, netuid_1), stake_amount ); + + // Run the coinbase + let emission: u64 = 1_000_000_000; + SubtensorModule::run_coinbase(I96F32::from_num(emission)); + close(SubnetTaoInEmission::::get(netuid_1), 1*(emission/6), 100); + close(SubnetTaoInEmission::::get(netuid_2), 2*(emission/6), 100); + close(SubnetTaoInEmission::::get(netuid_3), 3*(emission/6), 100); }); } From 0b6dd40dd65bdde8713ffe8c7a6f9e282cddf677 Mon Sep 17 00:00:00 2001 From: unconst Date: Fri, 7 Feb 2025 17:00:11 -0500 Subject: [PATCH 5/6] cargo clippy --- 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 9f31ad90d7..c9fe5ce521 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -373,7 +373,7 @@ fn test_migrate_rao() { // Run the coinbase let emission: u64 = 1_000_000_000; SubtensorModule::run_coinbase(I96F32::from_num(emission)); - close(SubnetTaoInEmission::::get(netuid_1), 1*(emission/6), 100); + close(SubnetTaoInEmission::::get(netuid_1), emission/6, 100); close(SubnetTaoInEmission::::get(netuid_2), 2*(emission/6), 100); close(SubnetTaoInEmission::::get(netuid_3), 3*(emission/6), 100); }); From b00b5b3f1db15dd8f37893d485e342d1686e8a6e Mon Sep 17 00:00:00 2001 From: unconst Date: Fri, 7 Feb 2025 17:00:52 -0500 Subject: [PATCH 6/6] cargo fmt --- .../subtensor/src/migrations/migrate_rao.rs | 7 ++++- pallets/subtensor/src/tests/migration.rs | 27 +++++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/pallets/subtensor/src/migrations/migrate_rao.rs b/pallets/subtensor/src/migrations/migrate_rao.rs index d45a5a04c3..ba9e217dc2 100644 --- a/pallets/subtensor/src/migrations/migrate_rao.rs +++ b/pallets/subtensor/src/migrations/migrate_rao.rs @@ -89,7 +89,12 @@ pub fn migrate_rao() -> Weight { let remaining_lock = lock.saturating_sub(pool_initial_tao); // Refund the owner for the remaining lock. - SubnetMovingPrice::::insert(netuid, I96F32::from_num(EmissionValues::::get(netuid)).checked_div( I96F32::from_num(1_000_000_000) ).unwrap_or( I96F32::from_num(0.0) ) ); + SubnetMovingPrice::::insert( + netuid, + I96F32::from_num(EmissionValues::::get(netuid)) + .checked_div(I96F32::from_num(1_000_000_000)) + .unwrap_or(I96F32::from_num(0.0)), + ); Pallet::::add_balance_to_coldkey_account(&owner, remaining_lock); SubnetLocked::::insert(netuid, 0); // Clear lock amount. SubnetTAO::::insert(netuid, pool_initial_tao); diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index c9fe5ce521..6d45cbe0be 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -14,8 +14,8 @@ use frame_system::Config; use sp_core::{crypto::Ss58Codec, H256, U256}; use sp_io::hashing::twox_128; use sp_runtime::traits::Zero; -use substrate_fixed::types::I96F32; use substrate_fixed::types::extra::U2; +use substrate_fixed::types::I96F32; #[allow(clippy::arithmetic_side_effects)] fn close(value: u64, target: u64, eps: u64) { @@ -99,7 +99,6 @@ fn test_migration_delete_subnet_21() { }) } - fn run_migration_and_check(migration_name: &'static str) -> frame_support::weights::Weight { // Execute the migration and store its weight let weight: frame_support::weights::Weight = @@ -230,9 +229,9 @@ fn test_migrate_rao() { SubnetLocked::::insert(netuid_1, lock_amount); // Add some initial stake - EmissionValues::::insert(netuid_1, 1_000_000_000 ); - EmissionValues::::insert(netuid_2, 2_000_000_000 ); - EmissionValues::::insert(netuid_3, 3_000_000_000 ); + EmissionValues::::insert(netuid_1, 1_000_000_000); + EmissionValues::::insert(netuid_2, 2_000_000_000); + EmissionValues::::insert(netuid_3, 3_000_000_000); Owner::::insert(hotkey1, coldkey1); Owner::::insert(hotkey2, coldkey2); @@ -373,9 +372,21 @@ fn test_migrate_rao() { // Run the coinbase let emission: u64 = 1_000_000_000; SubtensorModule::run_coinbase(I96F32::from_num(emission)); - close(SubnetTaoInEmission::::get(netuid_1), emission/6, 100); - close(SubnetTaoInEmission::::get(netuid_2), 2*(emission/6), 100); - close(SubnetTaoInEmission::::get(netuid_3), 3*(emission/6), 100); + close( + SubnetTaoInEmission::::get(netuid_1), + emission / 6, + 100, + ); + close( + SubnetTaoInEmission::::get(netuid_2), + 2 * (emission / 6), + 100, + ); + close( + SubnetTaoInEmission::::get(netuid_3), + 3 * (emission / 6), + 100, + ); }); }