Skip to content

Commit ede7a35

Browse files
authored
Merge pull request #2014 from opentensor/auto-stake-fix
Minor fixes and benchmarking of auto-stake extrinsic.
2 parents 45b7b59 + 9e2d575 commit ede7a35

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

pallets/subtensor/src/benchmarks.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,4 +1588,13 @@ mod pallet_benchmarks {
15881588
Subtensor::<T>::get_commit_reveal_weights_version(),
15891589
);
15901590
}
1591+
1592+
#[benchmark]
1593+
fn set_coldkey_auto_stake_hotkey() {
1594+
let coldkey: T::AccountId = whitelisted_caller();
1595+
let hot: T::AccountId = account("A", 0, 1);
1596+
1597+
#[extrinsic_call]
1598+
_(RawOrigin::Signed(coldkey.clone()), hot.clone());
1599+
}
15911600
}

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,9 @@ impl<T: Config> Pallet<T> {
510510
);
511511
continue;
512512
}
513-
let destination: T::AccountId;
513+
514514
let owner: T::AccountId = Owner::<T>::get(&hotkey);
515-
destination = AutoStakeDestination::<T>::get(&owner).unwrap_or(hotkey.clone());
515+
let destination = AutoStakeDestination::<T>::get(&owner).unwrap_or(hotkey.clone());
516516
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
517517
&destination,
518518
&owner,

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,16 +2062,17 @@ mod dispatches {
20622062
/// * `hotkey` (T::AccountId):
20632063
/// - The hotkey account to designate as the autostake destination.
20642064
#[pallet::call_index(114)]
2065-
#[pallet::weight((Weight::from_parts(64_530_000, 0)
2066-
.saturating_add(T::DbWeight::get().reads(7_u64))
2067-
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::Yes))]
2065+
#[pallet::weight(
2066+
Weight::from_parts(5_170_000, 0).saturating_add(T::DbWeight::get().writes(1_u64))
2067+
)]
20682068
pub fn set_coldkey_auto_stake_hotkey(
20692069
origin: T::RuntimeOrigin,
20702070
hotkey: T::AccountId,
20712071
) -> DispatchResult {
20722072
let coldkey = ensure_signed(origin)?;
2073-
log::debug!("set_coldkey_auto_stake_hotkey( origin:{coldkey:?} hotkey:{hotkey:?} )");
2073+
20742074
AutoStakeDestination::<T>::insert(coldkey, hotkey.clone());
2075+
20752076
Ok(())
20762077
}
20772078
}

pallets/subtensor/src/tests/coinbase.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2770,7 +2770,10 @@ fn test_incentive_is_autostaked_to_owner_destination() {
27702770
Uids::<Test>::insert(netuid, dest_hk, 2);
27712771

27722772
// Set autostake destination for the miner's coldkey
2773-
AutoStakeDestination::<Test>::insert(miner_ck, dest_hk);
2773+
assert_ok!(SubtensorModule::set_coldkey_auto_stake_hotkey(
2774+
RuntimeOrigin::signed(miner_ck),
2775+
dest_hk,
2776+
));
27742777

27752778
assert_eq!(
27762779
SubtensorModule::get_stake_for_hotkey_on_subnet(&miner_hk, netuid),

0 commit comments

Comments
 (0)