Skip to content

Commit 8ea7255

Browse files
committed
update dissolve network origin
1 parent 9424806 commit 8ea7255

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

pallets/subtensor/src/benchmarks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ benchmarks! {
312312
let amount_to_be_staked = 100_000_000_000_000u64;
313313
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked);
314314
assert_ok!(Subtensor::<T>::register_network(RawOrigin::Signed(coldkey.clone()).into()));
315-
}: dissolve_network(RawOrigin::Signed(coldkey), 1)
315+
}: dissolve_network(RawOrigin::Root, coldkey, 1)
316316

317317
// swap_hotkey {
318318
// let seed: u32 = 1;

pallets/subtensor/src/coinbase/root.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,9 +992,8 @@ impl<T: Config> Pallet<T> {
992992
/// * 'SubNetworkDoesNotExist': If the specified network does not exist.
993993
/// * 'NotSubnetOwner': If the caller does not own the specified subnet.
994994
///
995-
pub fn user_remove_network(origin: T::RuntimeOrigin, netuid: u16) -> dispatch::DispatchResult {
995+
pub fn user_remove_network(coldkey: T::AccountId, netuid: u16) -> dispatch::DispatchResult {
996996
// --- 1. Ensure the function caller is a signed user.
997-
let coldkey = ensure_signed(origin)?;
998997

999998
// --- 2. Ensure this subnet exists.
1000999
ensure!(

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ mod dispatches {
681681
new_coldkey: T::AccountId,
682682
) -> DispatchResultWithPostInfo {
683683
// Ensure it's called with root privileges (scheduler has root privileges)
684-
ensure_root(origin.clone())?;
684+
ensure_root(origin)?;
685685
log::info!("swap_coldkey: {:?} -> {:?}", old_coldkey, new_coldkey);
686686

687687
Self::do_swap_coldkey(&old_coldkey, &new_coldkey)
@@ -930,8 +930,13 @@ mod dispatches {
930930
#[pallet::weight((Weight::from_parts(119_000_000, 0)
931931
.saturating_add(T::DbWeight::get().reads(6))
932932
.saturating_add(T::DbWeight::get().writes(31)), DispatchClass::Operational, Pays::No))]
933-
pub fn dissolve_network(origin: OriginFor<T>, netuid: u16) -> DispatchResult {
934-
Self::user_remove_network(origin, netuid)
933+
pub fn dissolve_network(
934+
origin: OriginFor<T>,
935+
coldkey: T::AccountId,
936+
netuid: u16,
937+
) -> DispatchResult {
938+
ensure_root(origin)?;
939+
Self::user_remove_network(coldkey, netuid)
935940
}
936941

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

1103-
let call = Call::<T>::dissolve_network { netuid };
1108+
let call = Call::<T>::dissolve_network {
1109+
coldkey: who.clone(),
1110+
netuid,
1111+
};
11041112

11051113
let bound_call = T::Preimages::bound(LocalCallOf::<T>::from(call.clone()))
11061114
.map_err(|_| Error::<T>::FailedToSchedule)?;
@@ -1109,7 +1117,7 @@ mod dispatches {
11091117
DispatchTime::At(when),
11101118
None,
11111119
63,
1112-
frame_system::RawOrigin::Signed(who.clone()).into(),
1120+
frame_system::RawOrigin::Root.into(),
11131121
bound_call,
11141122
)
11151123
.map_err(|_| Error::<T>::FailedToSchedule)?;

pallets/subtensor/tests/networks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn test_registration_ok() {
3535
));
3636

3737
assert_ok!(SubtensorModule::user_remove_network(
38-
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
38+
coldkey_account_id,
3939
netuid
4040
));
4141

pallets/subtensor/tests/root.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,8 @@ fn test_dissolve_network_ok() {
914914

915915
assert!(SubtensorModule::if_subnet_exist(netuid));
916916
assert_ok!(SubtensorModule::dissolve_network(
917-
RuntimeOrigin::signed(owner_coldkey),
917+
RuntimeOrigin::root(),
918+
owner_coldkey,
918919
netuid
919920
));
920921
assert!(!SubtensorModule::if_subnet_exist(netuid))
@@ -937,7 +938,8 @@ fn test_dissolve_network_refund_coldkey_ok() {
937938

938939
assert!(SubtensorModule::if_subnet_exist(netuid));
939940
assert_ok!(SubtensorModule::dissolve_network(
940-
RuntimeOrigin::signed(owner_coldkey),
941+
RuntimeOrigin::root(),
942+
owner_coldkey,
941943
netuid
942944
));
943945
assert!(!SubtensorModule::if_subnet_exist(netuid));
@@ -961,7 +963,11 @@ fn test_dissolve_network_not_owner_err() {
961963
register_ok_neuron(netuid, hotkey, owner_coldkey, 3);
962964

963965
assert_err!(
964-
SubtensorModule::dissolve_network(RuntimeOrigin::signed(random_coldkey), netuid),
966+
SubtensorModule::dissolve_network(
967+
RuntimeOrigin::signed(random_coldkey),
968+
random_coldkey,
969+
netuid
970+
),
965971
Error::<Test>::NotSubnetOwner
966972
);
967973
});
@@ -974,7 +980,7 @@ fn test_dissolve_network_does_not_exist_err() {
974980
let coldkey = U256::from(2);
975981

976982
assert_err!(
977-
SubtensorModule::dissolve_network(RuntimeOrigin::signed(coldkey), netuid),
983+
SubtensorModule::dissolve_network(RuntimeOrigin::root(), coldkey, netuid),
978984
Error::<Test>::SubNetworkDoesNotExist
979985
);
980986
});

0 commit comments

Comments
 (0)