Skip to content

Commit 58be24f

Browse files
committed
resolve conflict
2 parents fc5ef70 + d6e40f3 commit 58be24f

File tree

14 files changed

+458
-79
lines changed

14 files changed

+458
-79
lines changed

pallets/admin-utils/src/lib.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,11 @@ pub mod pallet {
378378
/// It is only callable by the root account or subnet owner.
379379
/// The extrinsic will call the Subtensor pallet to set the adjustment alpha.
380380
#[pallet::call_index(9)]
381-
#[pallet::weight((
381+
#[pallet::weight(
382382
Weight::from_parts(14_000_000, 0)
383383
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1))
384-
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(1)),
385-
DispatchClass::Operational,
386-
Pays::No
387-
))]
384+
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(1))
385+
)]
388386
pub fn sudo_set_adjustment_alpha(
389387
origin: OriginFor<T>,
390388
netuid: NetUid,
@@ -604,12 +602,10 @@ pub mod pallet {
604602
/// It is only callable by the root account or subnet owner.
605603
/// The extrinsic will call the Subtensor pallet to set the network PoW registration allowed.
606604
#[pallet::call_index(20)]
607-
#[pallet::weight((
605+
#[pallet::weight(
608606
Weight::from_parts(14_000_000, 0)
609-
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1)),
610-
DispatchClass::Operational,
611-
Pays::No
612-
))]
607+
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1))
608+
)]
613609
pub fn sudo_set_network_pow_registration_allowed(
614610
origin: OriginFor<T>,
615611
netuid: NetUid,
@@ -1113,7 +1109,7 @@ pub mod pallet {
11131109
/// # Weight
11141110
/// This function has a fixed weight of 0 and is classified as an operational transaction that does not incur any fees.
11151111
#[pallet::call_index(50)]
1116-
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
1112+
#[pallet::weight((1_000_000, DispatchClass::Normal, Pays::Yes))] // TODO: add proper weights
11171113
pub fn sudo_set_liquid_alpha_enabled(
11181114
origin: OriginFor<T>,
11191115
netuid: NetUid,
@@ -1127,7 +1123,7 @@ pub mod pallet {
11271123

11281124
/// Sets values for liquid alpha
11291125
#[pallet::call_index(51)]
1130-
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
1126+
#[pallet::weight((1_000_000, DispatchClass::Normal, Pays::Yes))] // TODO: add proper weights
11311127
pub fn sudo_set_alpha_values(
11321128
origin: OriginFor<T>,
11331129
netuid: NetUid,
@@ -1306,7 +1302,7 @@ pub mod pallet {
13061302
/// # Weight
13071303
/// This function has a fixed weight of 0 and is classified as an operational transaction that does not incur any fees.
13081304
#[pallet::call_index(61)]
1309-
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
1305+
#[pallet::weight((1_000_000, DispatchClass::Normal, Pays::Yes))] // TODO: add proper weights
13101306
pub fn sudo_set_toggle_transfer(
13111307
origin: OriginFor<T>,
13121308
netuid: NetUid,
@@ -1436,7 +1432,7 @@ pub mod pallet {
14361432
/// # Weight
14371433
/// Weight is handled by the `#[pallet::weight]` attribute.
14381434
#[pallet::call_index(68)]
1439-
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
1435+
#[pallet::weight((1_000_000, DispatchClass::Normal, Pays::Yes))] // TODO: add proper weights
14401436
pub fn sudo_set_alpha_sigmoid_steepness(
14411437
origin: OriginFor<T>,
14421438
netuid: NetUid,
@@ -1471,7 +1467,7 @@ pub mod pallet {
14711467
/// # Weight
14721468
/// This function has a fixed weight of 0 and is classified as an operational transaction that does not incur any fees.
14731469
#[pallet::call_index(69)]
1474-
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
1470+
#[pallet::weight((1_000_000, DispatchClass::Normal, Pays::Yes))] // TODO: add proper weights
14751471
pub fn sudo_set_yuma3_enabled(
14761472
origin: OriginFor<T>,
14771473
netuid: NetUid,
@@ -1495,7 +1491,7 @@ pub mod pallet {
14951491
/// # Weight
14961492
/// This function has a fixed weight of 0 and is classified as an operational transaction that does not incur any fees.
14971493
#[pallet::call_index(70)]
1498-
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
1494+
#[pallet::weight((1_000_000, DispatchClass::Normal, Pays::Yes))] // TODO: add proper weights
14991495
pub fn sudo_set_bonds_reset_enabled(
15001496
origin: OriginFor<T>,
15011497
netuid: NetUid,
@@ -1540,7 +1536,7 @@ pub mod pallet {
15401536
/// # Rate Limiting
15411537
/// This function is rate-limited to one call per subnet per interval (e.g., one week).
15421538
#[pallet::call_index(67)]
1543-
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
1539+
#[pallet::weight((1_000_000, DispatchClass::Normal, Pays::Yes))] // TODO: add proper weights
15441540
pub fn sudo_set_sn_owner_hotkey(
15451541
origin: OriginFor<T>,
15461542
netuid: NetUid,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,8 +1227,8 @@ fn test_set_alpha_values_dispatch_info_ok() {
12271227

12281228
let dispatch_info = call.get_dispatch_info();
12291229

1230-
assert_eq!(dispatch_info.class, DispatchClass::Operational);
1231-
assert_eq!(dispatch_info.pays_fee, Pays::No);
1230+
assert_eq!(dispatch_info.class, DispatchClass::Normal);
1231+
assert_eq!(dispatch_info.pays_fee, Pays::Yes);
12321232
});
12331233
}
12341234

pallets/subtensor/src/coinbase/root.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,10 @@ impl<T: Config> Pallet<T> {
565565
NetworkLastLockCost::<T>::get()
566566
}
567567
pub fn get_network_last_lock_block() -> u64 {
568-
NetworkLastRegistered::<T>::get()
568+
Self::get_rate_limited_last_block(&RateLimitKey::NetworkLastRegistered)
569569
}
570570
pub fn set_network_last_lock_block(block: u64) {
571-
NetworkLastRegistered::<T>::set(block);
571+
Self::set_rate_limited_last_block(&RateLimitKey::NetworkLastRegistered, block);
572572
}
573573
pub fn set_lock_reduction_interval(interval: u64) {
574574
NetworkLockReductionInterval::<T>::set(interval);
@@ -588,10 +588,13 @@ impl<T: Config> Pallet<T> {
588588
let halved_interval: I64F64 = interval.saturating_mul(halving);
589589
halved_interval.saturating_to_num::<u64>()
590590
}
591-
pub fn get_rate_limited_last_block(rate_limit_key: &RateLimitKey) -> u64 {
591+
pub fn get_rate_limited_last_block(rate_limit_key: &RateLimitKey<T::AccountId>) -> u64 {
592592
LastRateLimitedBlock::<T>::get(rate_limit_key)
593593
}
594-
pub fn set_rate_limited_last_block(rate_limit_key: &RateLimitKey, block: u64) {
595-
LastRateLimitedBlock::<T>::set(rate_limit_key, block);
594+
pub fn set_rate_limited_last_block(rate_limit_key: &RateLimitKey<T::AccountId>, block: u64) {
595+
LastRateLimitedBlock::<T>::insert(rate_limit_key, block);
596+
}
597+
pub fn remove_rate_limited_last_block(rate_limit_key: &RateLimitKey<T::AccountId>) {
598+
LastRateLimitedBlock::<T>::remove(rate_limit_key);
596599
}
597600
}

pallets/subtensor/src/lib.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ extern crate alloc;
5454

5555
pub const MAX_CRV3_COMMIT_SIZE_BYTES: u32 = 5000;
5656

57+
#[allow(deprecated)]
5758
#[deny(missing_docs)]
5859
#[import_section(errors::errors)]
5960
#[import_section(events::events)]
@@ -525,11 +526,6 @@ pub mod pallet {
525526
T::InitialNetworkImmunityPeriod::get()
526527
}
527528
#[pallet::type_value]
528-
/// Default value for network last registered.
529-
pub fn DefaultNetworkLastRegistered<T: Config>() -> u64 {
530-
0
531-
}
532-
#[pallet::type_value]
533529
/// Default value for network min allowed UIDs.
534530
pub fn DefaultNetworkMinAllowedUids<T: Config>() -> u16 {
535531
T::InitialNetworkMinAllowedUids::get()
@@ -1173,10 +1169,6 @@ pub mod pallet {
11731169
pub type NetworkImmunityPeriod<T> =
11741170
StorageValue<_, u64, ValueQuery, DefaultNetworkImmunityPeriod<T>>;
11751171
#[pallet::storage]
1176-
/// ITEM( network_last_registered_block )
1177-
pub type NetworkLastRegistered<T> =
1178-
StorageValue<_, u64, ValueQuery, DefaultNetworkLastRegistered<T>>;
1179-
#[pallet::storage]
11801172
/// ITEM( min_network_lock_cost )
11811173
pub type NetworkMinLockCost<T> =
11821174
StorageValue<_, TaoCurrency, ValueQuery, DefaultNetworkMinLockCost<T>>;
@@ -1209,7 +1201,7 @@ pub mod pallet {
12091201
#[pallet::storage]
12101202
/// --- MAP ( RateLimitKey ) --> Block number in which the last rate limited operation occured
12111203
pub type LastRateLimitedBlock<T: Config> =
1212-
StorageMap<_, Identity, RateLimitKey, u64, ValueQuery, DefaultZeroU64<T>>;
1204+
StorageMap<_, Identity, RateLimitKey<T::AccountId>, u64, ValueQuery, DefaultZeroU64<T>>;
12131205

12141206
/// ============================
12151207
/// ==== Subnet Locks =====
@@ -1666,14 +1658,17 @@ pub mod pallet {
16661658
u64,
16671659
ValueQuery,
16681660
>;
1661+
#[deprecated]
16691662
#[pallet::storage]
16701663
/// --- MAP ( key ) --> last_block
16711664
pub type LastTxBlock<T: Config> =
16721665
StorageMap<_, Identity, T::AccountId, u64, ValueQuery, DefaultLastTxBlock<T>>;
1666+
#[deprecated]
16731667
#[pallet::storage]
16741668
/// --- MAP ( key ) --> last_tx_block_childkey_take
16751669
pub type LastTxBlockChildKeyTake<T: Config> =
16761670
StorageMap<_, Identity, T::AccountId, u64, ValueQuery, DefaultLastTxBlock<T>>;
1671+
#[deprecated]
16771672
#[pallet::storage]
16781673
/// --- MAP ( key ) --> last_tx_block_delegate_take
16791674
pub type LastTxBlockDelegateTake<T: Config> =
@@ -2144,9 +2139,17 @@ impl<T: Config + pallet_balances::Config<Balance = u64>>
21442139
/// Enum that defines types of rate limited operations for
21452140
/// storing last block when this operation occured
21462141
#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo)]
2147-
pub enum RateLimitKey {
2142+
pub enum RateLimitKey<AccountId> {
21482143
// The setting sn owner hotkey operation is rate limited per netuid
21492144
SetSNOwnerHotkey(NetUid),
2145+
// Subnet registration rate limit
2146+
NetworkLastRegistered,
2147+
// Last tx block limit per account ID
2148+
LastTxBlock(AccountId),
2149+
// Last tx block child key limit per account ID
2150+
LastTxBlockChildKeyTake(AccountId),
2151+
// Last tx block delegate key limit per account ID
2152+
LastTxBlockDelegateTake(AccountId),
21502153
}
21512154

21522155
pub trait ProxyInterface<AccountId> {

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ mod dispatches {
19451945
#[pallet::call_index(112)]
19461946
#[pallet::weight((
19471947
Weight::from_parts(26_200_000, 0).saturating_add(T::DbWeight::get().reads_writes(4, 1)),
1948-
DispatchClass::Operational,
1948+
DispatchClass::Normal,
19491949
Pays::Yes
19501950
))]
19511951
pub fn update_symbol(
@@ -1989,7 +1989,7 @@ mod dispatches {
19891989
/// * commit_reveal_version (`u16`):
19901990
/// - The client (bittensor-drand) version
19911991
#[pallet::call_index(113)]
1992-
#[pallet::weight((Weight::from_parts(65_020_000, 0)
1992+
#[pallet::weight((Weight::from_parts(80_690_000, 0)
19931993
.saturating_add(T::DbWeight::get().reads(7_u64))
19941994
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
19951995
pub fn commit_timelocked_weights(

pallets/subtensor/src/macros/hooks.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ mod hooks {
135135
//Migrate CRV3 to TimelockedCommits
136136
.saturating_add(migrations::migrate_crv3_v2_to_timelocked::migrate_crv3_v2_to_timelocked::<T>())
137137
// Migrate to fix root counters
138-
.saturating_add(migrations::migrate_fix_root_tao_and_alpha_in::migrate_fix_root_tao_and_alpha_in::<T>());
138+
.saturating_add(migrations::migrate_fix_root_tao_and_alpha_in::migrate_fix_root_tao_and_alpha_in::<T>())
139+
// Migrate last block rate limiting storage items
140+
.saturating_add(migrations::migrate_rate_limiting_last_blocks::migrate_obsolete_rate_limiting_last_blocks_storage::<T>());
139141
weight
140142
}
141143

0 commit comments

Comments
 (0)