Skip to content

Commit 7c36b3f

Browse files
authored
Merge pull request #1944 from opentensor/feat/validate-reg-network
Feat/validate reg network
2 parents 1cbc11d + bc24c46 commit 7c36b3f

File tree

5 files changed

+55
-64
lines changed

5 files changed

+55
-64
lines changed

Cargo.lock

Lines changed: 40 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ mod dispatches {
186186
/// - On failure for each failed item in the batch.
187187
///
188188
#[pallet::call_index(100)]
189-
#[pallet::weight((Weight::from_parts(82_010_000, 0)
189+
#[pallet::weight((Weight::from_parts(100_500_000, 0)
190190
.saturating_add(T::DbWeight::get().reads(8))
191191
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
192192
pub fn batch_commit_weights(
@@ -891,7 +891,7 @@ mod dispatches {
891891
///
892892
#[pallet::call_index(69)]
893893
#[pallet::weight((
894-
Weight::from_parts(5_912_000, 0)
894+
Weight::from_parts(5_660_000, 0)
895895
.saturating_add(T::DbWeight::get().reads(0))
896896
.saturating_add(T::DbWeight::get().writes(1)),
897897
DispatchClass::Operational,
@@ -1041,7 +1041,7 @@ mod dispatches {
10411041
#[pallet::call_index(59)]
10421042
#[pallet::weight((Weight::from_parts(235_400_000, 0)
10431043
.saturating_add(T::DbWeight::get().reads(36))
1044-
.saturating_add(T::DbWeight::get().writes(51_u64)), DispatchClass::Normal, Pays::No))]
1044+
.saturating_add(T::DbWeight::get().writes(52)), DispatchClass::Normal, Pays::Yes))]
10451045
pub fn register_network(origin: OriginFor<T>, hotkey: T::AccountId) -> DispatchResult {
10461046
Self::do_register_network(origin, &hotkey, 1, None)
10471047
}
@@ -1328,7 +1328,7 @@ mod dispatches {
13281328
#[pallet::call_index(79)]
13291329
#[pallet::weight((Weight::from_parts(234_200_000, 0)
13301330
.saturating_add(T::DbWeight::get().reads(35))
1331-
.saturating_add(T::DbWeight::get().writes(50_u64)), DispatchClass::Normal, Pays::No))]
1331+
.saturating_add(T::DbWeight::get().writes(51)), DispatchClass::Normal, Pays::Yes))]
13321332
pub fn register_network_with_identity(
13331333
origin: OriginFor<T>,
13341334
hotkey: T::AccountId,
@@ -2011,7 +2011,7 @@ mod dispatches {
20112011
/// Set the autostake destination hotkey for a coldkey.
20122012
///
20132013
/// The caller selects a hotkey where all future rewards
2014-
/// will be automatically staked.
2014+
/// will be automatically staked.
20152015
///
20162016
/// # Args:
20172017
/// * `origin` - (<T as frame_system::Config>::Origin):

pallets/subtensor/src/subnets/subnet.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ impl<T: Config> Pallet<T> {
134134

135135
// --- 4. Rate limit for network registrations.
136136
let current_block = Self::get_current_block_as_u64();
137-
let last_lock_block = Self::get_network_last_lock_block();
138137
ensure!(
139-
current_block.saturating_sub(last_lock_block) >= NetworkRateLimit::<T>::get(),
138+
Self::passes_rate_limit(&TransactionType::RegisterNetwork, &coldkey),
140139
Error::<T>::NetworkTxRateLimitExceeded
141140
);
142141

pallets/subtensor/src/transaction_extension.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{
22
BalancesCall, Call, ColdkeySwapScheduled, Config, CustomTransactionError, Error, Pallet,
3+
TransactionType,
34
};
45
use codec::{Decode, DecodeWithMemTracking, Encode};
56
use frame_support::dispatch::{DispatchInfo, PostDispatchInfo};
@@ -277,6 +278,13 @@ where
277278
)
278279
.map(|validity| (validity, Some(who.clone()), origin.clone()))
279280
}
281+
Some(Call::register_network { .. }) => {
282+
if !Pallet::<T>::passes_rate_limit(&TransactionType::RegisterNetwork, who) {
283+
return Err(CustomTransactionError::RateLimitExceeded.into());
284+
}
285+
286+
Ok((Default::default(), Some(who.clone()), origin))
287+
}
280288
_ => Ok((Default::default(), Some(who.clone()), origin)),
281289
}
282290
}

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
220220
// `spec_version`, and `authoring_version` are the same between Wasm and native.
221221
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
222222
// the compatible custom types.
223-
spec_version: 313,
223+
spec_version: 314,
224224
impl_version: 1,
225225
apis: RUNTIME_API_VERSIONS,
226226
transaction_version: 1,

0 commit comments

Comments
 (0)