Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
0178b88
impl get_network_to_prune
JohnReedV May 26, 2025
562823c
use NetworkImmunityPeriod
JohnReedV May 27, 2025
b2ef90e
update get_network_to_prune.
JohnReedV May 27, 2025
d569309
add `NetworkActivationDeadline `
JohnReedV May 27, 2025
8016183
WIP
JohnReedV Jun 2, 2025
000c3d0
remove NetworkActivationDeadline
JohnReedV Jun 2, 2025
dfe72d5
update InitialNetworkImmunityPeriod
JohnReedV Jun 2, 2025
2676c63
add dissolve_network tests
JohnReedV Jun 5, 2025
a4c78f3
fmt
JohnReedV Jun 5, 2025
ac29e34
unused param
JohnReedV Jun 9, 2025
17f0982
clean up destroy_alpha_in_out_stakes
JohnReedV Jun 9, 2025
4b03bc9
update destroy_alpha_in_out_stakes
JohnReedV Jun 9, 2025
7c205a9
add more tests
JohnReedV Jun 9, 2025
f948305
add destroy_alpha_out_multiple_stakers_pro_rata
JohnReedV Jun 9, 2025
39f77cf
add test destroy_alpha_out_many_stakers_complex_distribution
JohnReedV Jun 9, 2025
ee61b24
remove comment
JohnReedV Jun 9, 2025
512578b
add pruning tests
JohnReedV Jun 9, 2025
b45c9eb
fmt
JohnReedV Jun 9, 2025
b12164a
use saturating math
JohnReedV Jun 9, 2025
bc9cab8
clippy
JohnReedV Jun 9, 2025
fc5c05c
add SubnetLimit
JohnReedV Jun 9, 2025
4d746b3
prune subnets in do_register_network
JohnReedV Jun 9, 2025
90216c2
update doc comment
JohnReedV Jun 9, 2025
cf6a750
add register_network tests
JohnReedV Jun 9, 2025
8593dae
update weights
JohnReedV Jun 9, 2025
9796751
Merge branch 'devnet-ready' into dtao-subnet-deregistration
JohnReedV Jun 10, 2025
e35cc67
move alpha to root instead of wallet balance
JohnReedV Jun 18, 2025
af4ddc7
update tests
JohnReedV Jun 18, 2025
9e18ea9
Merge branch 'devnet-ready' into dtao-subnet-deregistration
JohnReedV Jun 18, 2025
02e2d07
resolve conflict errors
JohnReedV Jun 18, 2025
f42d45f
fmt
JohnReedV Jun 18, 2025
77ceec2
add migration for immunity_period
JohnReedV Jun 18, 2025
1e03849
Merge branch 'devnet-ready' into dtao-subnet-deregistration
JohnReedV Jun 22, 2025
a2913d9
fix cargo lock
JohnReedV Jun 22, 2025
800471f
add root_dissolve_network
JohnReedV Jun 23, 2025
6d86784
fmt
JohnReedV Jun 23, 2025
43a9270
clippy
JohnReedV Jun 23, 2025
8e9b08c
rm DefaultStakingFee
JohnReedV Jun 23, 2025
1edbfd6
fix test
JohnReedV Jun 23, 2025
2c52732
fmt
JohnReedV Jun 23, 2025
f0da041
Merge branch 'devnet-ready' into dtao-subnet-deregistration
JohnReedV Aug 12, 2025
d404554
post-merge compilation fixes
JohnReedV Aug 12, 2025
5bda41e
auto-update benchmark weights
github-actions[bot] Aug 12, 2025
09ed4a8
Merge branch 'devnet-ready' into dtao-subnet-deregistration
JohnReedV Aug 14, 2025
b3a730f
auto-update benchmark weights
github-actions[bot] Aug 14, 2025
d44fd56
fix dynamic symbol
JohnReedV Aug 14, 2025
aa06e5a
update destroy_alpha_in_out_stakes
JohnReedV Aug 18, 2025
ba15855
convert alpha to tao
JohnReedV Aug 18, 2025
fe780c3
rename symbol
JohnReedV Aug 18, 2025
7ddf95e
unwind liquidity providers
JohnReedV Aug 18, 2025
2ae2eb6
add stake to balance
JohnReedV Aug 19, 2025
63bad12
update tests
JohnReedV Aug 19, 2025
3c53b30
use the actual hotkey
JohnReedV Aug 20, 2025
c4668d4
add test massive_dissolve
JohnReedV Aug 20, 2025
00a7f50
decrease subnet limit to 128
JohnReedV Aug 20, 2025
43bc788
dissolve_all_liquidity_providers
JohnReedV Aug 20, 2025
f22ef77
clippy
JohnReedV Aug 20, 2025
d4d8619
bump spec
JohnReedV Aug 20, 2025
3203e68
Merge branch 'devnet-ready' into dtao-subnet-deregistration
JohnReedV Aug 20, 2025
b75c6e1
DefaultSubnetLimit 148
JohnReedV Aug 21, 2025
adf9d25
use price instead of emission
JohnReedV Aug 21, 2025
203ebf2
update prune tests for price
JohnReedV Aug 21, 2025
a0c93a8
add test prune_selection_complex_state_exhaustive
JohnReedV Aug 21, 2025
e609855
Merge branch 'devnet-ready' into dtao-subnet-deregistration
JohnReedV Aug 21, 2025
370252f
Merge branch 'devnet-ready' into dtao-subnet-deregistration
JohnReedV Aug 21, 2025
8ab9fba
add a few missing maps
JohnReedV Aug 21, 2025
448a78d
clear additional maps
JohnReedV Aug 21, 2025
25ada7c
use NetworksAdded
JohnReedV Aug 24, 2025
b891321
CannotAffordLockCost
JohnReedV Aug 24, 2025
1ffe46a
add more maps
JohnReedV Aug 24, 2025
c6b3af6
cleanup
JohnReedV Aug 24, 2025
e3ac2e4
revert
JohnReedV Aug 24, 2025
42a5815
improve refund_alpha
JohnReedV Aug 24, 2025
70ec2ee
add more dissolve LP tests
JohnReedV Aug 24, 2025
8d838c4
use moving price
JohnReedV Aug 24, 2025
53d7dbc
auto-update benchmark weights
github-actions[bot] Aug 25, 2025
5c46edb
remove duplicates
JohnReedV Aug 25, 2025
576720e
remove duplicate check
JohnReedV Aug 25, 2025
f4f5add
improve efficiency
JohnReedV Aug 25, 2025
890f5b9
migrate_subnet_limit_to_default
JohnReedV Aug 25, 2025
4052094
auto-update benchmark weights
github-actions[bot] Aug 26, 2025
ded32d4
clippy
JohnReedV Aug 26, 2025
66a07b4
add get_subnet_to_prune rpc
JohnReedV Aug 26, 2025
db6614e
don't dissolve root
JohnReedV Aug 29, 2025
6b8055e
Merge branch 'devnet-ready' into dtao-subnet-deregistration
JohnReedV Aug 31, 2025
aa08d50
auto-update benchmark weights
github-actions[bot] Aug 31, 2025
a0830a7
don't remove LastAdjustmentBlock
JohnReedV Sep 5, 2025
cd565b2
try_initialize_v3
JohnReedV Sep 6, 2025
1b33b6f
toggle_user_liquidity
JohnReedV Sep 8, 2025
982c005
128 subnet limit
JohnReedV Sep 8, 2025
0700740
purge commitments
JohnReedV Sep 8, 2025
79da970
fix tests
JohnReedV Sep 8, 2025
f8a0c20
Merge branch 'devnet-ready' into dtao-subnet-deregistration
JohnReedV Sep 8, 2025
d4ac33f
cleanup merge
JohnReedV Sep 8, 2025
0c5c596
auto-update benchmark weights
github-actions[bot] Sep 8, 2025
a3acec8
improve logic
JohnReedV Sep 10, 2025
b654eaf
add migrate_network_lock_reduction_interval
JohnReedV Sep 14, 2025
8fd27c4
Merge branch 'devnet-ready' into dtao-subnet-deregistration
JohnReedV Sep 15, 2025
d9fb4d2
fix merge
JohnReedV Sep 15, 2025
ce11f6b
migrate_restore_subnet_locked
JohnReedV Sep 15, 2025
ef3c344
Merge branch 'devnet-ready' into dtao-subnet-deregistration
JohnReedV Sep 15, 2025
13b23fd
clear new subsubnet maps
JohnReedV Sep 15, 2025
60834c8
add NetworkRegistrationStartBlock
JohnReedV Sep 16, 2025
66acda6
Merge branch 'devnet-ready' into dtao-subnet-deregistration
JohnReedV Sep 16, 2025
1005c97
clippy
JohnReedV Sep 16, 2025
eb11106
remove unused
JohnReedV Sep 16, 2025
d7dcbd8
8 day NetworkLockReductionInterval
JohnReedV Sep 16, 2025
b6a5750
clippy
JohnReedV Sep 16, 2025
ebdfe22
Merge branch 'devnet-ready' into dtao-subnet-deregistration
JohnReedV Sep 17, 2025
ab23480
continue on error
JohnReedV Sep 17, 2025
4ce7b38
clippy
JohnReedV 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
17 changes: 17 additions & 0 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,23 @@ pub mod pallet {
Ok(())
}

