Skip to content

Commit f7c001b

Browse files
authored
Merge pull request #1358 from opentensor/cleanup/remove-unused-after-rao
Cleanup/remove unused after rao
2 parents 1ff2edc + d456421 commit f7c001b

File tree

24 files changed

+101
-402
lines changed

24 files changed

+101
-402
lines changed

pallets/admin-utils/src/benchmarking.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,5 @@ mod benchmarks {
272272
_(RawOrigin::Root, 1u16/*netuid*/, true/*enabled*/)/*set_commit_reveal_weights_enabled*/;
273273
}
274274

275-
#[benchmark]
276-
fn sudo_set_network_max_stake() {
277-
pallet_subtensor::Pallet::<T>::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/);
278-
279-
#[extrinsic_call]
280-
_(RawOrigin::Root, 1u16/*netuid*/, 1_000_000_000_000_000u64/*max_stake*/)/*sudo_set_network_max_stake*/;
281-
}
282-
283275
//impl_benchmark_test_suite!(AdminUtils, crate::mock::new_test_ext(), crate::mock::Test);
284276
}

pallets/admin-utils/src/lib.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -910,12 +910,8 @@ pub mod pallet {
910910
DispatchClass::Operational,
911911
Pays::No
912912
))]
913-
pub fn sudo_set_subnet_limit(origin: OriginFor<T>, max_subnets: u16) -> DispatchResult {
913+
pub fn sudo_set_subnet_limit(origin: OriginFor<T>, _max_subnets: u16) -> DispatchResult {
914914
ensure_root(origin)?;
915-
pallet_subtensor::Pallet::<T>::set_max_subnets(max_subnets);
916-
917-
log::debug!("SubnetLimit( max_subnets: {:?} ) ", max_subnets);
918-
919915
Ok(())
920916
}
921917

@@ -1155,22 +1151,11 @@ pub mod pallet {
11551151
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
11561152
pub fn sudo_set_network_max_stake(
11571153
origin: OriginFor<T>,
1158-
netuid: u16,
1159-
max_stake: u64,
1154+
_netuid: u16,
1155+
_max_stake: u64,
11601156
) -> DispatchResult {
11611157
// Ensure the call is made by the root account
11621158
ensure_root(origin)?;
1163-
1164-
// Set the new maximum stake for the specified network
1165-
pallet_subtensor::Pallet::<T>::set_network_max_stake(netuid, max_stake);
1166-
1167-
// Log the change
1168-
log::trace!(
1169-
"NetworkMaxStakeSet( netuid: {:?}, max_stake: {:?} )",
1170-
netuid,
1171-
max_stake
1172-
);
1173-
11741159
Ok(())
11751160
}
11761161

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ parameter_types! {
123123
pub const InitialNetworkMinLockCost: u64 = 100_000_000_000;
124124
pub const InitialSubnetOwnerCut: u16 = 0; // 0%. 100% of rewards go to validators + miners.
125125
pub const InitialNetworkLockReductionInterval: u64 = 2; // 2 blocks.
126-
pub const InitialSubnetLimit: u16 = 10; // Max 10 subnets.
126+
// pub const InitialSubnetLimit: u16 = 10; // (DEPRECATED)
127127
pub const InitialNetworkRateLimit: u64 = 0;
128128
pub const InitialKeySwapCost: u64 = 1_000_000_000;
129129
pub const InitialAlphaHigh: u16 = 58982; // Represents 0.9 as per the production default
130130
pub const InitialAlphaLow: u16 = 45875; // Represents 0.7 as per the production default
131131
pub const InitialLiquidAlphaOn: bool = false; // Default value for LiquidAlphaOn
132132
// pub const InitialHotkeyEmissionTempo: u64 = 1; // (DEPRECATED)
133-
pub const InitialNetworkMaxStake: u64 = u64::MAX; // Maximum possible value for u64, this make the make stake infinity
133+
// pub const InitialNetworkMaxStake: u64 = u64::MAX; // (DEPRECATED)
134134
pub const InitialColdkeySwapScheduleDuration: u64 = 5 * 24 * 60 * 60 / 12; // 5 days
135135
pub const InitialDissolveNetworkScheduleDuration: u64 = 5 * 24 * 60 * 60 / 12; // 5 days
136136
pub const InitialTaoWeight: u64 = u64::MAX/10; // 10% global weight.
@@ -188,14 +188,11 @@ impl pallet_subtensor::Config for Test {
188188
type InitialNetworkMinLockCost = InitialNetworkMinLockCost;
189189
type InitialSubnetOwnerCut = InitialSubnetOwnerCut;
190190
type InitialNetworkLockReductionInterval = InitialNetworkLockReductionInterval;
191-
type InitialSubnetLimit = InitialSubnetLimit;
192191
type InitialNetworkRateLimit = InitialNetworkRateLimit;
193192
type KeySwapCost = InitialKeySwapCost;
194193
type AlphaHigh = InitialAlphaHigh;
195194
type AlphaLow = InitialAlphaLow;
196195
type LiquidAlphaOn = InitialLiquidAlphaOn;
197-
// type InitialHotkeyEmissionTempo = InitialHotkeyEmissionTempo; // (DEPRECATED)
198-
type InitialNetworkMaxStake = InitialNetworkMaxStake;
199196
type Preimages = ();
200197
type InitialColdkeySwapScheduleDuration = InitialColdkeySwapScheduleDuration;
201198
type InitialDissolveNetworkScheduleDuration = InitialDissolveNetworkScheduleDuration;

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -850,30 +850,6 @@ fn test_sudo_set_rao_recycled() {
850850
});
851851
}
852852

853-
#[test]
854-
fn test_sudo_set_subnet_limit() {
855-
new_test_ext().execute_with(|| {
856-
let netuid: u16 = 1;
857-
let to_be_set: u16 = 10;
858-
add_network(netuid, 10);
859-
860-
let init_value: u16 = SubtensorModule::get_max_subnets();
861-
assert_eq!(
862-
AdminUtils::sudo_set_subnet_limit(
863-
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
864-
to_be_set
865-
),
866-
Err(DispatchError::BadOrigin)
867-
);
868-
assert_eq!(SubtensorModule::get_max_subnets(), init_value);
869-
assert_ok!(AdminUtils::sudo_set_subnet_limit(
870-
<<Test as Config>::RuntimeOrigin>::root(),
871-
to_be_set
872-
));
873-
assert_eq!(SubtensorModule::get_max_subnets(), to_be_set);
874-
});
875-
}
876-
877853
#[test]
878854
fn test_sudo_set_network_lock_reduction_interval() {
879855
new_test_ext().execute_with(|| {

pallets/subtensor/src/coinbase/root.rs

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,6 @@ impl<T: Config> Pallet<T> {
7070
false
7171
}
7272

73-
/// Sets the emission values for each netuid
74-
///
75-
pub fn set_emission_values(netuids: &[u16], emission: Vec<u64>) -> Result<(), &'static str> {
76-
log::debug!(
77-
"set_emission_values: netuids: {:?} emission:{:?}",
78-
netuids,
79-
emission
80-
);
81-
82-
// Be careful this function can fail.
83-
if Self::contains_invalid_root_uids(netuids) {
84-
log::error!("set_emission_values: contains_invalid_root_uids");
85-
return Err("Invalid netuids");
86-
}
87-
if netuids.len() != emission.len() {
88-
log::error!("set_emission_values: netuids.len() != emission.len()");
89-
return Err("netuids and emission must have the same length");
90-
}
91-
for (netuid_i, emission_i) in netuids.iter().zip(emission) {
92-
log::debug!("set netuid:{:?} emission:{:?}", netuid_i, emission_i);
93-
EmissionValues::<T>::insert(*netuid_i, emission_i);
94-
}
95-
Ok(())
96-
}
97-
9873
/// Retrieves weight matrix associated with the root network.
9974
/// Weights represent the preferences for each subnetwork.
10075
///
@@ -577,7 +552,6 @@ impl<T: Config> Pallet<T> {
577552
MaxAllowedUids::<T>::remove(netuid);
578553
ImmunityPeriod::<T>::remove(netuid);
579554
ActivityCutoff::<T>::remove(netuid);
580-
EmissionValues::<T>::remove(netuid);
581555
MaxWeightsLimit::<T>::remove(netuid);
582556
MinAllowedWeights::<T>::remove(netuid);
583557
RegistrationsThisInterval::<T>::remove(netuid);
@@ -647,55 +621,6 @@ impl<T: Config> Pallet<T> {
647621
lock_cost
648622
}
649623

650-
/// This function is used to determine which subnet to prune when the total number of networks has reached the limit.
651-
/// It iterates over all the networks and finds the oldest subnet with the minimum emission value that is not in the immunity period.
652-
///
653-
/// # Returns:
654-
/// * 'u16':
655-
/// - The uid of the network to be pruned.
656-
///
657-
pub fn get_subnet_to_prune() -> u16 {
658-
let mut netuids: Vec<u16> = vec![];
659-
let current_block = Self::get_current_block_as_u64();
660-
661-
// Even if we don't have a root subnet, this still works
662-
for netuid in NetworksAdded::<T>::iter_keys_from(NetworksAdded::<T>::hashed_key_for(0)) {
663-
if current_block.saturating_sub(Self::get_network_registered_block(netuid))
664-
< Self::get_network_immunity_period()
665-
{
666-
continue;
667-
}
668-
669-
// This iterator seems to return them in order anyways, so no need to sort by key
670-
netuids.push(netuid);
671-
}
672-
673-
// Now we sort by emission, and then by subnet creation time.
674-
netuids.sort_by(|a, b| {
675-
use sp_std::cmp::Ordering;
676-
677-
match Self::get_emission_value(*b).cmp(&Self::get_emission_value(*a)) {
678-
Ordering::Equal => {
679-
if Self::get_network_registered_block(*b)
680-
< Self::get_network_registered_block(*a)
681-
{
682-
Ordering::Less
683-
} else {
684-
Ordering::Equal
685-
}
686-
}
687-
v => v,
688-
}
689-
});
690-
691-
log::debug!("Netuids Order: {:?}", netuids);
692-
693-
match netuids.last() {
694-
Some(netuid) => *netuid,
695-
None => 0,
696-
}
697-
}
698-
699624
pub fn get_network_registered_block(netuid: u16) -> u64 {
700625
NetworkRegisteredAt::<T>::get(netuid)
701626
}

pallets/subtensor/src/lib.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,6 @@ pub mod pallet {
501501
T::InitialSubnetOwnerCut::get()
502502
}
503503
#[pallet::type_value]
504-
/// Default value for subnet limit.
505-
pub fn DefaultSubnetLimit<T: Config>() -> u16 {
506-
T::InitialSubnetLimit::get()
507-
}
508-
#[pallet::type_value]
509504
/// Default value for network rate limit.
510505
pub fn DefaultNetworkRateLimit<T: Config>() -> u64 {
511506
if cfg!(feature = "pow-faucet") {
@@ -514,11 +509,6 @@ pub mod pallet {
514509
T::InitialNetworkRateLimit::get()
515510
}
516511
#[pallet::type_value]
517-
/// Default value for emission values.
518-
pub fn DefaultEmissionValues<T: Config>() -> u64 {
519-
0
520-
}
521-
#[pallet::type_value]
522512
/// Default value for pending emission.
523513
pub fn DefaultPendingEmission<T: Config>() -> u64 {
524514
0
@@ -728,11 +718,6 @@ pub mod pallet {
728718
pub fn DefaultAlphaValues<T: Config>() -> (u16, u16) {
729719
(45875, 58982)
730720
}
731-
#[pallet::type_value]
732-
/// Default value for network max stake.
733-
pub fn DefaultNetworkMaxStake<T: Config>() -> u64 {
734-
T::InitialNetworkMaxStake::get()
735-
}
736721

737722
#[pallet::type_value]
738723
/// Default value for coldkey swap schedule duration
@@ -1055,9 +1040,6 @@ pub mod pallet {
10551040
pub type MaxRegistrationsPerBlock<T> =
10561041
StorageMap<_, Identity, u16, u16, ValueQuery, DefaultMaxRegistrationsPerBlock<T>>;
10571042
#[pallet::storage]
1058-
/// --- ITEM( maximum_number_of_networks )
1059-
pub type SubnetLimit<T> = StorageValue<_, u16, ValueQuery, DefaultSubnetLimit<T>>;
1060-
#[pallet::storage]
10611043
/// --- ITEM( total_number_of_existing_networks )
10621044
pub type TotalNetworks<T> = StorageValue<_, u16, ValueQuery>;
10631045
#[pallet::storage]
@@ -1152,10 +1134,6 @@ pub mod pallet {
11521134
pub type NetworkRegisteredAt<T: Config> =
11531135
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultNetworkRegisteredAt<T>>;
11541136
#[pallet::storage]
1155-
/// --- MAP ( netuid ) --> emission_values
1156-
pub type EmissionValues<T> =
1157-
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultEmissionValues<T>>;
1158-
#[pallet::storage]
11591137
/// --- MAP ( netuid ) --> pending_emission
11601138
pub type PendingEmission<T> =
11611139
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultPendingEmission<T>>;
@@ -1324,10 +1302,6 @@ pub mod pallet {
13241302
/// MAP ( netuid ) --> (alpha_low, alpha_high)
13251303
pub type AlphaValues<T> =
13261304
StorageMap<_, Identity, u16, (u16, u16), ValueQuery, DefaultAlphaValues<T>>;
1327-
/// MAP ( netuid ) --> max stake allowed on a subnet.
1328-
#[pallet::storage]
1329-
pub type NetworkMaxStake<T> =
1330-
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultNetworkMaxStake<T>>;
13311305

13321306
/// =======================================
13331307
/// ==== Subnetwork Consensus Storage ====

pallets/subtensor/src/macros/config.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ mod config {
180180
/// Initial lock reduction interval.
181181
#[pallet::constant]
182182
type InitialNetworkLockReductionInterval: Get<u64>;
183-
/// Initial max allowed subnets
184-
#[pallet::constant]
185-
type InitialSubnetLimit: Get<u16>;
186183
/// Initial network creation rate limit
187184
#[pallet::constant]
188185
type InitialNetworkRateLimit: Get<u64>;
@@ -198,9 +195,6 @@ mod config {
198195
/// A flag to indicate if Liquid Alpha is enabled.
199196
#[pallet::constant]
200197
type LiquidAlphaOn: Get<bool>;
201-
/// Initial network max stake.
202-
#[pallet::constant]
203-
type InitialNetworkMaxStake: Get<u64>;
204198
// /// Initial hotkey emission tempo.
205199
// #[pallet::constant]
206200
// type InitialHotkeyEmissionTempo: Get<u64>;

pallets/subtensor/src/macros/events.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ mod events {
6565
AxonServed(u16, T::AccountId),
6666
/// the prometheus server information is added to the network.
6767
PrometheusServed(u16, T::AccountId),
68-
/// emission ratios for all networks is set.
69-
EmissionValuesSet(),
7068
/// a hotkey has become a delegate.
7169
DelegateAdded(T::AccountId, T::AccountId, u16),
7270
/// the default take is set.
@@ -124,7 +122,7 @@ mod events {
124122
/// the network minimum locking cost is set.
125123
NetworkMinLockCostSet(u64),
126124
/// the maximum number of subnets is set
127-
SubnetLimitSet(u16),
125+
// SubnetLimitSet(u16),
128126
/// the lock cost reduction is set
129127
NetworkLockCostReductionIntervalSet(u64),
130128
/// the take for a delegate is decreased.
@@ -193,8 +191,8 @@ mod events {
193191
SetChildren(T::AccountId, u16, Vec<(u64, T::AccountId)>),
194192
// /// The hotkey emission tempo has been set
195193
// HotkeyEmissionTempoSet(u64),
196-
/// The network maximum stake has been set
197-
NetworkMaxStakeSet(u16, u64),
194+
// /// The network maximum stake has been set
195+
// NetworkMaxStakeSet(u16, u64),
198196
/// The identity of a coldkey has been set
199197
ChainIdentitySet(T::AccountId),
200198
/// The identity of a subnet has been set

pallets/subtensor/src/macros/hooks.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ mod hooks {
7979
// Set the min difficulty across all subnets to a new minimum
8080
.saturating_add(migrations::migrate_set_min_difficulty::migrate_set_min_difficulty::<T>())
8181
// Remove Stake map entries
82-
.saturating_add(migrations::migrate_remove_stake_map::migrate_remove_stake_map::<T>());
82+
.saturating_add(migrations::migrate_remove_stake_map::migrate_remove_stake_map::<T>())
83+
// Remove unused maps entries
84+
.saturating_add(migrations::migrate_remove_unused_maps_and_values::migrate_remove_unused_maps_and_values::<T>());
8385
weight
8486
}
8587

pallets/subtensor/src/migrations/migrate_delete_subnet_21.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ pub fn migrate_delete_subnet_21<T: Config>() -> Weight {
103103
MaxAllowedUids::<T>::remove(netuid);
104104
ImmunityPeriod::<T>::remove(netuid);
105105
ActivityCutoff::<T>::remove(netuid);
106-
EmissionValues::<T>::remove(netuid);
107106
MaxWeightsLimit::<T>::remove(netuid);
108107
MinAllowedWeights::<T>::remove(netuid);
109108
RegistrationsThisInterval::<T>::remove(netuid);

0 commit comments

Comments
 (0)