Skip to content

Commit 3d20ad6

Browse files
Merge branch 'devnet-ready' into add-missing-benchmarks
2 parents 0577743 + 3146dbb commit 3d20ad6

11 files changed

Lines changed: 125 additions & 77 deletions

File tree

evm-tests/src/subtensor.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -233,24 +233,6 @@ export async function setActivityCutoff(api: TypedApi<typeof devnet>, netuid: nu
233233
assert.equal(activityCutoff, await api.query.SubtensorModule.ActivityCutoff.getValue(netuid))
234234
}
235235

236-
export async function setMaxAllowedUids(api: TypedApi<typeof devnet>, netuid: number, maxAllowedUids: number) {
237-
const value = await api.query.SubtensorModule.MaxAllowedUids.getValue(netuid)
238-
if (value === maxAllowedUids) {
239-
return;
240-
}
241-
242-
const alice = getAliceSigner()
243-
244-
const internalCall = api.tx.AdminUtils.sudo_set_max_allowed_uids({
245-
netuid: netuid,
246-
max_allowed_uids: maxAllowedUids
247-
})
248-
const tx = api.tx.Sudo.sudo({ call: internalCall.decodedCall })
249-
250-
await waitForTransactionWithRetry(api, tx, alice)
251-
assert.equal(maxAllowedUids, await api.query.SubtensorModule.MaxAllowedUids.getValue(netuid))
252-
}
253-
254236
export async function setMinDelegateTake(api: TypedApi<typeof devnet>, minDelegateTake: number) {
255237
const value = await api.query.SubtensorModule.MinDelegateTake.getValue()
256238
if (value === minDelegateTake) {

evm-tests/test/staking.precompile.reward.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { convertPublicKeyToSs58 } from "../src/address-utils"
66
import { tao } from "../src/balance-math"
77
import {
88
forceSetBalanceToSs58Address, addNewSubnetwork, burnedRegister,
9-
setTxRateLimit, setTempo, setWeightsSetRateLimit, setSubnetOwnerCut, setMaxAllowedUids,
9+
setTxRateLimit, setTempo, setWeightsSetRateLimit, setSubnetOwnerCut,
1010
setMinDelegateTake, setActivityCutoff, addStake, setWeight, rootRegister,
1111
startCall,
1212
disableAdminFreezeWindowAndOwnerHyperparamRateLimit
@@ -52,7 +52,6 @@ describe("Test neuron precompile reward", () => {
5252
await burnedRegister(api, netuid, convertPublicKeyToSs58(nominator.publicKey), coldkey)
5353
await setSubnetOwnerCut(api, 0)
5454
await setActivityCutoff(api, netuid, 65535)
55-
await setMaxAllowedUids(api, netuid, 65535)
5655
await setMinDelegateTake(api, 0)
5756
})
5857

pallets/admin-utils/src/benchmarking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ mod benchmarks {
263263
);
264264

265265
#[extrinsic_call]
266-
_(RawOrigin::Root, 1u16.into()/*netuid*/, 4097u16/*max_allowed_uids*/)/*sudo_set_max_allowed_uids*/;
266+
_(RawOrigin::Root, 1u16.into()/*netuid*/, 2048u16/*max_allowed_uids*/)/*sudo_set_max_allowed_uids*/;
267267
}
268268

269269
#[benchmark]

pallets/admin-utils/src/lib.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ pub mod pallet {
2525
use frame_support::{dispatch::DispatchResult, pallet_prelude::StorageMap};
2626
use frame_system::pallet_prelude::*;
2727
use pallet_evm_chain_id::{self, ChainId};
28-
use pallet_subtensor::utils::rate_limiting::{Hyperparameter, TransactionType};
28+
use pallet_subtensor::{
29+
DefaultMaxAllowedUids,
30+
utils::rate_limiting::{Hyperparameter, TransactionType},
31+
};
2932
use sp_runtime::BoundedVec;
3033
use substrate_fixed::types::I96F32;
3134
use subtensor_runtime_common::{MechId, NetUid, TaoCurrency};
@@ -110,6 +113,10 @@ pub mod pallet {
110113
MinAllowedUidsGreaterThanCurrentUids,
111114
/// The minimum allowed UIDs must be less than the maximum allowed UIDs.
112115
MinAllowedUidsGreaterThanMaxAllowedUids,
116+
/// The maximum allowed UIDs must be greater than the minimum allowed UIDs.
117+
MaxAllowedUidsLessThanMinAllowedUids,
118+
/// The maximum allowed UIDs must be less than the default maximum allowed UIDs.
119+
MaxAllowedUidsGreaterThanDefaultMaxAllowedUids,
113120
}
114121
/// Enum for specifying the type of precompile operation.
115122
#[derive(
@@ -522,27 +529,44 @@ pub mod pallet {
522529
}
523530

524531
/// The extrinsic sets the maximum allowed UIDs for a subnet.
525-
/// It is only callable by the root account.
532+
/// It is only callable by the root account and subnet owner.
526533
/// The extrinsic will call the Subtensor pallet to set the maximum allowed UIDs for a subnet.
527534
#[pallet::call_index(15)]
528-
#[pallet::weight(Weight::from_parts(18_800_000, 0)
529-
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(2_u64))
535+
#[pallet::weight(Weight::from_parts(32_140_000, 0)
536+
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(5_u64))
530537
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1_u64)))]
531538
pub fn sudo_set_max_allowed_uids(
532539
origin: OriginFor<T>,
533540
netuid: NetUid,
534541
max_allowed_uids: u16,
535542
) -> DispatchResult {
536-
ensure_root(origin)?;
543+
let maybe_owner = pallet_subtensor::Pallet::<T>::ensure_sn_owner_or_root_with_limits(
544+
origin,
545+
netuid,
546+
&[Hyperparameter::MaxAllowedUids.into()],
547+
)?;
537548
ensure!(
538549
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),
539550
Error::<T>::SubnetDoesNotExist
540551
);
541552
ensure!(
542-
pallet_subtensor::Pallet::<T>::get_subnetwork_n(netuid) < max_allowed_uids,
553+
max_allowed_uids >= pallet_subtensor::Pallet::<T>::get_min_allowed_uids(netuid),
554+
Error::<T>::MaxAllowedUidsLessThanMinAllowedUids
555+
);
556+
ensure!(
557+
pallet_subtensor::Pallet::<T>::get_subnetwork_n(netuid) <= max_allowed_uids,
543558
Error::<T>::MaxAllowedUIdsLessThanCurrentUIds
544559
);
560+
ensure!(
561+
max_allowed_uids <= DefaultMaxAllowedUids::<T>::get(),
562+
Error::<T>::MaxAllowedUidsGreaterThanDefaultMaxAllowedUids
563+
);
545564
pallet_subtensor::Pallet::<T>::set_max_allowed_uids(netuid, max_allowed_uids);
565+
pallet_subtensor::Pallet::<T>::record_owner_rl(
566+
maybe_owner,
567+
netuid,
568+
&[Hyperparameter::MaxAllowedUids.into()],
569+
);
546570
log::debug!(
547571
"MaxAllowedUidsSet( netuid: {netuid:?} max_allowed_uids: {max_allowed_uids:?} ) "
548572
);
@@ -818,7 +842,7 @@ pub mod pallet {
818842
/// It is only callable by the root account or subnet owner.
819843
/// The extrinsic will call the Subtensor pallet to set the difficulty.
820844
#[pallet::call_index(24)]
821-
#[pallet::weight(Weight::from_parts(26_230_000, 0)
845+
#[pallet::weight(Weight::from_parts(38_500_000, 0)
822846
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(3_u64))
823847
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1_u64)))]
824848
pub fn sudo_set_difficulty(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ parameter_types! {
9292
pub const SelfOwnership: u64 = 2;
9393
pub const InitialImmunityPeriod: u16 = 2;
9494
pub const InitialMinAllowedUids: u16 = 2;
95-
pub const InitialMaxAllowedUids: u16 = 4;
95+
pub const InitialMaxAllowedUids: u16 = 16;
9696
pub const InitialBondsMovingAverage: u64 = 900_000;
9797
pub const InitialBondsPenalty: u16 = u16::MAX;
9898
pub const InitialBondsResetOn: bool = false;

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

Lines changed: 72 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -513,69 +513,107 @@ fn test_sudo_set_min_allowed_weights() {
513513
fn test_sudo_set_max_allowed_uids() {
514514
new_test_ext().execute_with(|| {
515515
let netuid = NetUid::from(1);
516-
let to_be_set: u16 = 10;
516+
let to_be_set: u16 = 12;
517517
add_network(netuid, 10);
518-
let init_value: u16 = SubtensorModule::get_max_allowed_uids(netuid);
519-
assert_eq!(
518+
MaxRegistrationsPerBlock::<Test>::insert(netuid, 256);
519+
TargetRegistrationsPerInterval::<Test>::insert(netuid, 256);
520+
521+
// Register some neurons
522+
for i in 0..=8 {
523+
register_ok_neuron(netuid, U256::from(i * 1000), U256::from(i * 1000 + i), 0);
524+
}
525+
526+
// Bad origin that is not root or subnet owner
527+
assert_noop!(
520528
AdminUtils::sudo_set_max_allowed_uids(
521-
<<Test as Config>::RuntimeOrigin>::signed(U256::from(0)),
529+
<<Test as Config>::RuntimeOrigin>::signed(U256::from(42)),
522530
netuid,
523531
to_be_set
524532
),
525-
Err(DispatchError::BadOrigin)
533+
DispatchError::BadOrigin
526534
);
527-
assert_eq!(
535+
536+
// Random netuid that doesn't exist
537+
assert_noop!(
528538
AdminUtils::sudo_set_max_allowed_uids(
529539
<<Test as Config>::RuntimeOrigin>::root(),
530-
netuid.next(),
540+
NetUid::from(42),
531541
to_be_set
532542
),
533-
Err(Error::<Test>::SubnetDoesNotExist.into())
543+
Error::<Test>::SubnetDoesNotExist
534544
);
535-
assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), init_value);
536-
assert_ok!(AdminUtils::sudo_set_max_allowed_uids(
537-
<<Test as Config>::RuntimeOrigin>::root(),
538-
netuid,
539-
to_be_set
540-
));
541-
assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), to_be_set);
542-
});
543-
}
544545

545-
#[test]
546-
fn test_sudo_set_and_decrease_max_allowed_uids() {
547-
new_test_ext().execute_with(|| {
548-
let netuid = NetUid::from(1);
549-
let to_be_set: u16 = 10;
550-
add_network(netuid, 10);
551-
let init_value: u16 = SubtensorModule::get_max_allowed_uids(netuid);
552-
assert_eq!(
546+
// Trying to set max allowed uids less than min allowed uids
547+
assert_noop!(
553548
AdminUtils::sudo_set_max_allowed_uids(
554-
<<Test as Config>::RuntimeOrigin>::signed(U256::from(0)),
549+
<<Test as Config>::RuntimeOrigin>::root(),
555550
netuid,
556-
to_be_set
551+
SubtensorModule::get_min_allowed_uids(netuid) - 1
557552
),
558-
Err(DispatchError::BadOrigin)
553+
Error::<Test>::MaxAllowedUidsLessThanMinAllowedUids
559554
);
560-
assert_eq!(
555+
556+
// Trying to set max allowed uids less than current uids
557+
assert_noop!(
561558
AdminUtils::sudo_set_max_allowed_uids(
562559
<<Test as Config>::RuntimeOrigin>::root(),
563-
netuid.next(),
564-
to_be_set
560+
netuid,
561+
SubtensorModule::get_subnetwork_n(netuid) - 1
565562
),
566-
Err(Error::<Test>::SubnetDoesNotExist.into())
563+
Error::<Test>::MaxAllowedUIdsLessThanCurrentUIds
567564
);
568-
assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), init_value);
565+
566+
// Trying to set max allowed uids greater than default max allowed uids
567+
assert_noop!(
568+
AdminUtils::sudo_set_max_allowed_uids(
569+
<<Test as Config>::RuntimeOrigin>::root(),
570+
netuid,
571+
DefaultMaxAllowedUids::<Test>::get() + 1
572+
),
573+
Error::<Test>::MaxAllowedUidsGreaterThanDefaultMaxAllowedUids
574+
);
575+
576+
// Normal case
569577
assert_ok!(AdminUtils::sudo_set_max_allowed_uids(
570578
<<Test as Config>::RuntimeOrigin>::root(),
571579
netuid,
572580
to_be_set
573581
));
582+
assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), to_be_set);
583+
584+
// Exact current case
585+
assert_ok!(AdminUtils::sudo_set_max_allowed_uids(
586+
<<Test as Config>::RuntimeOrigin>::root(),
587+
netuid,
588+
SubtensorModule::get_subnetwork_n(netuid)
589+
));
590+
assert_eq!(
591+
SubtensorModule::get_max_allowed_uids(netuid),
592+
SubtensorModule::get_subnetwork_n(netuid)
593+
);
594+
595+
// Lower bound case
596+
SubtensorModule::set_min_allowed_uids(netuid, SubtensorModule::get_subnetwork_n(netuid));
574597
assert_ok!(AdminUtils::sudo_set_max_allowed_uids(
575598
<<Test as Config>::RuntimeOrigin>::root(),
576599
netuid,
577-
to_be_set - 1
600+
SubtensorModule::get_min_allowed_uids(netuid)
578601
));
602+
assert_eq!(
603+
SubtensorModule::get_max_allowed_uids(netuid),
604+
SubtensorModule::get_min_allowed_uids(netuid)
605+
);
606+
607+
// Upper bound case
608+
assert_ok!(AdminUtils::sudo_set_max_allowed_uids(
609+
<<Test as Config>::RuntimeOrigin>::root(),
610+
netuid,
611+
DefaultMaxAllowedUids::<Test>::get(),
612+
));
613+
assert_eq!(
614+
SubtensorModule::get_max_allowed_uids(netuid),
615+
DefaultMaxAllowedUids::<Test>::get()
616+
);
579617
});
580618
}
581619

pallets/commitments/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ pub mod pallet {
337337
.saturating_add(T::DbWeight::get().reads(0_u64))
338338
.saturating_add(T::DbWeight::get().writes(1_u64)),
339339
DispatchClass::Operational,
340-
Pays::No
340+
Pays::Yes
341341
))]
342342
pub fn set_max_space(origin: OriginFor<T>, new_limit: u32) -> DispatchResult {
343343
ensure_root(origin)?;

0 commit comments

Comments
 (0)