Skip to content

Commit 63ae469

Browse files
authored
Merge pull request #1332 from opentensor/feat/delegate-info-dtao
become delegate on every add_stake op
2 parents 0ac6947 + f9ad0b6 commit 63ae469

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
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,

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
228228
// `spec_version`, and `authoring_version` are the same between Wasm and native.
229229
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
230230
// the compatible custom types.
231-
spec_version: 242,
231+
spec_version: 243,
232232
impl_version: 1,
233233
apis: RUNTIME_API_VERSIONS,
234234
transaction_version: 1,

0 commit comments

Comments
 (0)