Skip to content

Commit 3ae481e

Browse files
authored
Merge branch 'devnet-ready' into auto_stake
2 parents 76ae063 + 14024fd commit 3ae481e

File tree

15 files changed

+94
-463
lines changed

15 files changed

+94
-463
lines changed

common/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub enum ProxyType {
154154
Registration,
155155
Transfer,
156156
SmallTransfer,
157-
RootWeights,
157+
RootWeights, // deprecated
158158
ChildKeys,
159159
SudoUncheckedSetCode,
160160
SwapHotkey,

pallets/admin-utils/src/lib.rs

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -957,21 +957,6 @@ pub mod pallet {
957957
Ok(())
958958
}
959959

960-
/// The extrinsic sets the subnet limit for the network.
961-
/// It is only callable by the root account.
962-
/// The extrinsic will call the Subtensor pallet to set the subnet limit.
963-
#[pallet::call_index(37)]
964-
#[pallet::weight((
965-
Weight::from_parts(14_000_000, 0)
966-
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1)),
967-
DispatchClass::Operational,
968-
Pays::No
969-
))]
970-
pub fn sudo_set_subnet_limit(origin: OriginFor<T>, _max_subnets: u16) -> DispatchResult {
971-
ensure_root(origin)?;
972-
Ok(())
973-
}
974-
975960
/// The extrinsic sets the lock reduction interval for the network.
976961
/// It is only callable by the root account.
977962
/// The extrinsic will call the Subtensor pallet to set the lock reduction interval.
@@ -1076,26 +1061,6 @@ pub mod pallet {
10761061
Ok(())
10771062
}
10781063

1079-
// The extrinsic sets the target stake per interval.
1080-
// It is only callable by the root account.
1081-
// The extrinsic will call the Subtensor pallet to set target stake per interval.
1082-
// #[pallet::call_index(47)]
1083-
// #[pallet::weight((0, DispatchClass::Operational, Pays::No))]
1084-
// pub fn sudo_set_target_stakes_per_interval(
1085-
// origin: OriginFor<T>,
1086-
// target_stakes_per_interval: u64,
1087-
// ) -> DispatchResult {
1088-
// ensure_root(origin)?;
1089-
// pallet_subtensor::Pallet::<T>::set_target_stakes_per_interval(
1090-
// target_stakes_per_interval,
1091-
// );
1092-
// log::debug!(
1093-
// "TxTargetStakesPerIntervalSet( set_target_stakes_per_interval: {:?} ) ",
1094-
// target_stakes_per_interval
1095-
// ); (DEPRECATED)
1096-
// Ok(())
1097-
// } (DEPRECATED)
1098-
10991064
/// The extrinsic enabled/disables commit/reaveal for a given subnet.
11001065
/// It is only callable by the root account or subnet owner.
11011066
/// The extrinsic will call the Subtensor pallet to set the value.
@@ -1157,62 +1122,6 @@ pub mod pallet {
11571122
)
11581123
}
11591124

1160-
// DEPRECATED
1161-
// #[pallet::call_index(52)]
1162-
// #[pallet::weight((0, DispatchClass::Operational, Pays::No))]
1163-
// pub fn sudo_set_hotkey_emission_tempo(
1164-
// origin: OriginFor<T>,
1165-
// emission_tempo: u64,
1166-
// ) -> DispatchResult {
1167-
// ensure_root(origin)?;
1168-
// pallet_subtensor::Pallet::<T>::set_hotkey_emission_tempo(emission_tempo);
1169-
// log::debug!(
1170-
// "HotkeyEmissionTempoSet( emission_tempo: {:?} )",
1171-
// emission_tempo
1172-
// );
1173-
// Ok(())
1174-
// }
1175-
1176-
/// Sets the maximum stake allowed for a specific network.
1177-
///
1178-
/// This function allows the root account to set the maximum stake for a given network.
1179-
/// It updates the network's maximum stake value and logs the change.
1180-
///
1181-
/// # Arguments
1182-
///
1183-
/// * `origin` - The origin of the call, which must be the root account.
1184-
/// * `netuid` - The unique identifier of the network.
1185-
/// * `max_stake` - The new maximum stake value to set.
1186-
///
1187-
/// # Returns
1188-
///
1189-
/// Returns `Ok(())` if the operation is successful, or an error if it fails.
1190-
///
1191-
/// # Example
1192-
///
1193-
///
1194-
/// # Notes
1195-
///
1196-
/// - This function can only be called by the root account.
1197-
/// - The `netuid` should correspond to an existing network.
1198-
///
1199-
/// # TODO
1200-
///
1201-
// - Consider adding a check to ensure the `netuid` corresponds to an existing network.
1202-
// - Implement a mechanism to gradually adjust the max stake to prevent sudden changes.
1203-
// #[pallet::weight(<T as Config>::WeightInfo::sudo_set_network_max_stake())]
1204-
#[pallet::call_index(53)]
1205-
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
1206-
pub fn sudo_set_network_max_stake(
1207-
origin: OriginFor<T>,
1208-
_netuid: NetUid,
1209-
_max_stake: u64,
1210-
) -> DispatchResult {
1211-
// Ensure the call is made by the root account
1212-
ensure_root(origin)?;
1213-
Ok(())
1214-
}
1215-
12161125
/// Sets the duration of the coldkey swap schedule.
12171126
///
12181127
/// This extrinsic allows the root account to set the duration for the coldkey swap schedule.

