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
7 changes: 6 additions & 1 deletion pallets/subtensor/src/macros/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ mod hooks {
// Fix lock state left behind by subnet-scoped hotkey swaps.
.saturating_add(migrations::migrate_fix_subnet_hotkey_lock_swaps::migrate_fix_subnet_hotkey_lock_swaps::<T>())
// Populate reverse lookup index for EVM address associations.
.saturating_add(migrations::migrate_associated_evm_address_index::migrate_associated_evm_address_index::<T>());
.saturating_add(migrations::migrate_associated_evm_address_index::migrate_associated_evm_address_index::<T>())
// Fold the deprecated SubnetTaoProvided / SubnetAlphaInProvided residuals into the
// main AMM reserves (issue #2793). reserve() dropped the *Provided addend, so this
// migration must run at upgrade to keep reserves / spot price continuous. It is
// HasMigrationRun-guarded and idempotent.
.saturating_add(migrations::migrate_cleanup_swap_v3::migrate_cleanup_swap_v3::<T>());
weight
}

Expand Down
40 changes: 40 additions & 0 deletions pallets/subtensor/src/tests/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3342,6 +3342,46 @@ fn test_migrate_cleanup_swap_v3() {
});
}

// Regression test for issue #2793: migrate_cleanup_swap_v3 MUST be wired into the pallet
// on_runtime_upgrade hook. Seeds a *Provided residual, runs the full upgrade hook, and asserts
// the residual is folded into the main reserves. Without the wiring line in hooks.rs this fails
// (the residual is never folded), which is exactly the regression the issue reports.
#[test]
fn test_migrate_cleanup_swap_v3_runs_on_runtime_upgrade() {
use crate::migrations::migrate_cleanup_swap_v3::deprecated_swap_maps;
use frame_support::traits::Hooks;

new_test_ext(1).execute_with(|| {
let netuid = NetUid::from(1);
let provided: u64 = 9876;

// Seed residuals that the wired migration must fold into the main reserves at upgrade.
deprecated_swap_maps::SubnetTaoProvided::<Test>::insert(netuid, TaoBalance::from(provided));
deprecated_swap_maps::SubnetAlphaInProvided::<Test>::insert(
netuid,
AlphaBalance::from(provided),
);

let tao_before = u64::from(SubnetTAO::<Test>::get(netuid));
let alpha_before = u64::from(SubnetAlphaIn::<Test>::get(netuid));

// Drive the real upgrade path. cleanup_swap_v3 is the last migration in the chain.
let _ = <crate::Pallet<Test> as Hooks<u64>>::on_runtime_upgrade();

// The wired migration folded the residual into the main reserves and cleared the maps.
assert!(!deprecated_swap_maps::SubnetTaoProvided::<Test>::contains_key(netuid));
assert!(!deprecated_swap_maps::SubnetAlphaInProvided::<Test>::contains_key(netuid));
assert_eq!(
u64::from(SubnetTAO::<Test>::get(netuid)),
tao_before + provided
);
assert_eq!(
u64::from(SubnetAlphaIn::<Test>::get(netuid)),
alpha_before + provided
);
});
}

#[test]
fn test_migrate_coldkey_swap_scheduled_to_announcements() {
new_test_ext(1000).execute_with(|| {
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,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: 428,
spec_version: 429,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down