Skip to content

Commit

Permalink
Fix rate limit for setting children
Browse files Browse the repository at this point in the history
  • Loading branch information
gztensor committed Aug 14, 2024
1 parent 8f9e841 commit ce0dfa7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 11 additions & 1 deletion pallets/subtensor/src/staking/set_children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,22 @@ impl<T: Config> Pallet<T> {
// Ensure the hotkey passes the rate limit.
ensure!(
Self::passes_rate_limit_globally(
&TransactionType::SetChildren, // Set children.
&hotkey, // Specific to a hotkey.
netuid, // Specific to a subnet.
&TransactionType::SetChildren, // Set children.
),
Error::<T>::TxRateLimitExceeded
);

// Set last transaction block
let current_block = Self::get_current_block_as_u64();
Self::set_last_transaction_block(
&hotkey,
netuid,
&TransactionType::SetChildren,
current_block
);

// --- 2. Check that this delegation is not on the root network. Child hotkeys are not valid on root.
ensure!(
netuid != Self::get_root_netuid(),
Expand Down
7 changes: 5 additions & 2 deletions pallets/subtensor/src/utils/rate_limiting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ impl<T: Config> Pallet<T> {
}

/// Check if a transaction should be rate limited globally
pub fn passes_rate_limit_globally(tx_type: &TransactionType, hotkey: &T::AccountId) -> bool {
let netuid: u16 = u16::MAX;
pub fn passes_rate_limit_globally(
hotkey: &T::AccountId,
netuid: u16,
tx_type: &TransactionType,
) -> bool {
let block: u64 = Self::get_current_block_as_u64();
let limit: u64 = Self::get_rate_limit(tx_type);
let last_block: u64 = Self::get_last_transaction_block(hotkey, netuid, tx_type);
Expand Down

0 comments on commit ce0dfa7

Please sign in to comment.