pallets/commitments/src/lib.rs

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ pub use types::*;
1515
pub use weights::WeightInfo;
1616

1717
use ark_serialize::CanonicalDeserialize;
18-
use frame_support::{BoundedVec, traits::Currency};
18+
use frame_support::{
19+
BoundedVec,
20+
traits::{Currency, Get},
21+
};
1922
use scale_info::prelude::collections::BTreeSet;
2023
use sp_runtime::SaturatedConversion;
21-
use sp_runtime::{Saturating, traits::Zero};
24+
use sp_runtime::{Saturating, Weight, traits::Zero};
2225
use sp_std::{boxed::Box, vec::Vec};
2326
use subtensor_runtime_common::NetUid;
2427
use tle::{
@@ -325,21 +328,6 @@ pub mod pallet {
325328
Ok(())
326329
}
327330

328-
/// *DEPRECATED* Sudo-set the commitment rate limit
329-
#[pallet::call_index(1)]
330-
#[pallet::weight((
331-
Weight::from_parts(3_596_000, 0)
332-
.saturating_add(T::DbWeight::get().reads(0_u64))
333-
.saturating_add(T::DbWeight::get().writes(1_u64)),
334-
DispatchClass::Operational,
335-
Pays::No
336-
))]
337-
pub fn set_rate_limit(origin: OriginFor<T>, _rate_limit_blocks: u32) -> DispatchResult {
338-
ensure_root(origin)?;
339-
// RateLimit::<T>::set(rate_limit_blocks.into());
340-
Ok(())
341-
}
342-
343331
/// Sudo-set MaxSpace
344332
#[pallet::call_index(2)]
345333
#[pallet::weight((
@@ -359,10 +347,13 @@ pub mod pallet {
359347
#[pallet::hooks]
360348
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
361349
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
362-
if let Err(e) = Self::reveal_timelocked_commitments() {
363-
log::debug!("Failed to unveil matured commitments on block {n:?}: {e:?}");
350+
match Self::reveal_timelocked_commitments() {
351+
Ok(w) => w,
352+
Err(e) => {
353+
log::debug!("Failed to unveil matured commitments on block {n:?}: {e:?}");
354+
Weight::from_parts(0, 0)
355+
}
364356
}
365-
Weight::from_parts(0, 0)
366357
}
367358
}
368359
}
@@ -399,13 +390,22 @@ pub enum CallType {
399390
use frame_support::{dispatch::DispatchResult, pallet_prelude::TypeInfo};
400391

401392
impl<T: Config> Pallet<T> {
402-
pub fn reveal_timelocked_commitments() -> DispatchResult {
393+
pub fn reveal_timelocked_commitments() -> Result<Weight, sp_runtime::DispatchError> {
394+
let mut total_weight = Weight::from_parts(0, 0);
395+
403396
let index = TimelockedIndex::<T>::get();
397+
total_weight = total_weight.saturating_add(T::DbWeight::get().reads(1));
398+
404399
for (netuid, who) in index.clone() {
405-
let Some(mut registration) = <CommitmentOf<T>>::get(netuid, &who) else {
400+
let maybe_registration = <CommitmentOf<T>>::get(netuid, &who);
401+
total_weight = total_weight.saturating_add(T::DbWeight::get().reads(1));
402+
403+
let Some(mut registration) = maybe_registration else {
406404
TimelockedIndex::<T>::mutate(|idx| {
407405
idx.remove(&(netuid, who.clone()));
408406
});
407+
408+
total_weight = total_weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
409409
continue;
410410
};
411411

@@ -419,6 +419,7 @@ impl<T: Config> Pallet<T> {
419419
encrypted,
420420
reveal_round,
421421
} => {
422+
total_weight = total_weight.saturating_add(T::DbWeight::get().reads(1));
422423
let pulse = match pallet_drand::Pulses::<T>::get(reveal_round) {
423424
Some(p) => p,
424425
None => {
@@ -486,6 +487,7 @@ impl<T: Config> Pallet<T> {
486487
if !revealed_fields.is_empty() {
487488
let mut existing_reveals =
488489
RevealedCommitments::<T>::get(netuid, &who).unwrap_or_default();
490+
total_weight = total_weight.saturating_add(T::DbWeight::get().reads(1));
489491

490492
let current_block = <frame_system::Pallet<T>>::block_number();
491493
let block_u64 = current_block.saturated_into::<u64>();
@@ -507,6 +509,7 @@ impl<T: Config> Pallet<T> {
507509
}
508510

509511
RevealedCommitments::<T>::insert(netuid, &who, existing_reveals);
512+
total_weight = total_weight.saturating_add(T::DbWeight::get().writes(1));
510513
}
511514

512515
registration.info.fields = BoundedVec::try_from(remain_fields)
@@ -515,12 +518,19 @@ impl<T: Config> Pallet<T> {
515518
match registration.info.fields.is_empty() {
516519
true => {
517520
<CommitmentOf<T>>::remove(netuid, &who);
521+
total_weight = total_weight.saturating_add(T::DbWeight::get().writes(1));
522+
518523
TimelockedIndex::<T>::mutate(|idx| {
519524
idx.remove(&(netuid, who.clone()));
520525
});
526+
527+
total_weight =
528+
total_weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
521529
}
522530
false => {
523531
<CommitmentOf<T>>::insert(netuid, &who, &registration);
532+
total_weight = total_weight.saturating_add(T::DbWeight::get().writes(1));
533+
524534
let has_timelock = registration
525535
.info
526536
.fields
@@ -530,11 +540,14 @@ impl<T: Config> Pallet<T> {
530540
TimelockedIndex::<T>::mutate(|idx| {
531541
idx.remove(&(netuid, who.clone()));
532542
});
543+
544+
total_weight =
545+
total_weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
533546
}
534547
}
535548
}
536549
}
537550

538-
Ok(())
551+
Ok(total_weight)
539552
}
540553
}

pallets/subtensor/src/benchmarks.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -98,33 +98,6 @@ mod pallet_benchmarks {
9898
);
9999
}
100100

101-
#[benchmark]
102-
fn become_delegate() {
103-
let netuid = NetUid::from(1);
104-
let tempo: u16 = 1;
105-
106-
Subtensor::<T>::init_new_network(netuid, tempo);
107-
SubtokenEnabled::<T>::insert(netuid, true);
108-
Subtensor::<T>::set_burn(netuid, 1.into());
109-
Subtensor::<T>::set_max_allowed_uids(netuid, 4096);
110-
Subtensor::<T>::set_network_registration_allowed(netuid, true);
111-
112-
let seed: u32 = 1;
113-
let coldkey: T::AccountId = account("Test", 0, seed);
114-
let hotkey: T::AccountId = account("Alice", 0, seed);
115-
let amount_to_be_staked: u64 = 1_000_000_000;
116-
117-
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey, amount_to_be_staked);
118-
assert_ok!(Subtensor::<T>::do_burned_registration(
119-
RawOrigin::Signed(coldkey.clone()).into(),
120-
netuid,
121-
hotkey.clone()
122-
));
123-
124-
#[extrinsic_call]
125-
_(RawOrigin::Signed(coldkey.clone()), hotkey.clone());
126-
}
127-
128101
#[benchmark]
129102
fn add_stake() {
130103
let netuid = NetUid::from(1);
@@ -1280,27 +1253,6 @@ mod pallet_benchmarks {
12801253
);
12811254
}
12821255

1283-
#[benchmark]
1284-
fn set_tao_weights() {
1285-
let netuid = NetUid::from(1);
1286-
let hotkey: T::AccountId = account("A", 0, 6);
1287-
let dests = vec![0u16];
1288-
let weights = vec![0u16];
1289-
let version: u64 = 1;
1290-
1291-
Subtensor::<T>::init_new_network(netuid, 1);
1292-
1293-
#[extrinsic_call]
1294-
_(
1295-
RawOrigin::None,
1296-
netuid,
1297-
hotkey.clone(),
1298-
dests.clone(),
1299-
weights.clone(),
1300-
version,
1301-
);
1302-
}
1303-
13041256
#[benchmark]
13051257
fn swap_hotkey() {
13061258
let coldkey: T::AccountId = whitelisted_caller();

0 commit comments

Comments
 (0)