Skip to content

Commit c82f82f

Browse files
author
Samuel Dare
committed
chore: pr comments
1 parent 49d19b1 commit c82f82f

File tree

5 files changed

+44
-105
lines changed

5 files changed

+44
-105
lines changed

pallets/subtensor/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ pub mod pallet {
364364
pub type Owner<T: Config> =
365365
StorageMap<_, Blake2_128Concat, T::AccountId, T::AccountId, ValueQuery, DefaultAccount<T>>;
366366
#[pallet::storage] // --- MAP ( cold ) --> Vec<hot> | Returns the vector of hotkeys controlled by this coldkey.
367-
pub type Owned<T: Config> =
367+
pub type OwnedHotkeys<T: Config> =
368368
StorageMap<_, Blake2_128Concat, T::AccountId, Vec<T::AccountId>, ValueQuery>;
369369
#[pallet::storage] // --- MAP ( hot ) --> take | Returns the hotkey delegation take. And signals that this key is open for delegation.
370370
pub type Delegates<T: Config> =
@@ -1207,11 +1207,11 @@ pub mod pallet {
12071207
// Fill stake information.
12081208
Owner::<T>::insert(hotkey.clone(), coldkey.clone());
12091209

1210-
// Update Owned map
1211-
let mut hotkeys = Owned::<T>::get(coldkey);
1210+
// Update OwnedHotkeys map
1211+
let mut hotkeys = OwnedHotkeys::<T>::get(coldkey);
12121212
if !hotkeys.contains(hotkey) {
12131213
hotkeys.push(hotkey.clone());
1214-
Owned::<T>::insert(coldkey, hotkeys);
1214+
OwnedHotkeys::<T>::insert(coldkey, hotkeys);
12151215
}
12161216

12171217
TotalHotkeyStake::<T>::insert(hotkey.clone(), stake);
@@ -1336,7 +1336,7 @@ pub mod pallet {
13361336
.saturating_add(migration::migrate_delete_subnet_3::<T>())
13371337
// Doesn't check storage version. TODO: Remove after upgrade
13381338
.saturating_add(migration::migration5_total_issuance::<T>(false))
1339-
// Populate Owned map for coldkey swap. Doesn't update storage vesion.
1339+
// Populate OwnedHotkeys map for coldkey swap. Doesn't update storage vesion.
13401340
.saturating_add(migration::migrate_populate_owned::<T>());
13411341

13421342
weight

pallets/subtensor/src/migration.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,10 @@ pub fn migrate_to_v2_fixed_total_stake<T: Config>() -> Weight {
481481
pub fn migrate_populate_owned<T: Config>() -> Weight {
482482
// Setup migration weight
483483
let mut weight = T::DbWeight::get().reads(1);
484-
let migration_name = "Populate Owned map";
484+
let migration_name = "Populate OwnedHotkeys map";
485485

486-
// Check if this migration is needed (if Owned map is empty)
487-
let migrate = Owned::<T>::iter().next().is_none();
486+
// Check if this migration is needed (if OwnedHotkeys map is empty)
487+
let migrate = OwnedHotkeys::<T>::iter().next().is_none();
488488

489489
// Only runs if we haven't already updated version past above new_storage_version.
490490
if migrate {
@@ -493,7 +493,7 @@ pub fn migrate_populate_owned<T: Config>() -> Weight {
493493
let mut longest_hotkey_vector = 0;
494494
let mut longest_coldkey: Option<T::AccountId> = None;
495495
Owner::<T>::iter().for_each(|(hotkey, coldkey)| {
496-
let mut hotkeys = Owned::<T>::get(&coldkey);
496+
let mut hotkeys = OwnedHotkeys::<T>::get(&coldkey);
497497
if !hotkeys.contains(&hotkey) {
498498
hotkeys.push(hotkey);
499499
if longest_hotkey_vector < hotkeys.len() {
@@ -502,7 +502,7 @@ pub fn migrate_populate_owned<T: Config>() -> Weight {
502502
}
503503
}
504504

505-
Owned::<T>::insert(&coldkey, hotkeys);
505+
OwnedHotkeys::<T>::insert(&coldkey, hotkeys);
506506

507507
weight.saturating_accrue(T::DbWeight::get().reads_writes(2, 1));
508508
});

pallets/subtensor/src/staking.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,11 @@ impl<T: Config> Pallet<T> {
561561
Stake::<T>::insert(hotkey, coldkey, 0);
562562
Owner::<T>::insert(hotkey, coldkey);
563563

564-
// Update Owned map
565-
let mut hotkeys = Owned::<T>::get(coldkey);
564+
// Update OwnedHotkeys map
565+
let mut hotkeys = OwnedHotkeys::<T>::get(coldkey);
566566
if !hotkeys.contains(hotkey) {
567567
hotkeys.push(hotkey.clone());
568-
Owned::<T>::insert(coldkey, hotkeys);
568+
OwnedHotkeys::<T>::insert(coldkey, hotkeys);
569569
}
570570
}
571571
}

pallets/subtensor/src/swap.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,17 @@ impl<T: Config> Pallet<T> {
137137
Error::<T>::NewColdKeyIsSameWithOld
138138
);
139139

140-
// Check if the new coldkey is already associated with any hotkeys
141-
ensure!(
142-
!Self::coldkey_has_associated_hotkeys(new_coldkey),
143-
Error::<T>::ColdKeyAlreadyAssociated
144-
);
140+
// // Check if the new coldkey is already associated with any hotkeys
141+
// ensure!(
142+
// !Self::coldkey_has_associated_hotkeys(new_coldkey),
143+
// Error::<T>::ColdKeyAlreadyAssociated
144+
// );
145145

146146
let block: u64 = Self::get_current_block_as_u64();
147-
ensure!(
148-
!Self::exceeds_tx_rate_limit(Self::get_last_tx_block(old_coldkey), block),
149-
Error::<T>::ColdKeySwapTxRateLimitExceeded
150-
);
147+
// ensure!(
148+
// !Self::exceeds_tx_rate_limit(Self::get_last_tx_block(old_coldkey), block),
149+
// Error::<T>::ColdKeySwapTxRateLimitExceeded
150+
// );
151151

152152
// Note: we probably want to make this free
153153
let swap_cost = Self::get_coldkey_swap_cost();
@@ -224,13 +224,13 @@ impl<T: Config> Pallet<T> {
224224
Owner::<T>::remove(old_hotkey);
225225
Owner::<T>::insert(new_hotkey, coldkey.clone());
226226

227-
// Update Owned map
228-
let mut hotkeys = Owned::<T>::get(coldkey);
227+
// Update OwnedHotkeys map
228+
let mut hotkeys = OwnedHotkeys::<T>::get(coldkey);
229229
if !hotkeys.contains(new_hotkey) {
230230
hotkeys.push(new_hotkey.clone());
231231
}
232232
hotkeys.retain(|hk| *hk != *old_hotkey);
233-
Owned::<T>::insert(coldkey, hotkeys);
233+
OwnedHotkeys::<T>::insert(coldkey, hotkeys);
234234

235235
weight.saturating_accrue(T::DbWeight::get().writes(2));
236236
}
@@ -545,7 +545,7 @@ impl<T: Config> Pallet<T> {
545545
weight: &mut Weight,
546546
) {
547547
// Find all hotkeys for this coldkey
548-
let hotkeys = Owned::<T>::get(old_coldkey);
548+
let hotkeys = OwnedHotkeys::<T>::get(old_coldkey);
549549
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 0));
550550
for hotkey in hotkeys.iter() {
551551
let stake = Stake::<T>::get(&hotkey, old_coldkey);
@@ -572,7 +572,7 @@ impl<T: Config> Pallet<T> {
572572
new_coldkey: &T::AccountId,
573573
weight: &mut Weight,
574574
) {
575-
let hotkeys = Owned::<T>::get(old_coldkey);
575+
let hotkeys = OwnedHotkeys::<T>::get(old_coldkey);
576576
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 0));
577577
for hotkey in hotkeys.iter() {
578578
Owner::<T>::insert(&hotkey, new_coldkey);
@@ -599,7 +599,7 @@ impl<T: Config> Pallet<T> {
599599
weight: &mut Weight,
600600
) {
601601
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 0));
602-
for hotkey in Owned::<T>::get(old_coldkey).iter() {
602+
for hotkey in OwnedHotkeys::<T>::get(old_coldkey).iter() {
603603
let (stake, block) =
604604
TotalHotkeyColdkeyStakesThisInterval::<T>::get(&hotkey, old_coldkey);
605605
TotalHotkeyColdkeyStakesThisInterval::<T>::remove(&hotkey, old_coldkey);
@@ -665,10 +665,10 @@ impl<T: Config> Pallet<T> {
665665
new_coldkey: &T::AccountId,
666666
weight: &mut Weight,
667667
) {
668-
// Update Owned map with new coldkey
669-
let hotkeys = Owned::<T>::get(old_coldkey);
670-
Owned::<T>::remove(old_coldkey);
671-
Owned::<T>::insert(new_coldkey, hotkeys);
668+
// Update OwnedHotkeys map with new coldkey
669+
let hotkeys = OwnedHotkeys::<T>::get(old_coldkey);
670+
OwnedHotkeys::<T>::remove(old_coldkey);
671+
OwnedHotkeys::<T>::insert(new_coldkey, hotkeys);
672672
weight.saturating_accrue(T::DbWeight::get().reads_writes(0, 2));
673673
}
674674

pallets/subtensor/tests/swap.rs

Lines changed: 12 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,8 +1088,8 @@ fn test_do_swap_coldkey_success() {
10881088
assert_eq!(TotalColdkeyStake::<Test>::get(old_coldkey), stake_amount);
10891089
assert_eq!(Stake::<Test>::get(hotkey, old_coldkey), stake_amount);
10901090

1091-
assert_eq!(Owned::<Test>::get(old_coldkey), vec![hotkey]);
1092-
assert!(!Owned::<Test>::contains_key(new_coldkey));
1091+
assert_eq!(OwnedHotkeys::<Test>::get(old_coldkey), vec![hotkey]);
1092+
assert!(!OwnedHotkeys::<Test>::contains_key(new_coldkey));
10931093

10941094
// Get coldkey free balance before swap
10951095
let balance = SubtensorModule::get_coldkey_balance(&old_coldkey);
@@ -1108,8 +1108,8 @@ fn test_do_swap_coldkey_success() {
11081108
assert!(!TotalColdkeyStake::<Test>::contains_key(old_coldkey));
11091109
assert_eq!(Stake::<Test>::get(hotkey, new_coldkey), stake_amount);
11101110
assert!(!Stake::<Test>::contains_key(hotkey, old_coldkey));
1111-
assert_eq!(Owned::<Test>::get(new_coldkey), vec![hotkey]);
1112-
assert!(!Owned::<Test>::contains_key(old_coldkey));
1111+
assert_eq!(OwnedHotkeys::<Test>::get(new_coldkey), vec![hotkey]);
1112+
assert!(!OwnedHotkeys::<Test>::contains_key(old_coldkey));
11131113

11141114
// Verify balance transfer
11151115
assert_eq!(
@@ -1168,34 +1168,6 @@ fn test_do_swap_coldkey_same_keys() {
11681168
});
11691169
}
11701170

1171-
#[test]
1172-
fn test_do_swap_coldkey_new_key_already_associated() {
1173-
new_test_ext(1).execute_with(|| {
1174-
let old_coldkey = U256::from(1);
1175-
let new_coldkey = U256::from(2);
1176-
let hotkey1 = U256::from(3);
1177-
let hotkey2 = U256::from(4);
1178-
let netuid = 1u16;
1179-
let swap_cost = SubtensorModule::get_coldkey_swap_cost();
1180-
1181-
// Setup initial state
1182-
add_network(netuid, 13, 0);
1183-
register_ok_neuron(netuid, hotkey1, old_coldkey, 0);
1184-
register_ok_neuron(netuid, hotkey2, new_coldkey, 0);
1185-
SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, swap_cost);
1186-
1187-
// Attempt the swap
1188-
assert_err!(
1189-
SubtensorModule::do_swap_coldkey(
1190-
<<Test as Config>::RuntimeOrigin>::signed(old_coldkey),
1191-
&old_coldkey,
1192-
&new_coldkey
1193-
),
1194-
Error::<Test>::ColdKeyAlreadyAssociated
1195-
);
1196-
});
1197-
}
1198-
11991171
#[test]
12001172
fn test_swap_total_coldkey_stake() {
12011173
new_test_ext(1).execute_with(|| {
@@ -1235,8 +1207,8 @@ fn test_swap_stake_for_coldkey() {
12351207
Stake::<Test>::insert(hotkey1, old_coldkey, stake_amount1);
12361208
Stake::<Test>::insert(hotkey2, old_coldkey, stake_amount2);
12371209

1238-
// Populate Owned map
1239-
Owned::<Test>::insert(old_coldkey, vec![hotkey1, hotkey2]);
1210+
// Populate OwnedHotkeys map
1211+
OwnedHotkeys::<Test>::insert(old_coldkey, vec![hotkey1, hotkey2]);
12401212

12411213
// Perform the swap
12421214
SubtensorModule::swap_stake_for_coldkey(&old_coldkey, &new_coldkey, &mut weight);
@@ -1266,8 +1238,8 @@ fn test_swap_owner_for_coldkey() {
12661238
Owner::<Test>::insert(hotkey1, old_coldkey);
12671239
Owner::<Test>::insert(hotkey2, old_coldkey);
12681240

1269-
// Initialize Owned map
1270-
Owned::<Test>::insert(old_coldkey, vec![hotkey1, hotkey2]);
1241+
// Initialize OwnedHotkeys map
1242+
OwnedHotkeys::<Test>::insert(old_coldkey, vec![hotkey1, hotkey2]);
12711243

12721244
// Perform the swap
12731245
SubtensorModule::swap_owner_for_coldkey(&old_coldkey, &new_coldkey, &mut weight);
@@ -1297,8 +1269,8 @@ fn test_swap_total_hotkey_coldkey_stakes_this_interval_for_coldkey() {
12971269
TotalHotkeyColdkeyStakesThisInterval::<Test>::insert(hotkey1, old_coldkey, stake1);
12981270
TotalHotkeyColdkeyStakesThisInterval::<Test>::insert(hotkey2, old_coldkey, stake2);
12991271

1300-
// Populate Owned map
1301-
Owned::<Test>::insert(old_coldkey, vec![hotkey1, hotkey2]);
1272+
// Populate OwnedHotkeys map
1273+
OwnedHotkeys::<Test>::insert(old_coldkey, vec![hotkey1, hotkey2]);
13021274

13031275
// Perform the swap
13041276
SubtensorModule::swap_total_hotkey_coldkey_stakes_this_interval_for_coldkey(
@@ -1380,8 +1352,8 @@ fn test_do_swap_coldkey_with_subnet_ownership() {
13801352
SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, stake_amount + swap_cost);
13811353
SubnetOwner::<Test>::insert(netuid, old_coldkey);
13821354

1383-
// Populate Owned map
1384-
Owned::<Test>::insert(old_coldkey, vec![hotkey]);
1355+
// Populate OwnedHotkeys map
1356+
OwnedHotkeys::<Test>::insert(old_coldkey, vec![hotkey]);
13851357

13861358
// Perform the swap
13871359
assert_ok!(SubtensorModule::do_swap_coldkey(
@@ -1395,39 +1367,6 @@ fn test_do_swap_coldkey_with_subnet_ownership() {
13951367
});
13961368
}
13971369

1398-
#[test]
1399-
fn test_do_swap_coldkey_tx_rate_limit() {
1400-
new_test_ext(1).execute_with(|| {
1401-
let old_coldkey = U256::from(1);
1402-
let new_coldkey = U256::from(2);
1403-
let swap_cost = SubtensorModule::get_coldkey_swap_cost();
1404-
1405-
// Set non-zero tx rate limit
1406-
SubtensorModule::set_tx_rate_limit(1);
1407-
1408-
// Setup initial state
1409-
SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, swap_cost * 2);
1410-
SubtensorModule::add_balance_to_coldkey_account(&new_coldkey, swap_cost * 2);
1411-
1412-
// Perform first swap
1413-
assert_ok!(SubtensorModule::do_swap_coldkey(
1414-
<<Test as Config>::RuntimeOrigin>::signed(old_coldkey),
1415-
&old_coldkey,
1416-
&new_coldkey
1417-
));
1418-
1419-
// Attempt second swap immediately
1420-
assert_err!(
1421-
SubtensorModule::do_swap_coldkey(
1422-
<<Test as Config>::RuntimeOrigin>::signed(new_coldkey),
1423-
&new_coldkey,
1424-
&old_coldkey
1425-
),
1426-
Error::<Test>::ColdKeySwapTxRateLimitExceeded
1427-
);
1428-
});
1429-
}
1430-
14311370
#[test]
14321371
fn test_coldkey_has_associated_hotkeys() {
14331372
new_test_ext(1).execute_with(|| {

0 commit comments

Comments
 (0)