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

Add delegate take argument to root_register extrinsic and set_delegate_take extrinsic #193

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ pub mod pallet {
NetworkMinLockCostSet(u64), // Event created when the network minimum locking cost is set.
SubnetLimitSet(u16), // Event created when the maximum number of subnets is set
NetworkLockCostReductionIntervalSet(u64), // Event created when the lock cost reduction is set
DelegateTakeSet(u16),
}

// Errors inform users that something went wrong.
Expand Down Expand Up @@ -1504,8 +1505,8 @@ pub mod pallet {
#[pallet::weight((Weight::from_ref_time(120_000_000)
.saturating_add(T::DbWeight::get().reads(23))
.saturating_add(T::DbWeight::get().writes(20)), DispatchClass::Normal, Pays::No))]
pub fn root_register(origin: OriginFor<T>, hotkey: T::AccountId) -> DispatchResult {
Self::do_root_register(origin, hotkey)
pub fn root_register(origin: OriginFor<T>, hotkey: T::AccountId, take: u16) -> DispatchResult {
Self::do_root_register(origin, hotkey, take)
}

#[pallet::call_index(7)]
Expand Down Expand Up @@ -1535,6 +1536,24 @@ pub mod pallet {
Self::do_sudo_registration(origin, netuid, hotkey, coldkey, stake, balance)
}

#[pallet::call_index(70)]
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
pub fn set_delegate_take(
origin: OriginFor<T>,
hotkey: T::AccountId,
take: u16
) -> DispatchResult {
let coldkey = ensure_signed(origin)?;
ensure!(Self::coldkey_owns_hotkey(&coldkey, &hotkey), Error::<T>::NonAssociatedColdKey);
ensure!(Self::hotkey_is_delegate(&hotkey), Error::<T>::NotDelegate);

Delegates::<T>::set(hotkey, take);

Self::deposit_event(Event::<T>::DelegateTakeSet(take));

Ok(())
}

// ---- SUDO ONLY FUNCTIONS ------------------------------------------------------------

// ==================================
Expand Down
4 changes: 2 additions & 2 deletions pallets/subtensor/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ impl<T: Config> Pallet<T> {
// # Returns:
// * 'DispatchResult': A result type indicating success or failure of the registration.
//
pub fn do_root_register(origin: T::RuntimeOrigin, hotkey: T::AccountId) -> DispatchResult {
pub fn do_root_register(origin: T::RuntimeOrigin, hotkey: T::AccountId, cut: u16) -> DispatchResult {
// --- 0. Get the unique identifier (UID) for the root network.
let root_netuid: u16 = Self::get_root_netuid();
let current_block_number: u64 = Self::get_current_block_as_u64();
Expand Down Expand Up @@ -508,7 +508,7 @@ impl<T: Config> Pallet<T> {

// --- 13. Force all members on root to become a delegate.
if !Self::hotkey_is_delegate(&hotkey) {
Self::delegate_hotkey(&hotkey, 11_796); // 18% cut defaulted.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the conversion factor here? Would like to add some guardrails on the python side

Self::delegate_hotkey(&hotkey, cut);
}

// --- 14. Update the registration counters for both the block and interval.
Expand Down
9 changes: 8 additions & 1 deletion pallets/subtensor/tests/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fn test_root_register_network_exist() {
assert_ok!(SubtensorModule::root_register(
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
hotkey_account_id,
11_796
));
});
}
Expand Down Expand Up @@ -124,6 +125,7 @@ fn test_root_register_stake_based_pruning_works() {
assert_ok!(SubtensorModule::root_register(
<<Test as Config>::RuntimeOrigin>::signed(cold),
hot,
11_796
));
// Check succesfull registration.
assert!(SubtensorModule::get_uid_for_net_and_hotkey(root_netuid, &hot).is_ok());
Expand All @@ -139,6 +141,7 @@ fn test_root_register_stake_based_pruning_works() {
assert_ok!(SubtensorModule::root_register(
<<Test as Config>::RuntimeOrigin>::signed(cold),
hot,
11_796
));
// Check succesfull registration.
assert!(SubtensorModule::get_uid_for_net_and_hotkey(root_netuid, &hot).is_ok());
Expand All @@ -153,6 +156,7 @@ fn test_root_register_stake_based_pruning_works() {
SubtensorModule::root_register(
<<Test as Config>::RuntimeOrigin>::signed(cold),
hot,
11_796
),
Err(Error::<Test>::StakeTooLowForRoot.into())
);
Expand Down Expand Up @@ -184,6 +188,7 @@ fn test_root_set_weights() {
assert_ok!(SubtensorModule::root_register(
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
hotkey_account_id,
11_796
));
assert_ok!(SubtensorModule::add_stake(
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
Expand Down Expand Up @@ -278,6 +283,7 @@ fn test_root_set_weights_out_of_order_netuids() {
assert_ok!(SubtensorModule::root_register(
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
hotkey_account_id,
11_796
));
assert_ok!(SubtensorModule::add_stake(
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
Expand Down Expand Up @@ -469,7 +475,8 @@ fn test_network_pruning() {
SubtensorModule::add_balance_to_coldkey_account(&cold, 1_000_000_000_000_000);
assert_ok!(SubtensorModule::root_register(
<<Test as Config>::RuntimeOrigin>::signed(cold),
hot
hot,
11_796
));
assert_ok!(SubtensorModule::add_stake(
<<Test as Config>::RuntimeOrigin>::signed(cold),
Expand Down
16 changes: 11 additions & 5 deletions pallets/subtensor/tests/senate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ fn test_senate_join_works() {

assert_ok!(SubtensorModule::root_register(
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
hotkey_account_id
hotkey_account_id,
11_796
));
assert_eq!(Senate::is_member(&hotkey_account_id), true);
});
Expand Down Expand Up @@ -181,7 +182,8 @@ fn test_senate_vote_works() {

assert_ok!(SubtensorModule::root_register(
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
hotkey_account_id
hotkey_account_id,
11_796
));
assert_eq!(Senate::is_member(&hotkey_account_id), true);

Expand Down Expand Up @@ -351,7 +353,8 @@ fn test_senate_leave_works() {

assert_ok!(SubtensorModule::root_register(
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
hotkey_account_id
hotkey_account_id,
11_796
));
assert_eq!(Senate::is_member(&hotkey_account_id), true);
});
Expand Down Expand Up @@ -421,7 +424,8 @@ fn test_senate_leave_vote_removal() {

assert_ok!(SubtensorModule::root_register(
coldkey_origin.clone(),
hotkey_account_id
hotkey_account_id,
11_796
));
assert_eq!(Senate::is_member(&hotkey_account_id), true);

Expand Down Expand Up @@ -476,6 +480,7 @@ fn test_senate_leave_vote_removal() {
assert_ok!(SubtensorModule::root_register(
<<Test as Config>::RuntimeOrigin>::signed(cold),
hot,
11_796
));
// Check succesfull registration.
assert!(SubtensorModule::get_uid_for_net_and_hotkey(other_netuid, &hot).is_ok());
Expand Down Expand Up @@ -557,7 +562,8 @@ fn test_senate_not_leave_when_stake_removed() {

assert_ok!(SubtensorModule::root_register(
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
hotkey_account_id
hotkey_account_id,
11_796
));
assert_eq!(Senate::is_member(&hotkey_account_id), true);

Expand Down
Loading