Skip to content
Open
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
4 changes: 2 additions & 2 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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((<T as crate::pallet::Config>::WeightInfo::decrease_take(), DispatchClass::Normal, Pays::No))]
#[pallet::weight((<T as crate::pallet::Config>::WeightInfo::decrease_take(), DispatchClass::Normal, Pays::Yes))]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HIGH] Runtime fee semantics changed without a spec_version bump

This changes dispatch metadata for decrease_take from Pays::No to Pays::Yes, and the same PR also changes increase_take. That is a runtime-affecting semantic change, but the diff does not update runtime/src/lib.rs spec_version (currently 417). Shipping upgraded Wasm with the same spec version can leave nodes treating old native runtime code as compatible with the new on-chain runtime, which is especially risky here because old and new code disagree on whether these calls withdraw transaction fees. Bump spec_version in this PR.

pub fn decrease_take(
origin: OriginFor<T>,
hotkey: T::AccountId,
Expand Down Expand Up @@ -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((<T as crate::pallet::Config>::WeightInfo::increase_take(), DispatchClass::Normal, Pays::No))]
#[pallet::weight((<T as crate::pallet::Config>::WeightInfo::increase_take(), DispatchClass::Normal, Pays::Yes))]
pub fn increase_take(
origin: OriginFor<T>,
hotkey: T::AccountId,
Expand Down
12 changes: 8 additions & 4 deletions pallets/subtensor/src/swap/swap_hotkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,21 @@ impl<T: Config> Pallet<T> {
Error::<T>::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::<T>::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::<T>::NewHotKeyIsSameWithOld);

Expand Down
20 changes: 20 additions & 0 deletions pallets/subtensor/src/tests/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
Expand Down
9 changes: 5 additions & 4 deletions pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Test>::insert(old_hotkey, coldkey);
Owner::<Test>::insert(new_hotkey, another_coldkey);

// Perform the swap
System::set_block_number(System::block_number() + HotkeySwapOnSubnetInterval::get());
Expand All @@ -927,7 +928,7 @@ fn test_swap_owner_new_hotkey_already_exists() {
Some(netuid),
false
),
Error::<Test>::HotKeyAlreadyRegisteredInSubNet
Error::<Test>::NonAssociatedColdKey
);

// Verify the swap
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading