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
6 changes: 5 additions & 1 deletion pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,10 +1556,14 @@ pub mod pallet {
OptionQuery,
>;

/// --- MAP ( netuid ) --> LockState | Aggregate owner-coldkey lock for a subnet.
/// --- MAP ( netuid ) --> LockState | Total perpetual lock to the owner hotkey for a subnet.
#[pallet::storage]
pub type OwnerLock<T: Config> = StorageMap<_, Identity, NetUid, LockState, OptionQuery>;

/// --- MAP ( netuid ) --> LockState | Total decaying lock to the owner hotkey for a subnet.
#[pallet::storage]
pub type DecayingOwnerLock<T: Config> = StorageMap<_, Identity, NetUid, LockState, OptionQuery>;

/// --- DMAP ( coldkey, netuid ) --> false | When present, this coldkey's lock decays.
/// Missing entries mean the lock is perpetual.
#[pallet::storage]
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 @@ -178,7 +178,9 @@ mod hooks {
// Fix testnet Subtensor TotalIssuance after the EVM fees issue.
.saturating_add(migrations::migrate_fix_total_issuance_evm_fees::migrate_fix_total_issuance_evm_fees::<T>())
// Remove deprecated conviction lock storage.
.saturating_add(migrations::migrate_remove_deprecated_conviction_maps::migrate_remove_deprecated_conviction_maps::<T>());
.saturating_add(migrations::migrate_remove_deprecated_conviction_maps::migrate_remove_deprecated_conviction_maps::<T>())
// Reset testnet conviction lock storage before deploying the current design.
.saturating_add(migrations::migrate_reset_testnet_conviction_locks::migrate_reset_testnet_conviction_locks::<T>());
weight
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use super::*;
use frame_support::weights::Weight;
use scale_info::prelude::string::String;

/// Clears conviction v2 lock state that only exists on testnet before this
/// conviction design is deployed more broadly.
///
/// `devnet-ready` had `Lock`, `HotkeyLock`, `DecayingHotkeyLock`, `OwnerLock`,
/// and `DecayingLock`, but did not have `DecayingOwnerLock`. `OwnerLock` also
/// used the old owner-coldkey aggregate semantics. Clear these prefixes without
/// decoding values so old or incompatible aggregate bytes are removed safely.
pub fn migrate_reset_testnet_conviction_locks<T: Config>() -> Weight {
let migration_name = b"migrate_reset_testnet_conviction_locks".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)
);

// This only affects testnet: mainnet has not had this conviction lock state
// deployed with live values yet.
let lock_removal = Lock::<T>::clear(u32::MAX, None);
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] Migration clears user-sized lock storage in one upgrade block

Lock, HotkeyLock, DecayingHotkeyLock, OwnerLock, DecayingOwnerLock, and DecayingLock are cleared with u32::MAX in a single on_runtime_upgrade migration. These maps can scale with user lock activity, and computing the weight after clear() does not bound the work already performed. If testnet/devnet has more entries than expected, the upgrade can exceed block limits or stall. Make this bounded with finite clear limits plus a cursor/progress flag, or otherwise gate/prove the exact live state size before running it.

weight = weight.saturating_add(
T::DbWeight::get().reads_writes(lock_removal.loops as u64, lock_removal.backend as u64),
);

let hotkey_lock_removal = HotkeyLock::<T>::clear(u32::MAX, None);
weight = weight.saturating_add(T::DbWeight::get().reads_writes(
hotkey_lock_removal.loops as u64,
hotkey_lock_removal.backend as u64,
));

let decaying_hotkey_lock_removal = DecayingHotkeyLock::<T>::clear(u32::MAX, None);
weight = weight.saturating_add(T::DbWeight::get().reads_writes(
decaying_hotkey_lock_removal.loops as u64,
decaying_hotkey_lock_removal.backend as u64,
));

let owner_lock_removal = OwnerLock::<T>::clear(u32::MAX, None);
weight = weight.saturating_add(T::DbWeight::get().reads_writes(
owner_lock_removal.loops as u64,
owner_lock_removal.backend as u64,
));

let decaying_owner_lock_removal = DecayingOwnerLock::<T>::clear(u32::MAX, None);
weight = weight.saturating_add(T::DbWeight::get().reads_writes(
decaying_owner_lock_removal.loops as u64,
decaying_owner_lock_removal.backend as u64,
));

let decaying_lock_removal = DecayingLock::<T>::clear(u32::MAX, None);
weight = weight.saturating_add(T::DbWeight::get().reads_writes(
decaying_lock_removal.loops as u64,
decaying_lock_removal.backend as u64,
));

HasMigrationRun::<T>::insert(&migration_name, true);
weight = weight.saturating_add(T::DbWeight::get().writes(1));

log::info!(
"Migration '{:?}' completed successfully. Removed Lock: {:?}, HotkeyLock: {:?}, DecayingHotkeyLock: {:?}, OwnerLock: {:?}, DecayingOwnerLock: {:?}, DecayingLock: {:?}.",
String::from_utf8_lossy(&migration_name),
lock_removal.backend,
hotkey_lock_removal.backend,
decaying_hotkey_lock_removal.backend,
owner_lock_removal.backend,
decaying_owner_lock_removal.backend,
decaying_lock_removal.backend,
);

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 @@ -49,6 +49,7 @@ pub mod migrate_remove_unused_maps_and_values;
pub mod migrate_remove_zero_total_hotkey_alpha;
pub mod migrate_reset_bonds_moving_average;
pub mod migrate_reset_max_burn;
pub mod migrate_reset_testnet_conviction_locks;
pub mod migrate_reset_unactive_sn;
pub mod migrate_set_first_emission_block_number;
pub mod migrate_set_min_burn;
Expand Down
Loading