/// The extrinsic sets the subnet limit for the network.
/// It is only callable by the root account.
/// The extrinsic will call the Subtensor pallet to set the subnet limit.
#[pallet::call_index(37)]
#[pallet::weight((
Weight::from_parts(14_000_000, 0)
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1)),
DispatchClass::Operational,
Pays::No
))]
pub fn sudo_set_subnet_limit(origin: OriginFor<T>, max_subnets: u16) -> DispatchResult {
ensure_root(origin)?;
pallet_subtensor::Pallet::<T>::set_max_subnets(max_subnets);
log::debug!("MaxSubnets ( max_subnets: {max_subnets:?} ) ");
Ok(())
}

/// The extrinsic sets the lock reduction interval for the network.
/// It is only callable by the root account.
/// The extrinsic will call the Subtensor pallet to set the lock reduction interval.
Expand Down
8 changes: 7 additions & 1 deletion pallets/admin-utils/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ parameter_types! {
pub const InitialMaxDifficulty: u64 = u64::MAX;
pub const InitialRAORecycledForRegistration: u64 = 0;
pub const InitialSenateRequiredStakePercentage: u64 = 2; // 2 percent of total stake
pub const InitialNetworkImmunityPeriod: u64 = 7200 * 7;
pub const InitialNetworkImmunityPeriod: u64 = 1_296_000;
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 Down Expand Up @@ -230,6 +230,7 @@ impl pallet_subtensor::Config for Test {
type LeaseDividendsDistributionInterval = LeaseDividendsDistributionInterval;
type GetCommitments = ();
type MaxImmuneUidsPercentage = MaxImmuneUidsPercentage;
type CommitmentsInterface = CommitmentsI;
}

parameter_types! {
Expand Down Expand Up @@ -356,6 +357,11 @@ impl PrivilegeCmp<OriginCaller> for OriginPrivilegeCmp {
}
}

pub struct CommitmentsI;
impl pallet_subtensor::CommitmentsInterface for CommitmentsI {
fn purge_netuid(_netuid: NetUid) {}
}

pub struct GrandpaInterfaceImpl;
impl crate::GrandpaInterface<Test> for GrandpaInterfaceImpl {
fn schedule_change(
Expand Down
12 changes: 12 additions & 0 deletions pallets/commitments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,18 @@ impl<T: Config> Pallet<T> {
.collect();
commitments
}

pub fn purge_netuid(netuid: NetUid) {
let _ = CommitmentOf::<T>::clear_prefix(netuid, u32::MAX, None);
let _ = LastCommitment::<T>::clear_prefix(netuid, u32::MAX, None);
let _ = LastBondsReset::<T>::clear_prefix(netuid, u32::MAX, None);
let _ = RevealedCommitments::<T>::clear_prefix(netuid, u32::MAX, None);
let _ = UsedSpaceOf::<T>::clear_prefix(netuid, u32::MAX, None);

TimelockedIndex::<T>::mutate(|index| {
index.retain(|(n, _)| *n != netuid);
});
}
}

pub trait GetCommitments<AccountId> {
Expand Down
121 changes: 119 additions & 2 deletions pallets/commitments/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use subtensor_runtime_common::NetUid;

#[cfg(test)]
use crate::{
BalanceOf, CommitmentInfo, CommitmentOf, Config, Data, Error, Event, MaxSpace, Pallet,
Registration, RevealedCommitments, TimelockedIndex, UsedSpaceOf,
BalanceOf, CommitmentInfo, CommitmentOf, Config, Data, Error, Event, LastBondsReset,
LastCommitment, MaxSpace, Pallet, Registration, RevealedCommitments, TimelockedIndex,
UsageTracker, UsedSpaceOf,
mock::{
Balances, DRAND_QUICKNET_SIG_2000_HEX, DRAND_QUICKNET_SIG_HEX, RuntimeEvent, RuntimeOrigin,
Test, TestMaxFields, insert_drand_pulse, new_test_ext, produce_ciphertext,
Expand Down Expand Up @@ -2185,3 +2186,119 @@ fn mixed_timelocked_and_raw_fields_works() {
);
});
}

#[test]
fn purge_netuid_clears_only_that_netuid() {
new_test_ext().execute_with(|| {
// Setup
System::<Test>::set_block_number(1);

let net_a = NetUid::from(42);
let net_b = NetUid::from(43);
let who_a1: u64 = 1001;
let who_a2: u64 = 1002;
let who_b: u64 = 2001;

// Minimal commitment payload
let empty_fields: BoundedVec<Data, <Test as Config>::MaxFields> = BoundedVec::default();
let info_empty: CommitmentInfo<<Test as Config>::MaxFields> = CommitmentInfo {
fields: empty_fields,
};
let bn = System::<Test>::block_number();

// Seed NET A with two accounts across all tracked storages
let reg_a1 = Registration {
deposit: Default::default(),
block: bn,
info: info_empty.clone(),
};
let reg_a2 = Registration {
deposit: Default::default(),
block: bn,
info: info_empty.clone(),
};
CommitmentOf::<Test>::insert(net_a, who_a1, reg_a1);
CommitmentOf::<Test>::insert(net_a, who_a2, reg_a2);
LastCommitment::<Test>::insert(net_a, who_a1, bn);
LastCommitment::<Test>::insert(net_a, who_a2, bn);
LastBondsReset::<Test>::insert(net_a, who_a1, bn);
RevealedCommitments::<Test>::insert(net_a, who_a1, vec![(b"a".to_vec(), 7u64)]);
UsedSpaceOf::<Test>::insert(
net_a,
who_a1,
UsageTracker {
last_epoch: 1,
used_space: 123,
},
);

// Seed NET B with one account that must remain intact
let reg_b = Registration {
deposit: Default::default(),
block: bn,
info: info_empty,
};
CommitmentOf::<Test>::insert(net_b, who_b, reg_b);
LastCommitment::<Test>::insert(net_b, who_b, bn);
LastBondsReset::<Test>::insert(net_b, who_b, bn);
RevealedCommitments::<Test>::insert(net_b, who_b, vec![(b"b".to_vec(), 8u64)]);
UsedSpaceOf::<Test>::insert(
net_b,
who_b,
UsageTracker {
last_epoch: 9,
used_space: 999,
},
);

// Timelocked index contains both nets
TimelockedIndex::<Test>::mutate(|idx| {
idx.insert((net_a, who_a1));
idx.insert((net_a, who_a2));
idx.insert((net_b, who_b));
});

// Sanity pre-checks
assert!(CommitmentOf::<Test>::get(net_a, who_a1).is_some());
assert!(CommitmentOf::<Test>::get(net_b, who_b).is_some());
assert!(TimelockedIndex::<Test>::get().contains(&(net_a, who_a1)));

// Act
Pallet::<Test>::purge_netuid(net_a);

// NET A: everything cleared
assert_eq!(CommitmentOf::<Test>::iter_prefix(net_a).count(), 0);
assert!(CommitmentOf::<Test>::get(net_a, who_a1).is_none());
assert!(CommitmentOf::<Test>::get(net_a, who_a2).is_none());

assert_eq!(LastCommitment::<Test>::iter_prefix(net_a).count(), 0);
assert!(LastCommitment::<Test>::get(net_a, who_a1).is_none());
assert!(LastCommitment::<Test>::get(net_a, who_a2).is_none());

assert_eq!(LastBondsReset::<Test>::iter_prefix(net_a).count(), 0);
assert!(LastBondsReset::<Test>::get(net_a, who_a1).is_none());

assert_eq!(RevealedCommitments::<Test>::iter_prefix(net_a).count(), 0);
assert!(RevealedCommitments::<Test>::get(net_a, who_a1).is_none());

assert_eq!(UsedSpaceOf::<Test>::iter_prefix(net_a).count(), 0);
assert!(UsedSpaceOf::<Test>::get(net_a, who_a1).is_none());

let idx_after = TimelockedIndex::<Test>::get();
assert!(!idx_after.contains(&(net_a, who_a1)));
assert!(!idx_after.contains(&(net_a, who_a2)));

// NET B: untouched
assert!(CommitmentOf::<Test>::get(net_b, who_b).is_some());
assert!(LastCommitment::<Test>::get(net_b, who_b).is_some());
assert!(LastBondsReset::<Test>::get(net_b, who_b).is_some());
assert!(RevealedCommitments::<Test>::get(net_b, who_b).is_some());
assert!(UsedSpaceOf::<Test>::get(net_b, who_b).is_some());
assert!(idx_after.contains(&(net_b, who_b)));

// Idempotency
Pallet::<Test>::purge_netuid(net_a);
assert_eq!(CommitmentOf::<Test>::iter_prefix(net_a).count(), 0);
assert!(!TimelockedIndex::<Test>::get().contains(&(net_a, who_a1)));
});
}
17 changes: 17 additions & 0 deletions pallets/subtensor/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ pub trait SubtensorCustomApi<BlockHash> {
metagraph_index: Vec<u16>,
at: Option<BlockHash>,
) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getSubnetToPrune")]
fn get_subnet_to_prune(&self, at: Option<BlockHash>) -> RpcResult<Option<NetUid>>;
}

pub struct SubtensorCustom<C, P> {
Expand Down Expand Up @@ -489,4 +491,19 @@ where
}
}
}

fn get_subnet_to_prune(
&self,
at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<Option<NetUid>> {
let api = self.client.runtime_api();
let at = at.unwrap_or_else(|| self.client.info().best_hash);

match api.get_subnet_to_prune(at) {
Ok(result) => Ok(result),
Err(e) => {
Err(Error::RuntimeError(format!("Unable to get subnet to prune: {e:?}")).into())
}
}
}
}
1 change: 1 addition & 0 deletions pallets/subtensor/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ sp_api::decl_runtime_apis! {
fn get_subnet_state(netuid: NetUid) -> Option<SubnetState<AccountId32>>;
fn get_selective_metagraph(netuid: NetUid, metagraph_indexes: Vec<u16>) -> Option<SelectiveMetagraph<AccountId32>>;
fn get_selective_submetagraph(netuid: NetUid, subid: SubId, metagraph_indexes: Vec<u16>) -> Option<SelectiveMetagraph<AccountId32>>;
fn get_subnet_to_prune() -> Option<NetUid>;
}

pub trait StakeInfoRuntimeApi {
Expand Down
Loading
Loading