Skip to content

Commit 82b3f31

Browse files
committed
make immune limit error more explicit
1 parent 94d5ce1 commit 82b3f31

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

pallets/admin-utils/src/tests/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,7 +2713,7 @@ fn test_trim_to_max_allowed_uids_too_many_immune() {
27132713
MaxRegistrationsPerBlock::<Test>::insert(netuid, 256);
27142714
TargetRegistrationsPerInterval::<Test>::insert(netuid, 256);
27152715
ImmuneOwnerUidsLimit::<Test>::insert(netuid, 2);
2716-
MinAllowedUids::<Test>::set(netuid, 4);
2716+
MinAllowedUids::<Test>::set(netuid, 2);
27172717

27182718
// Add 5 neurons
27192719
let max_n = 5;
@@ -2751,7 +2751,7 @@ fn test_trim_to_max_allowed_uids_too_many_immune() {
27512751
netuid,
27522752
4
27532753
),
2754-
pallet_subtensor::Error::<Test>::InvalidValue
2754+
pallet_subtensor::Error::<Test>::TrimmingWouldExceedMaxImmunePercentage
27552755
);
27562756

27572757
// Try to trim to 3 UIDs - this should also fail because 4/3 > 80% immune (>= 80%)
@@ -2761,7 +2761,7 @@ fn test_trim_to_max_allowed_uids_too_many_immune() {
27612761
netuid,
27622762
3
27632763
),
2764-
pallet_subtensor::Error::<Test>::InvalidValue
2764+
pallet_subtensor::Error::<Test>::TrimmingWouldExceedMaxImmunePercentage
27652765
);
27662766

27672767
// Now test a scenario where trimming should succeed
@@ -2773,10 +2773,6 @@ fn test_trim_to_max_allowed_uids_too_many_immune() {
27732773
Uids::<Test>::remove(netuid, hotkey_to_remove);
27742774
BlockAtRegistration::<Test>::remove(netuid, uid_to_remove);
27752775

2776-
// Now we have 3 immune out of 4 total UIDs
2777-
// Try to trim to 3 UIDs - this should succeed because 3/3 = 100% immune, but that's exactly 80%
2778-
// Wait, 100% is > 80%, so this should fail. Let me test with a scenario where we have fewer immune UIDs
2779-
27802776
// Remove another immune UID to make it 2 immune out of 3 total
27812777
let uid_to_remove2 = 2;
27822778
let hotkey_to_remove2 = U256::from(uid_to_remove2 * 1000 + 1000);

pallets/subtensor/src/macros/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,7 @@ mod errors {
258258
EvmKeyAssociateRateLimitExceeded,
259259
/// The UID map for the subnet could not be cleared
260260
UidMapCouldNotBeCleared,
261+
/// Trimming would exceed the max immune neurons percentage
262+
TrimmingWouldExceedMaxImmunePercentage,
261263
}
262264
}

pallets/subtensor/src/subnets/uids.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<T: Config> Pallet<T> {
162162
let immune_percentage = Percent::from_rational(immune_count, max_n);
163163
ensure!(
164164
immune_percentage < T::MaxImmuneUidsPercentage::get(),
165-
Error::<T>::InvalidValue
165+
Error::<T>::TrimmingWouldExceedMaxImmunePercentage
166166
);
167167

168168
// Get all emissions with their UIDs and sort by emission (descending)

0 commit comments

Comments
 (0)