diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index 42e3d79a23..6dd5390992 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -1588,4 +1588,13 @@ mod pallet_benchmarks { Subtensor::::get_commit_reveal_weights_version(), ); } + + #[benchmark] + fn set_coldkey_auto_stake_hotkey() { + let coldkey: T::AccountId = whitelisted_caller(); + let hot: T::AccountId = account("A", 0, 1); + + #[extrinsic_call] + _(RawOrigin::Signed(coldkey.clone()), hot.clone()); + } } diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index b14dd9e826..c143d16a16 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -510,9 +510,9 @@ impl Pallet { ); continue; } - let destination: T::AccountId; + let owner: T::AccountId = Owner::::get(&hotkey); - destination = AutoStakeDestination::::get(&owner).unwrap_or(hotkey.clone()); + let destination = AutoStakeDestination::::get(&owner).unwrap_or(hotkey.clone()); Self::increase_stake_for_hotkey_and_coldkey_on_subnet( &destination, &owner, diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index b758bc74cc..c842709208 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -2062,16 +2062,17 @@ mod dispatches { /// * `hotkey` (T::AccountId): /// - The hotkey account to designate as the autostake destination. #[pallet::call_index(114)] - #[pallet::weight((Weight::from_parts(64_530_000, 0) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::Yes))] + #[pallet::weight( + Weight::from_parts(5_170_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)) + )] pub fn set_coldkey_auto_stake_hotkey( origin: T::RuntimeOrigin, hotkey: T::AccountId, ) -> DispatchResult { let coldkey = ensure_signed(origin)?; - log::debug!("set_coldkey_auto_stake_hotkey( origin:{coldkey:?} hotkey:{hotkey:?} )"); + AutoStakeDestination::::insert(coldkey, hotkey.clone()); + Ok(()) } } diff --git a/pallets/subtensor/src/tests/coinbase.rs b/pallets/subtensor/src/tests/coinbase.rs index 4781ad2dbd..ccad86855b 100644 --- a/pallets/subtensor/src/tests/coinbase.rs +++ b/pallets/subtensor/src/tests/coinbase.rs @@ -2770,7 +2770,10 @@ fn test_incentive_is_autostaked_to_owner_destination() { Uids::::insert(netuid, dest_hk, 2); // Set autostake destination for the miner's coldkey - AutoStakeDestination::::insert(miner_ck, dest_hk); + assert_ok!(SubtensorModule::set_coldkey_auto_stake_hotkey( + RuntimeOrigin::signed(miner_ck), + dest_hk, + )); assert_eq!( SubtensorModule::get_stake_for_hotkey_on_subnet(&miner_hk, netuid),