Skip to content

Commit 07ef7cd

Browse files
fix alphas min value checks
1 parent 8d9cde5 commit 07ef7cd

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ fn test_sudo_get_set_alpha() {
12511251
));
12521252

12531253
// 2. Alpha high too low
1254-
let alpha_high_too_low = (u16::MAX as u32 * 4 / 5) as u16 - 1; // One less than the minimum acceptable value
1254+
let alpha_high_too_low = (u16::MAX as u32 / 40) as u16 - 1; // One less than the minimum acceptable value
12551255
assert_err!(
12561256
AdminUtils::sudo_set_alpha_values(
12571257
signer.clone(),
@@ -1288,7 +1288,7 @@ fn test_sudo_get_set_alpha() {
12881288
alpha_high
12891289
));
12901290

1291-
let alpha_low_too_high = (u16::MAX as u32 * 4 / 5) as u16 + 1; // One more than the maximum acceptable value
1291+
let alpha_low_too_high = (u16::MAX as u32 / 40) as u16 + 1; // One more than the maximum acceptable value
12921292
assert_err!(
12931293
AdminUtils::sudo_set_alpha_values(
12941294
signer.clone(),

pallets/subtensor/src/epoch/run_epoch.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,14 +1332,15 @@ impl<T: Config> Pallet<T> {
13321332
);
13331333

13341334
let max_u16: u32 = u16::MAX as u32; // 65535
1335-
let min_alpha_high: u16 = (max_u16.saturating_mul(4).safe_div(5)) as u16; // 52428
1335+
let min_alpha_low: u16 = (max_u16.safe_div(40)) as u16; // 1638
1336+
let min_alpha_high: u16 = min_alpha_low;
13361337

13371338
// --- 4. Ensure alpha high is greater than the minimum
13381339
ensure!(alpha_high >= min_alpha_high, Error::<T>::AlphaHighTooLow);
13391340

13401341
// -- 5. Ensure alpha low is within range
13411342
ensure!(
1342-
alpha_low > 0 && alpha_low < min_alpha_high,
1343+
alpha_low >= min_alpha_low && alpha_low < alpha_high,
13431344
Error::<T>::AlphaLowOutOfRange
13441345
);
13451346

pallets/subtensor/src/tests/epoch.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,15 +1312,15 @@ fn test_set_alpha_disabled() {
13121312
// Explicitly set to false
13131313
SubtensorModule::set_liquid_alpha_enabled(netuid, false);
13141314
assert_err!(
1315-
SubtensorModule::do_set_alpha_values(signer.clone(), netuid, 12_u16, u16::MAX),
1315+
SubtensorModule::do_set_alpha_values(signer.clone(), netuid, 1638_u16, u16::MAX),
13161316
Error::<Test>::LiquidAlphaDisabled
13171317
);
13181318

13191319
SubtensorModule::set_liquid_alpha_enabled(netuid, true);
13201320
assert_ok!(SubtensorModule::do_set_alpha_values(
13211321
signer.clone(),
13221322
netuid,
1323-
12_u16,
1323+
1638_u16,
13241324
u16::MAX
13251325
));
13261326
});
@@ -2227,7 +2227,7 @@ fn test_validator_permits() {
22272227
fn test_get_set_alpha() {
22282228
new_test_ext(1).execute_with(|| {
22292229
let netuid = 1;
2230-
let alpha_low: u16 = 12_u16;
2230+
let alpha_low: u16 = 1638_u16;
22312231
let alpha_high: u16 = u16::MAX - 10;
22322232

22332233
let hotkey: U256 = U256::from(1);
@@ -2315,7 +2315,7 @@ fn test_get_set_alpha() {
23152315
));
23162316

23172317
// 2. Alpha high too low
2318-
let alpha_high_too_low = (u16::MAX as u32 * 4 / 5) as u16 - 1; // One less than the minimum acceptable value
2318+
let alpha_high_too_low = (u16::MAX as u32 * 1 / 40) as u16 - 1; // One less than the minimum acceptable value
23192319
assert_err!(
23202320
SubtensorModule::do_set_alpha_values(
23212321
signer.clone(),
@@ -2352,7 +2352,7 @@ fn test_get_set_alpha() {
23522352
alpha_high
23532353
));
23542354

2355-
let alpha_low_too_high = (u16::MAX as u32 * 4 / 5) as u16 + 1; // One more than the maximum acceptable value
2355+
let alpha_low_too_high = alpha_high; // should be smaller than alpha_high
23562356
assert_err!(
23572357
SubtensorModule::do_set_alpha_values(
23582358
signer.clone(),

0 commit comments

Comments
 (0)