Skip to content

Commit

Permalink
Update rate limit for setting children to 7200
Browse files Browse the repository at this point in the history
  • Loading branch information
gztensor committed Nov 29, 2024
1 parent 5747644 commit c17eb3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pallets/subtensor/src/utils/rate_limiting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ impl<T: Config> Pallet<T> {
// ==== Rate Limiting =====
// ========================
/// Get the rate limit for a specific transaction type
pub fn get_rate_limit(tx_type: &TransactionType, netuid: u16) -> u64 {
let subnet_tempo = Self::get_tempo(netuid);
pub fn get_rate_limit(tx_type: &TransactionType, _netuid: u16) -> u64 {
match tx_type {
TransactionType::SetChildren => (subnet_tempo.saturating_mul(2)).into(), // Cannot set children twice within the default tempo period.
TransactionType::SetChildren => 7200, // Cannot set children twice within a day
TransactionType::SetChildkeyTake => TxChildkeyTakeRateLimit::<T>::get(),
TransactionType::Unknown => 0, // Default to no limit for unknown types (no limit)
}
Expand Down
4 changes: 4 additions & 0 deletions pallets/subtensor/tests/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ fn test_add_singular_child() {
Err(Error::<Test>::SubNetworkDoesNotExist.into())
);
add_network(netuid, 0, 0);
step_rate_limit(&TransactionType::SetChildren, netuid);
assert_eq!(
SubtensorModule::do_set_children(
RuntimeOrigin::signed(coldkey),
Expand All @@ -367,6 +368,7 @@ fn test_add_singular_child() {
Err(Error::<Test>::NonAssociatedColdKey.into())
);
SubtensorModule::create_account_if_non_existent(&coldkey, &hotkey);
step_rate_limit(&TransactionType::SetChildren, netuid);
assert_eq!(
SubtensorModule::do_set_children(
RuntimeOrigin::signed(coldkey),
Expand All @@ -377,6 +379,7 @@ fn test_add_singular_child() {
Err(Error::<Test>::InvalidChild.into())
);
let child = U256::from(3);
step_rate_limit(&TransactionType::SetChildren, netuid);
assert_ok!(SubtensorModule::do_set_children(
RuntimeOrigin::signed(coldkey),
hotkey,
Expand Down Expand Up @@ -2396,6 +2399,7 @@ fn test_dynamic_parent_child_relationships() {
step_block(11);

// Change parent-child relationships
step_rate_limit(&TransactionType::SetChildren, netuid);
assert_ok!(SubtensorModule::do_set_children(
RuntimeOrigin::signed(coldkey_parent),
parent,
Expand Down

0 comments on commit c17eb3f

Please sign in to comment.