Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
c42de52
commit Cargo.lock
Aug 29, 2025
bf7478e
cargo clippy
Aug 29, 2025
7e11d96
cargo fmt
Aug 29, 2025
7ae3dc8
Disable Keys::remove check for trim_to_max_allowed_uids
ales-otf Sep 1, 2025
d00cfc1
Add benchmark for trim_to_max_uids
ales-otf Sep 1, 2025
3c0ffb1
Fix wrong way ensure for min burn value, fix outdated comments
gztensor Sep 2, 2025
11c281f
Merge branch 'trim_uids' of github.com:opentensor/subtensor into trim…
gztensor Sep 2, 2025
86cce6f
add test + small refacto
l0r1s Sep 3, 2025
9e98561
Merge branch 'devnet-ready' into trim_uids
l0r1s Sep 3, 2025
3c8ff8e
cargo fmt
l0r1s Sep 3, 2025
eb001e3
fix misleading comment
l0r1s Sep 3, 2025
c7230d7
Merge branch 'devnet-ready' into trim_uids
l0r1s Sep 3, 2025
b96c60c
fix merge issue
l0r1s Sep 3, 2025
0b5e5b1
trim by emission and compress to the left
l0r1s Sep 3, 2025
15a3925
add sudo set min allowed uids
l0r1s Sep 9, 2025
ecc7f13
commit Cargo.lock
l0r1s Sep 9, 2025
30f3f0d
cargo fmt
l0r1s Sep 9, 2025
aa4c566
commit Cargo.lock
l0r1s Sep 9, 2025
4c9a3e2
Merge branch 'devnet-ready' into trim_uids
l0r1s Sep 9, 2025
b7e434c
fix merge
l0r1s Sep 9, 2025
26798bd
fix merge 2
l0r1s Sep 9, 2025
c19b71f
cargo fmt
l0r1s Sep 9, 2025
5dc32fd
added max immune percentage
l0r1s Sep 9, 2025
5a55def
fix imports
l0r1s Sep 9, 2025
0a033b2
cargo clippy
l0r1s Sep 9, 2025
2463441
commit Cargo.lock
l0r1s Sep 9, 2025
9e27dd0
cargo fmt
l0r1s Sep 9, 2025
e6fd948
restore clear_neuron
l0r1s Sep 10, 2025
f0b7188
restore clear_neuron 2
l0r1s Sep 10, 2025
04568f2
Merge branch 'devnet-ready' into trim_uids
l0r1s Sep 10, 2025
15ccf67
cargo fmt
l0r1s Sep 10, 2025
bf3c278
Merge branch 'devnet-ready' into trim_uids
l0r1s Sep 10, 2025
a027ba7
fix rate limit + call_index
l0r1s Sep 10, 2025
b2b9636
refacto to handle subsubnet when trimming uids
l0r1s Sep 10, 2025
20ef94a
fixed tests
l0r1s Sep 10, 2025
45bf58d
trigger ci
l0r1s Sep 11, 2025
a602599
Merge branch 'devnet-ready' into trim_uids
l0r1s Sep 12, 2025
b54ca79
fix get_immune_owner_hotkeys
l0r1s Sep 12, 2025
084407c
Merge branch 'devnet-ready' into trim_uids
l0r1s Sep 15, 2025
2ce716b
MinAllowedUids to 64
l0r1s Sep 15, 2025
cca14ab
Merge branch 'devnet-ready' into trim_uids
l0r1s Sep 15, 2025
a051137
extract rate limit
l0r1s Sep 15, 2025
ac5d6b3
fix benchmarks
l0r1s Sep 15, 2025
746cc61
Merge branch 'devnet-ready' into trim_uids
l0r1s Sep 16, 2025
aa4a23e
fix benchmarks
l0r1s Sep 16, 2025
5da86f1
cargo fmt
l0r1s Sep 16, 2025
261ef5a
auto-update benchmark weights
github-actions[bot] Sep 16, 2025
97efc75
Merge branch 'devnet-ready' into trim_uids
l0r1s Sep 16, 2025
f516593
fix rate limit
l0r1s Sep 16, 2025
d794795
auto-update benchmark weights
github-actions[bot] Sep 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pallets/admin-utils/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use frame_benchmarking::v1::account;
use frame_benchmarking::v2::*;
use frame_support::BoundedVec;
use frame_system::RawOrigin;
use pallet_subtensor::SubnetworkN;
use subtensor_runtime_common::NetUid;

