Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract subnet specific take logic from dynamic branch #600

Open
5 tasks
distributedstatemachine opened this issue Jul 1, 2024 · 2 comments
Open
5 tasks
Assignees

Comments

@distributedstatemachine
Copy link
Contributor

distributedstatemachine commented Jul 1, 2024

Description

Child keys require delegates to be able to set subnet specific takes. This is already implemented in the dynamic branch. We need to extract the relevant code from that branch into the chain_bloat branch.

Acceptance Criteria

  • Implement a new function do_set_delegate_takes that allows delegates to set take rates for multiple subnets in a single transaction.
  • The function should validate that the caller (coldkey) owns the specified hotkey.
  • Each take rate should be checked against the maximum allowed take rate.
  • The function should enforce rate limiting for take rate changes.
  • The function should check if each specified subnet exists.

Tasks

pub fn do_set_delegate_takes(
    origin: T::RuntimeOrigin,
    hotkey: &T::AccountId,
    takes: Vec<(u16, u16)>,
) -> dispatch::DispatchResult {
    let coldkey = ensure_signed(origin)?;
    log::trace!(
        "do_increase_take( origin:{:?} hotkey:{:?}, take:{:?} )",
        coldkey,
        hotkey,
        takes
    );

    // --- 2. Ensure we are delegating a known key.
    //        Ensure that the coldkey is the owner.
    Self::do_account_checks(&coldkey, hotkey)?;
    let block: u64 = Self::get_current_block_as_u64();

    for (netuid, take) in takes {
        // Check if the subnet exists before setting the take.
        ensure!(
            Self::if_subnet_exist(netuid),
            Error::<T>::SubNetworkDoesNotExist
        );

        // Ensure the take does not exceed the initial default take.
        let max_take = T::InitialDefaultTake::get();
        ensure!(take <= max_take, Error::<T>::DelegateTakeTooHigh);

        // Enforce the rate limit (independently on do_add_stake rate limits)
        ensure!(
            !Self::exceeds_tx_delegate_take_rate_limit(
                Self::get_last_tx_block_delegate_take(hotkey),
                block
            ),
            Error::<T>::DelegateTxRateLimitExceeded
        );

        // Insert the take into the storage.
        DelegatesTake::<T>::insert(hotkey, netuid, take);
    }

    // Set last block for rate limiting after all takes are set
    Self::set_last_tx_block_delegate_take(hotkey, block);

    Ok(())
}
  • Add appropriate error handling for invalid inputs or conditions
  • Implement rate limiting for the do_set_delegate_takes function
  • Add events for successful take rate changes
  • Update relevant helper functions to work with the new do_set_delegate_takes functionality
@distributedstatemachine
Copy link
Contributor Author

@open-junius can you please add the commit you finished this in . Also , can you migrate the tests before you close it.

@open-junius
Copy link
Contributor

Ok, the last commit is ae628b8. I will check the test cases, and migrate them to chain_bloat branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants