Skip to content

Commit ce0dfa7

Browse files
committed
Fix rate limit for setting children
1 parent 8f9e841 commit ce0dfa7

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

pallets/subtensor/src/staking/set_children.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,22 @@ impl<T: Config> Pallet<T> {
6161
// Ensure the hotkey passes the rate limit.
6262
ensure!(
6363
Self::passes_rate_limit_globally(
64-
&TransactionType::SetChildren, // Set children.
6564
&hotkey, // Specific to a hotkey.
65+
netuid, // Specific to a subnet.
66+
&TransactionType::SetChildren, // Set children.
6667
),
6768
Error::<T>::TxRateLimitExceeded
6869
);
6970

71+
// Set last transaction block
72+
let current_block = Self::get_current_block_as_u64();
73+
Self::set_last_transaction_block(
74+
&hotkey,
75+
netuid,
76+
&TransactionType::SetChildren,
77+
current_block
78+
);
79+
7080
// --- 2. Check that this delegation is not on the root network. Child hotkeys are not valid on root.
7181
ensure!(
7282
netuid != Self::get_root_netuid(),

pallets/subtensor/src/utils/rate_limiting.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ impl<T: Config> Pallet<T> {
5858
}
5959

6060
/// Check if a transaction should be rate limited globally
61-
pub fn passes_rate_limit_globally(tx_type: &TransactionType, hotkey: &T::AccountId) -> bool {
62-
let netuid: u16 = u16::MAX;
61+
pub fn passes_rate_limit_globally(
62+
hotkey: &T::AccountId,
63+
netuid: u16,
64+
tx_type: &TransactionType,
65+
) -> bool {
6366
let block: u64 = Self::get_current_block_as_u64();
6467
let limit: u64 = Self::get_rate_limit(tx_type);
6568
let last_block: u64 = Self::get_last_transaction_block(hotkey, netuid, tx_type);

0 commit comments

Comments
 (0)