Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,16 @@ impl<T: Config> Pallet<T> {
);
continue;
}

// Increase stake for miner.
let destination: T::AccountId;
let owner: T::AccountId = Owner::<T>::get(&hotkey);
if AutoStakeDestination::<T>::contains_key(&owner) {
destination = AutoStakeDestination::<T>::get(&owner);
} else {
destination = hotkey.clone();
}
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we emit an event here? This makes it way harder to account mining emissions vs staking emissions

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't emit events in such cases in this file.

&hotkey.clone(),
&Owner::<T>::get(hotkey.clone()),
&destination,
&owner,
netuid,
incentive,
);
Expand Down
5 changes: 3 additions & 2 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,8 +1081,9 @@ pub mod pallet {
pub type StakingHotkeys<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, Vec<T::AccountId>, ValueQuery>;
#[pallet::storage] // --- MAP ( cold ) --> Vec<hot> | Returns the vector of hotkeys controlled by this coldkey.
pub type OwnedHotkeys<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, Vec<T::AccountId>, ValueQuery>;
pub type OwnedHotkeys<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId, Vec<T::AccountId>, ValueQuery>;
#[pallet::storage] // --- MAP ( cold ) --> hot | Returns the hotkey a coldkey will autostake to with mining rewards.
pub type AutoStakeDestination<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId, T::AccountId, ValueQuery>;

#[pallet::storage] // --- DMAP ( cold ) --> (block_expected, new_coldkey) | Maps coldkey to the block to swap at and new coldkey.
pub type ColdkeySwapScheduled<T: Config> = StorageMap<
Expand Down
16 changes: 16 additions & 0 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2219,5 +2219,21 @@ mod dispatches {
commit_reveal_version,
)
}

#[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))]
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::<T>::insert( coldkey, hotkey.clone() );
Ok(())
}
}
}
4 changes: 4 additions & 0 deletions pallets/subtensor/src/swap/swap_coldkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ impl<T: Config> Pallet<T> {
weight.saturating_accrue(T::DbWeight::get().reads_writes(2, 2));
}

let old_auto_stake_hotkey: T::AccountId = AutoStakeDestination::<T>::get(old_coldkey);
AutoStakeDestination::<T>::remove(old_coldkey);
AutoStakeDestination::<T>::insert(new_coldkey, old_auto_stake_hotkey);

// 4. Swap TotalColdkeyAlpha (DEPRECATED)
// for netuid in Self::get_all_subnet_netuids() {
// let old_alpha_stake: u64 = TotalColdkeyAlpha::<T>::get(old_coldkey, netuid);
Expand Down
Loading