Skip to content

Commit f6903ac

Browse files
committed
become delegate on every add_stake op
1 parent 0ac6947 commit f6903ac

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

pallets/subtensor/src/staking/add_stake.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,15 @@ impl<T: Config> Pallet<T> {
142142
allow_partial,
143143
)?;
144144

145-
// 4. Ensure the remove operation from the coldkey is a success.
145+
// 4. If the coldkey is not the owner, make the hotkey a delegate.
146+
if Self::get_owning_coldkey_for_hotkey(&hotkey) != coldkey {
147+
Self::maybe_become_delegate(&hotkey);
148+
}
149+
150+
// 5. Ensure the remove operation from the coldkey is a success.
146151
let tao_staked: u64 = Self::remove_balance_from_coldkey_account(&coldkey, possible_stake)?;
147152

148-
// 5. Swap the stake into alpha on the subnet and increase counters.
153+
// 6. Swap the stake into alpha on the subnet and increase counters.
149154
// Emit the staking event.
150155
let fee = DefaultStakingFee::<T>::get();
151156
Self::stake_into_subnet(&hotkey, &coldkey, netuid, tao_staked, fee);

pallets/subtensor/src/staking/helpers.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ impl<T: Config> Pallet<T> {
9999
}
100100
}
101101

102+
//// If the hotkey is not a delegate, make it a delegate.
103+
pub fn maybe_become_delegate(hotkey: &T::AccountId) {
104+
if !Self::hotkey_is_delegate(hotkey) {
105+
Self::delegate_hotkey(hotkey, Self::get_hotkey_take(hotkey));
106+
}
107+
}
108+
102109
/// Returns the coldkey owning this hotkey. This function should only be called for active accounts.
103110
///
104111
/// # Arguments

pallets/subtensor/src/staking/move_stake.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ impl<T: Config> Pallet<T> {
344344
// Because of the fee, the tao_unstaked may be too low if initial stake is low. In that case,
345345
// do not restake.
346346
if tao_unstaked >= DefaultMinStake::<T>::get().saturating_add(fee) {
347+
// If the coldkey is not the owner, make the hotkey a delegate.
348+
if Self::get_owning_coldkey_for_hotkey(destination_hotkey) != *destination_coldkey {
349+
Self::maybe_become_delegate(destination_hotkey);
350+
}
351+
347352
Self::stake_into_subnet(
348353
destination_hotkey,
349354
destination_coldkey,

0 commit comments

Comments
 (0)