use super::*;

Expand Down Expand Up @@ -238,6 +240,19 @@ mod benchmarks {
_(RawOrigin::Root, 1u16.into()/*netuid*/, 3u16/*kappa*/)/*set_kappa*/;
}

#[benchmark]
fn sudo_set_min_allowed_uids() {
let netuid = NetUid::from(1);
pallet_subtensor::Pallet::<T>::set_admin_freeze_window(0);
pallet_subtensor::Pallet::<T>::init_new_network(netuid, 1u16 /*tempo*/);

// Artificially set that some neurons are already registered
SubnetworkN::<T>::set(netuid, 32);

#[extrinsic_call]
_(RawOrigin::Root, netuid, 16u16/*min_allowed_uids*/)/*sudo_set_min_allowed_uids*/;
}

#[benchmark]
fn sudo_set_max_allowed_uids() {
// disable admin freeze window
Expand Down Expand Up @@ -432,5 +447,17 @@ mod benchmarks {
_(RawOrigin::Root, 1u16.into()/*netuid*/, 5u16/*immune_neurons*/)/*sudo_set_owner_immune_neuron_limit()*/;
}

#[benchmark]
fn sudo_trim_to_max_allowed_uids() {
pallet_subtensor::Pallet::<T>::set_admin_freeze_window(0);
pallet_subtensor::Pallet::<T>::init_new_network(
1u16.into(), /*netuid*/
1u16, /*sudo_tempo*/
);

#[extrinsic_call]
_(RawOrigin::Root, 1u16.into()/*netuid*/, 256u16/*max_n*/)/*sudo_trim_to_max_allowed_uids()*/;
}

//impl_benchmark_test_suite!(AdminUtils, crate::mock::new_test_ext(), crate::mock::Test);
}
68 changes: 68 additions & 0 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ pub mod pallet {
NegativeSigmoidSteepness,
/// Value not in allowed bounds.
ValueNotInBounds,
/// The minimum allowed UIDs must be less than the current number of UIDs in the subnet.
MinAllowedUidsGreaterThanCurrentUids,
/// The minimum allowed UIDs must be less than the maximum allowed UIDs.
MinAllowedUidsGreaterThanMaxAllowedUids,
}
/// Enum for specifying the type of precompile operation.
#[derive(
Expand Down Expand Up @@ -1902,6 +1906,70 @@ pub mod pallet {
);
Ok(())
}

/// Trims the maximum number of UIDs for a subnet.
///
/// The trimming is done by sorting the UIDs by emission descending and then trimming
/// the lowest emitters while preserving temporally and owner immune UIDs. The UIDs are
/// then compressed to the left and storage is migrated to the new compressed UIDs.
#[pallet::call_index(78)]
#[pallet::weight(Weight::from_parts(32_880_000, 0)
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(6_u64))
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1_u64)))]
pub fn sudo_trim_to_max_allowed_uids(
origin: OriginFor<T>,
netuid: NetUid,
max_n: u16,
) -> DispatchResult {
let maybe_owner = pallet_subtensor::Pallet::<T>::ensure_sn_owner_or_root_with_limits(
origin.clone(),
netuid,
&[TransactionType::MaxUidsTrimming],
)?;

pallet_subtensor::Pallet::<T>::trim_to_max_allowed_uids(netuid, max_n)?;

pallet_subtensor::Pallet::<T>::record_owner_rl(
maybe_owner,
netuid,
&[TransactionType::MaxUidsTrimming],
);
Ok(())
}

/// The extrinsic sets the minimum allowed UIDs for a subnet.
/// It is only callable by the root account.
#[pallet::call_index(79)]
#[pallet::weight(Weight::from_parts(31_550_000, 0)
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(5_u64))
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1_u64)))]
pub fn sudo_set_min_allowed_uids(
origin: OriginFor<T>,
netuid: NetUid,
min_allowed_uids: u16,
) -> DispatchResult {
pallet_subtensor::Pallet::<T>::ensure_root_with_rate_limit(origin, netuid)?;

ensure!(
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),
Error::<T>::SubnetDoesNotExist
);
ensure!(
min_allowed_uids < pallet_subtensor::Pallet::<T>::get_max_allowed_uids(netuid),
Error::<T>::MinAllowedUidsGreaterThanMaxAllowedUids
);
ensure!(
min_allowed_uids < pallet_subtensor::Pallet::<T>::get_subnetwork_n(netuid),
Error::<T>::MinAllowedUidsGreaterThanCurrentUids
);

