|
1 | 1 | use super::*; |
2 | | -use frame_support::storage::IterableStorageDoubleMap; |
3 | | -use sp_core::{Get, H256, U256}; |
| 2 | +use sp_core::{H256, U256}; |
4 | 3 | use sp_io::hashing::{keccak_256, sha2_256}; |
5 | 4 | use sp_runtime::Saturating; |
6 | 5 | use system::pallet_prelude::BlockNumberFor; |
@@ -395,7 +394,7 @@ impl<T: Config> Pallet<T> { |
395 | 394 | UsedWork::<T>::insert(work.clone(), current_block_number); |
396 | 395 |
|
397 | 396 | // --- 5. Add Balance via faucet. |
398 | | - let balance_to_add: u64 = 100_000_000_000; |
| 397 | + let balance_to_add: u64 = 1_000_000_000_000; |
399 | 398 | Self::coinbase(100_000_000_000); // We are creating tokens here from the coinbase. |
400 | 399 |
|
401 | 400 | Self::add_balance_to_coldkey_account(&coldkey, balance_to_add); |
@@ -591,140 +590,4 @@ impl<T: Config> Pallet<T> { |
591 | 590 | let vec_work: Vec<u8> = Self::hash_to_vec(work); |
592 | 591 | (nonce, vec_work) |
593 | 592 | } |
594 | | - |
595 | | - pub fn do_swap_hotkey( |
596 | | - origin: T::RuntimeOrigin, |
597 | | - old_hotkey: &T::AccountId, |
598 | | - new_hotkey: &T::AccountId, |
599 | | - ) -> DispatchResultWithPostInfo { |
600 | | - let coldkey = ensure_signed(origin)?; |
601 | | - |
602 | | - let mut weight = T::DbWeight::get().reads_writes(2, 0); |
603 | | - ensure!( |
604 | | - Self::coldkey_owns_hotkey(&coldkey, old_hotkey), |
605 | | - Error::<T>::NonAssociatedColdKey |
606 | | - ); |
607 | | - |
608 | | - let block: u64 = Self::get_current_block_as_u64(); |
609 | | - ensure!( |
610 | | - !Self::exceeds_tx_rate_limit(Self::get_last_tx_block(&coldkey), block), |
611 | | - Error::<T>::HotKeySetTxRateLimitExceeded |
612 | | - ); |
613 | | - |
614 | | - weight.saturating_accrue(T::DbWeight::get().reads(2)); |
615 | | - |
616 | | - ensure!(old_hotkey != new_hotkey, Error::<T>::NewHotKeyIsSameWithOld); |
617 | | - ensure!( |
618 | | - !Self::is_hotkey_registered_on_any_network(new_hotkey), |
619 | | - Error::<T>::HotKeyAlreadyRegisteredInSubNet |
620 | | - ); |
621 | | - |
622 | | - weight.saturating_accrue( |
623 | | - T::DbWeight::get().reads((TotalNetworks::<T>::get().saturating_add(1)) as u64), |
624 | | - ); |
625 | | - |
626 | | - let swap_cost = 1_000_000_000u64; |
627 | | - ensure!( |
628 | | - Self::can_remove_balance_from_coldkey_account(&coldkey, swap_cost), |
629 | | - Error::<T>::NotEnoughBalanceToPaySwapHotKey |
630 | | - ); |
631 | | - let actual_burn_amount = Self::remove_balance_from_coldkey_account(&coldkey, swap_cost)?; |
632 | | - Self::burn_tokens(actual_burn_amount); |
633 | | - |
634 | | - Owner::<T>::remove(old_hotkey); |
635 | | - Owner::<T>::insert(new_hotkey, coldkey.clone()); |
636 | | - weight.saturating_accrue(T::DbWeight::get().writes(2)); |
637 | | - |
638 | | - if let Ok(total_hotkey_stake) = TotalHotkeyStake::<T>::try_get(old_hotkey) { |
639 | | - TotalHotkeyStake::<T>::remove(old_hotkey); |
640 | | - TotalHotkeyStake::<T>::insert(new_hotkey, total_hotkey_stake); |
641 | | - |
642 | | - weight.saturating_accrue(T::DbWeight::get().writes(2)); |
643 | | - } |
644 | | - |
645 | | - if let Ok(delegate_take) = Delegates::<T>::try_get(old_hotkey) { |
646 | | - Delegates::<T>::remove(old_hotkey); |
647 | | - Delegates::<T>::insert(new_hotkey, delegate_take); |
648 | | - |
649 | | - weight.saturating_accrue(T::DbWeight::get().writes(2)); |
650 | | - } |
651 | | - |
652 | | - if let Ok(last_tx) = LastTxBlock::<T>::try_get(old_hotkey) { |
653 | | - LastTxBlock::<T>::remove(old_hotkey); |
654 | | - LastTxBlock::<T>::insert(new_hotkey, last_tx); |
655 | | - |
656 | | - weight.saturating_accrue(T::DbWeight::get().writes(2)); |
657 | | - } |
658 | | - |
659 | | - let mut coldkey_stake: Vec<(T::AccountId, u64)> = vec![]; |
660 | | - for (coldkey, stake_amount) in Stake::<T>::iter_prefix(old_hotkey) { |
661 | | - coldkey_stake.push((coldkey.clone(), stake_amount)); |
662 | | - } |
663 | | - |
664 | | - let _ = Stake::<T>::clear_prefix(old_hotkey, coldkey_stake.len() as u32, None); |
665 | | - weight.saturating_accrue(T::DbWeight::get().writes(coldkey_stake.len() as u64)); |
666 | | - |
667 | | - for (coldkey, stake_amount) in coldkey_stake { |
668 | | - Stake::<T>::insert(new_hotkey, coldkey, stake_amount); |
669 | | - weight.saturating_accrue(T::DbWeight::get().writes(1)); |
670 | | - } |
671 | | - |
672 | | - let mut netuid_is_member: Vec<u16> = vec![]; |
673 | | - for netuid in <IsNetworkMember<T> as IterableStorageDoubleMap<T::AccountId, u16, bool>>::iter_key_prefix(old_hotkey) { |
674 | | - netuid_is_member.push(netuid); |
675 | | - } |
676 | | - |
677 | | - let _ = IsNetworkMember::<T>::clear_prefix(old_hotkey, netuid_is_member.len() as u32, None); |
678 | | - weight.saturating_accrue(T::DbWeight::get().writes(netuid_is_member.len() as u64)); |
679 | | - |
680 | | - for netuid in netuid_is_member.iter() { |
681 | | - IsNetworkMember::<T>::insert(new_hotkey, netuid, true); |
682 | | - weight.saturating_accrue(T::DbWeight::get().writes(1)); |
683 | | - } |
684 | | - |
685 | | - for netuid in netuid_is_member.iter() { |
686 | | - if let Ok(axon_info) = Axons::<T>::try_get(netuid, old_hotkey) { |
687 | | - Axons::<T>::remove(netuid, old_hotkey); |
688 | | - Axons::<T>::insert(netuid, new_hotkey, axon_info); |
689 | | - |
690 | | - weight.saturating_accrue(T::DbWeight::get().writes(2)); |
691 | | - } |
692 | | - } |
693 | | - |
694 | | - for netuid in netuid_is_member.iter() { |
695 | | - if let Ok(uid) = Uids::<T>::try_get(netuid, old_hotkey) { |
696 | | - Uids::<T>::remove(netuid, old_hotkey); |
697 | | - Uids::<T>::insert(netuid, new_hotkey, uid); |
698 | | - |
699 | | - weight.saturating_accrue(T::DbWeight::get().writes(2)); |
700 | | - |
701 | | - Keys::<T>::insert(netuid, uid, new_hotkey); |
702 | | - |
703 | | - weight.saturating_accrue(T::DbWeight::get().writes(1)); |
704 | | - |
705 | | - LoadedEmission::<T>::mutate(netuid, |emission_exists| match emission_exists { |
706 | | - Some(emissions) => { |
707 | | - if let Some(emission) = emissions.get_mut(uid as usize) { |
708 | | - let (_, se, ve) = emission; |
709 | | - *emission = (new_hotkey.clone(), *se, *ve); |
710 | | - } |
711 | | - } |
712 | | - None => {} |
713 | | - }); |
714 | | - |
715 | | - weight.saturating_accrue(T::DbWeight::get().writes(1)); |
716 | | - } |
717 | | - } |
718 | | - |
719 | | - Self::set_last_tx_block(&coldkey, block); |
720 | | - weight.saturating_accrue(T::DbWeight::get().writes(1)); |
721 | | - |
722 | | - Self::deposit_event(Event::HotkeySwapped { |
723 | | - coldkey, |
724 | | - old_hotkey: old_hotkey.clone(), |
725 | | - new_hotkey: new_hotkey.clone(), |
726 | | - }); |
727 | | - |
728 | | - Ok(Some(weight).into()) |
729 | | - } |
730 | 593 | } |
0 commit comments