diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 7a64acba44..b21ba442de 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -611,7 +611,7 @@ mod dispatches { /// - The delegate is setting a take which is not lower than the previous. /// #[pallet::call_index(65)] - #[pallet::weight((::WeightInfo::decrease_take(), DispatchClass::Normal, Pays::No))] + #[pallet::weight((::WeightInfo::decrease_take(), DispatchClass::Normal, Pays::Yes))] pub fn decrease_take( origin: OriginFor, hotkey: T::AccountId, @@ -651,7 +651,7 @@ mod dispatches { /// - The delegate is setting a take which is not greater than the previous. /// #[pallet::call_index(66)] - #[pallet::weight((::WeightInfo::increase_take(), DispatchClass::Normal, Pays::No))] + #[pallet::weight((::WeightInfo::increase_take(), DispatchClass::Normal, Pays::Yes))] pub fn increase_take( origin: OriginFor, hotkey: T::AccountId, diff --git a/pallets/subtensor/src/swap/swap_hotkey.rs b/pallets/subtensor/src/swap/swap_hotkey.rs index a266798aeb..ee97d3d099 100644 --- a/pallets/subtensor/src/swap/swap_hotkey.rs +++ b/pallets/subtensor/src/swap/swap_hotkey.rs @@ -46,17 +46,21 @@ impl Pallet { Error::::NonAssociatedColdKey ); - // 3. If the new hotkey already exists globally, ensure the coldkey owns it + // 3. Initialize the weight for this operation. This includes the old-hotkey + // owner check above. + let mut weight = T::DbWeight::get().reads(2); + + // 4. If the new hotkey already exists globally, ensure the coldkey owns it if Self::hotkey_account_exists(new_hotkey) { + weight.saturating_accrue(T::DbWeight::get().reads(3)); ensure!( Self::coldkey_owns_hotkey(&coldkey, new_hotkey), Error::::NonAssociatedColdKey ); + } else { + weight.saturating_accrue(T::DbWeight::get().reads(1)); } - // 4. Initialize the weight for this operation - let mut weight = T::DbWeight::get().reads(2); - // 5. Ensure the new hotkey is different from the old one ensure!(old_hotkey != new_hotkey, Error::::NewHotKeyIsSameWithOld); diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index 7906c8b798..46b938b484 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -22,6 +22,26 @@ use crate::*; staking::add_stake() tests ************************************************************/ +#[test] +fn test_delegate_take_dispatch_info_pays_fee() { + new_test_ext(1).execute_with(|| { + let hotkey = U256::from(1); + let take = SubtensorModule::get_min_delegate_take(); + + let decrease_take_call = + RuntimeCall::SubtensorModule(SubtensorCall::decrease_take { hotkey, take }); + let decrease_take_dispatch_info = decrease_take_call.get_dispatch_info(); + assert_eq!(decrease_take_dispatch_info.class, DispatchClass::Normal); + assert_eq!(decrease_take_dispatch_info.pays_fee, Pays::Yes); + + let increase_take_call = + RuntimeCall::SubtensorModule(SubtensorCall::increase_take { hotkey, take }); + let increase_take_dispatch_info = increase_take_call.get_dispatch_info(); + assert_eq!(increase_take_dispatch_info.class, DispatchClass::Normal); + assert_eq!(increase_take_dispatch_info.pays_fee, Pays::Yes); + }); +} + #[test] fn test_add_stake_dispatch_info_ok() { new_test_ext(1).execute_with(|| { diff --git a/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs b/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs index 1e200aaedd..beb8ec9a75 100644 --- a/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs +++ b/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs @@ -900,22 +900,23 @@ fn test_swap_owner_old_hotkey_not_exist() { }); } -// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey_with_subnet -- test_swap_owner_new_hotkey_already_exists --exact --nocapture +// SKIP_WASM_BUILD=1 cargo test --package pallet-subtensor --lib -- tests::swap_hotkey_with_subnet::test_swap_owner_new_hotkey_already_exists --exact --nocapture #[test] fn test_swap_owner_new_hotkey_already_exists() { new_test_ext(1).execute_with(|| { let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); let coldkey = U256::from(3); + let another_coldkey = U256::from(4); - let netuid = add_dynamic_network(&new_hotkey, &coldkey); + let netuid = add_dynamic_network(&old_hotkey, &coldkey); add_balance_to_coldkey_account(&coldkey, 1_000_000_000_000_u64.into()); // old_hotkey is owned by coldkey; new_hotkey was already registered on `netuid` // by add_dynamic_network (the condition under test). Do NOT reassign new_hotkey to // a foreign coldkey — the new_hotkey-ownership check (NonAssociatedColdKey) would // then fire before the already-registered-in-subnet check this test targets. - Owner::::insert(old_hotkey, coldkey); + Owner::::insert(new_hotkey, another_coldkey); // Perform the swap System::set_block_number(System::block_number() + HotkeySwapOnSubnetInterval::get()); @@ -927,7 +928,7 @@ fn test_swap_owner_new_hotkey_already_exists() { Some(netuid), false ), - Error::::HotKeyAlreadyRegisteredInSubNet + Error::::NonAssociatedColdKey ); // Verify the swap diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 5cf4d7aadb..94e25a46fb 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -234,7 +234,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: 419, + spec_version: 420, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1,