pallet_subtensor::Pallet::<T>::set_min_allowed_uids(netuid, min_allowed_uids);

log::debug!(
"MinAllowedUidsSet( netuid: {netuid:?} min_allowed_uids: {min_allowed_uids:?} ) "
);
Ok(())
}
}
}

Expand Down
10 changes: 6 additions & 4 deletions pallets/admin-utils/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use sp_consensus_grandpa::AuthorityList as GrandpaAuthorityList;
use sp_core::U256;
use sp_core::{ConstU64, H256};
use sp_runtime::{
BuildStorage, KeyTypeId, Perbill,
BuildStorage, KeyTypeId, Perbill, Percent,
testing::TestXt,
traits::{BlakeTwo256, ConstU32, IdentityLookup},
};
Expand Down Expand Up @@ -91,7 +91,8 @@ parameter_types! {
pub const InitialTempo: u16 = 0;
pub const SelfOwnership: u64 = 2;
pub const InitialImmunityPeriod: u16 = 2;
pub const InitialMaxAllowedUids: u16 = 2;
pub const InitialMinAllowedUids: u16 = 2;
pub const InitialMaxAllowedUids: u16 = 4;
pub const InitialBondsMovingAverage: u64 = 900_000;
pub const InitialBondsPenalty: u16 = u16::MAX;
pub const InitialBondsResetOn: bool = false;
Expand Down Expand Up @@ -129,7 +130,6 @@ parameter_types! {
pub const InitialRAORecycledForRegistration: u64 = 0;
pub const InitialSenateRequiredStakePercentage: u64 = 2; // 2 percent of total stake
pub const InitialNetworkImmunityPeriod: u64 = 7200 * 7;
pub const InitialNetworkMinAllowedUids: u16 = 128;
pub const InitialNetworkMinLockCost: u64 = 100_000_000_000;
pub const InitialSubnetOwnerCut: u16 = 0; // 0%. 100% of rewards go to validators + miners.
pub const InitialNetworkLockReductionInterval: u64 = 2; // 2 blocks.
Expand All @@ -151,6 +151,7 @@ parameter_types! {
pub const InitialKeySwapOnSubnetCost: u64 = 10_000_000;
pub const HotkeySwapOnSubnetInterval: u64 = 7 * 24 * 60 * 60 / 12; // 7 days
pub const LeaseDividendsDistributionInterval: u32 = 100; // 100 blocks
pub const MaxImmuneUidsPercentage: Percent = Percent::from_percent(80);
}

impl pallet_subtensor::Config for Test {
Expand All @@ -174,6 +175,7 @@ impl pallet_subtensor::Config for Test {
type InitialRho = InitialRho;
type InitialAlphaSigmoidSteepness = InitialAlphaSigmoidSteepness;
type InitialKappa = InitialKappa;
type InitialMinAllowedUids = InitialMinAllowedUids;
type InitialMaxAllowedUids = InitialMaxAllowedUids;
type InitialValidatorPruneLen = InitialValidatorPruneLen;
type InitialScalingLawPower = InitialScalingLawPower;
Expand Down Expand Up @@ -205,7 +207,6 @@ impl pallet_subtensor::Config for Test {
type InitialRAORecycledForRegistration = InitialRAORecycledForRegistration;
type InitialSenateRequiredStakePercentage = InitialSenateRequiredStakePercentage;
type InitialNetworkImmunityPeriod = InitialNetworkImmunityPeriod;
type InitialNetworkMinAllowedUids = InitialNetworkMinAllowedUids;
type InitialNetworkMinLockCost = InitialNetworkMinLockCost;
type InitialSubnetOwnerCut = InitialSubnetOwnerCut;
type InitialNetworkLockReductionInterval = InitialNetworkLockReductionInterval;
Expand All @@ -228,6 +229,7 @@ impl pallet_subtensor::Config for Test {
type ProxyInterface = ();
type LeaseDividendsDistributionInterval = LeaseDividendsDistributionInterval;
type GetCommitments = ();
type MaxImmuneUidsPercentage = MaxImmuneUidsPercentage;
}

parameter_types! {
Expand Down
Loading