Skip to content

Commit

Permalink
update dissolve network origin
Browse files Browse the repository at this point in the history
  • Loading branch information
open-junius committed Aug 21, 2024
1 parent 9424806 commit 8ea7255
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pallets/subtensor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ benchmarks! {
let amount_to_be_staked = 100_000_000_000_000u64;
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked);
assert_ok!(Subtensor::<T>::register_network(RawOrigin::Signed(coldkey.clone()).into()));
}: dissolve_network(RawOrigin::Signed(coldkey), 1)
}: dissolve_network(RawOrigin::Root, coldkey, 1)

// swap_hotkey {
// let seed: u32 = 1;
Expand Down
3 changes: 1 addition & 2 deletions pallets/subtensor/src/coinbase/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,9 +992,8 @@ impl<T: Config> Pallet<T> {
/// * 'SubNetworkDoesNotExist': If the specified network does not exist.
/// * 'NotSubnetOwner': If the caller does not own the specified subnet.
///
pub fn user_remove_network(origin: T::RuntimeOrigin, netuid: u16) -> dispatch::DispatchResult {
pub fn user_remove_network(coldkey: T::AccountId, netuid: u16) -> dispatch::DispatchResult {
// --- 1. Ensure the function caller is a signed user.
let coldkey = ensure_signed(origin)?;

// --- 2. Ensure this subnet exists.
ensure!(
Expand Down
18 changes: 13 additions & 5 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ mod dispatches {
new_coldkey: T::AccountId,
) -> DispatchResultWithPostInfo {
// Ensure it's called with root privileges (scheduler has root privileges)
ensure_root(origin.clone())?;
ensure_root(origin)?;
log::info!("swap_coldkey: {:?} -> {:?}", old_coldkey, new_coldkey);

Self::do_swap_coldkey(&old_coldkey, &new_coldkey)
Expand Down Expand Up @@ -930,8 +930,13 @@ mod dispatches {
#[pallet::weight((Weight::from_parts(119_000_000, 0)
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(31)), DispatchClass::Operational, Pays::No))]
pub fn dissolve_network(origin: OriginFor<T>, netuid: u16) -> DispatchResult {
Self::user_remove_network(origin, netuid)
pub fn dissolve_network(
origin: OriginFor<T>,
coldkey: T::AccountId,
netuid: u16,
) -> DispatchResult {
ensure_root(origin)?;
Self::user_remove_network(coldkey, netuid)
}

/// Set a single child for a given hotkey on a specified network.
Expand Down Expand Up @@ -1100,7 +1105,10 @@ mod dispatches {
let duration: BlockNumberFor<T> = DissolveNetworkScheduleDuration::<T>::get();
let when: BlockNumberFor<T> = current_block.saturating_add(duration);

let call = Call::<T>::dissolve_network { netuid };
let call = Call::<T>::dissolve_network {
coldkey: who.clone(),
netuid,
};

let bound_call = T::Preimages::bound(LocalCallOf::<T>::from(call.clone()))
.map_err(|_| Error::<T>::FailedToSchedule)?;
Expand All @@ -1109,7 +1117,7 @@ mod dispatches {
DispatchTime::At(when),
None,
63,
frame_system::RawOrigin::Signed(who.clone()).into(),
frame_system::RawOrigin::Root.into(),
bound_call,
)
.map_err(|_| Error::<T>::FailedToSchedule)?;
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/tests/networks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn test_registration_ok() {
));

assert_ok!(SubtensorModule::user_remove_network(
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
coldkey_account_id,
netuid
));

Expand Down
14 changes: 10 additions & 4 deletions pallets/subtensor/tests/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,8 @@ fn test_dissolve_network_ok() {

assert!(SubtensorModule::if_subnet_exist(netuid));
assert_ok!(SubtensorModule::dissolve_network(
RuntimeOrigin::signed(owner_coldkey),
RuntimeOrigin::root(),
owner_coldkey,
netuid
));
assert!(!SubtensorModule::if_subnet_exist(netuid))
Expand All @@ -937,7 +938,8 @@ fn test_dissolve_network_refund_coldkey_ok() {

assert!(SubtensorModule::if_subnet_exist(netuid));
assert_ok!(SubtensorModule::dissolve_network(
RuntimeOrigin::signed(owner_coldkey),
RuntimeOrigin::root(),
owner_coldkey,
netuid
));
assert!(!SubtensorModule::if_subnet_exist(netuid));
Expand All @@ -961,7 +963,11 @@ fn test_dissolve_network_not_owner_err() {
register_ok_neuron(netuid, hotkey, owner_coldkey, 3);

assert_err!(
SubtensorModule::dissolve_network(RuntimeOrigin::signed(random_coldkey), netuid),
SubtensorModule::dissolve_network(
RuntimeOrigin::signed(random_coldkey),
random_coldkey,
netuid
),
Error::<Test>::NotSubnetOwner
);
});
Expand All @@ -974,7 +980,7 @@ fn test_dissolve_network_does_not_exist_err() {
let coldkey = U256::from(2);

assert_err!(
SubtensorModule::dissolve_network(RuntimeOrigin::signed(coldkey), netuid),
SubtensorModule::dissolve_network(RuntimeOrigin::root(), coldkey, netuid),
Error::<Test>::SubNetworkDoesNotExist
);
});
Expand Down

0 comments on commit 8ea7255

Please sign in to comment.