Skip to content

Commit 9d1f6c9

Browse files
author
Samuel Dare
committed
feat: remove schedule coldkey swap
1 parent 3e8afeb commit 9d1f6c9

File tree

4 files changed

+21
-42
lines changed

4 files changed

+21
-42
lines changed

pallets/subtensor/src/benchmarks.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -429,30 +429,4 @@ reveal_weights {
429429

430430
}: reveal_weights(RawOrigin::Signed(hotkey.clone()), netuid, uids, weight_values, salt, version_key)
431431

432-
schedule_coldkey_swap {
433-
let seed: u32 = 1;
434-
let old_coldkey: T::AccountId = account("OldColdkey", 0, seed);
435-
let new_coldkey: T::AccountId = account("NewColdkey", 0, seed + 1);
436-
let hotkey: T::AccountId = account("Hotkey", 0, seed);
437-
438-
let netuid = 1u16;
439-
let tempo = 1u16;
440-
let block_number: u64 = Subtensor::<T>::get_current_block_as_u64();
441-
let nonce = 0;
442-
443-
// Initialize the network
444-
Subtensor::<T>::init_new_network(netuid, tempo);
445-
Subtensor::<T>::set_network_registration_allowed(netuid, true);
446-
447-
// Add balance to the old coldkey account
448-
let amount_to_be_staked: u64 = 1000000u32.into();
449-
Subtensor::<T>::add_balance_to_coldkey_account(&old_coldkey.clone(), amount_to_be_staked+1000000000);
450-
// Burned register the hotkey with the old coldkey
451-
assert_ok!(Subtensor::<T>::burned_register(
452-
RawOrigin::Signed(old_coldkey.clone()).into(),
453-
netuid,
454-
hotkey.clone()
455-
));
456-
457-
}: schedule_coldkey_swap(RawOrigin::Signed(old_coldkey.clone()), new_coldkey.clone(), vec![], block_number, nonce)
458432
}

pallets/subtensor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2089,7 +2089,6 @@ pub mod pallet {
20892089
) -> DispatchResultWithPostInfo {
20902090
Self::do_swap_coldkey(origin, &new_coldkey)
20912091
}
2092-
20932092
/// Unstakes all tokens associated with a hotkey and transfers them to a new coldkey.
20942093
///
20952094
/// # Arguments
@@ -2105,6 +2104,7 @@ pub mod pallet {
21052104
/// # Weight
21062105
///
21072106
/// Weight is calculated based on the number of database reads and writes.
2107+
#[cfg(test)]
21082108
#[pallet::call_index(72)]
21092109
#[pallet::weight((Weight::from_parts(21_000_000, 0)
21102110
.saturating_add(T::DbWeight::get().reads(3))

pallets/subtensor/src/swap.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ impl<T: Config> Pallet<T> {
3131
new_hotkey: &T::AccountId,
3232
) -> DispatchResultWithPostInfo {
3333
let coldkey = ensure_signed(origin)?;
34-
ensure!(
35-
!Self::coldkey_in_arbitration(&coldkey),
36-
Error::<T>::ColdkeyIsInArbitration
37-
);
3834

3935
let mut weight = T::DbWeight::get().reads(2);
4036

@@ -60,6 +56,16 @@ impl<T: Config> Pallet<T> {
6056
T::DbWeight::get().reads((TotalNetworks::<T>::get().saturating_add(1u16)) as u64),
6157
);
6258

59+
let swap_cost = Self::get_hotkey_swap_cost();
60+
log::debug!("Swap cost: {:?}", swap_cost);
61+
62+
ensure!(
63+
Self::can_remove_balance_from_coldkey_account(&coldkey, swap_cost),
64+
Error::<T>::NotEnoughBalanceToPaySwapHotKey
65+
);
66+
let actual_burn_amount = Self::remove_balance_from_coldkey_account(&coldkey, swap_cost)?;
67+
Self::burn_tokens(actual_burn_amount);
68+
6369
Self::swap_owner(old_hotkey, new_hotkey, &coldkey, &mut weight);
6470
Self::swap_total_hotkey_stake(old_hotkey, new_hotkey, &mut weight);
6571
Self::swap_delegates(old_hotkey, new_hotkey, &mut weight);
@@ -189,15 +195,15 @@ impl<T: Config> Pallet<T> {
189195
///
190196
/// This function calculates the remaining arbitration period by subtracting the current block number
191197
/// from the arbitration block number of the coldkey.
192-
// pub fn get_remaining_arbitration_period(coldkey: &T::AccountId) -> u64 {
193-
// let current_block: u64 = Self::get_current_block_as_u64();
194-
// let arbitration_block: u64 = ColdkeyArbitrationBlock::<T>::get(coldkey);
195-
// if arbitration_block > current_block {
196-
// arbitration_block.saturating_sub(current_block)
197-
// } else {
198-
// 0
199-
// }
200-
// }
198+
pub fn get_remaining_arbitration_period(coldkey: &T::AccountId) -> u64 {
199+
let current_block: u64 = Self::get_current_block_as_u64();
200+
let arbitration_block: u64 = ColdkeyArbitrationBlock::<T>::get(coldkey);
201+
if arbitration_block > current_block {
202+
arbitration_block.saturating_sub(current_block)
203+
} else {
204+
0
205+
}
206+
}
201207

202208
pub fn meets_min_allowed_coldkey_balance(coldkey: &T::AccountId) -> bool {
203209
let all_staked_keys: Vec<T::AccountId> = StakingHotkeys::<T>::get(coldkey);

runtime/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@ impl Contains<RuntimeCall> for SafeModeWhitelistedCalls {
312312
| RuntimeCall::SafeMode(_)
313313
| RuntimeCall::Timestamp(_)
314314
| RuntimeCall::SubtensorModule(
315-
pallet_subtensor::Call::schedule_coldkey_swap { .. }
316-
| pallet_subtensor::Call::set_weights { .. }
315+
pallet_subtensor::Call::set_weights { .. }
317316
| pallet_subtensor::Call::set_root_weights { .. }
318317
| pallet_subtensor::Call::serve_axon { .. }
319318
)

0 commit comments

Comments
 (0)