Skip to content

Commit

Permalink
add cleared amount in remove_stake
Browse files Browse the repository at this point in the history
  • Loading branch information
cuteolaf committed Sep 11, 2024
1 parent adad4fd commit 2462b53
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pallets/subtensor/src/staking/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl<T: Config> Pallet<T> {
hotkey: &T::AccountId,
coldkey: &T::AccountId,
stake: u64,
) {
) -> u64 {
// Verify if the account is a nominator account by checking ownership of the hotkey by the coldkey.
if !Self::coldkey_owns_hotkey(coldkey, hotkey) {
// If the stake is below the minimum required, it's considered a small nomination and needs to be cleared.
Expand All @@ -315,8 +315,10 @@ impl<T: Config> Pallet<T> {
let cleared_stake = Self::empty_stake_on_coldkey_hotkey_account(coldkey, hotkey);
// Add the stake to the coldkey account.
Self::add_balance_to_coldkey_account(coldkey, cleared_stake);
return cleared_stake;
}
}
0
}

/// Clears small nominations for all accounts.
Expand Down
10 changes: 6 additions & 4 deletions pallets/subtensor/src/staking/remove_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ impl<T: Config> Pallet<T> {
// This only applies to nominator stakes.
// If the coldkey does not own the hotkey, it's a nominator stake.
let new_stake = Self::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey);
Self::clear_small_nomination_if_required(&hotkey, &coldkey, new_stake);
let cleared_stake = Self::clear_small_nomination_if_required(&hotkey, &coldkey, new_stake);
let stake_removed = stake_to_be_removed.saturating_add(cleared_stake);

// Set last block for rate limiting
let block: u64 = Self::get_current_block_as_u64();
Expand All @@ -97,11 +98,12 @@ impl<T: Config> Pallet<T> {
block,
);
log::debug!(
"StakeRemoved( hotkey:{:?}, stake_to_be_removed:{:?} )",
"StakeRemoved( hotkey:{:?}, stake_to_be_removed:{:?} stake_removed:{:?} )",
hotkey,
stake_to_be_removed
stake_to_be_removed,
stake_removed
);
Self::deposit_event(Event::StakeRemoved(hotkey, stake_to_be_removed));
Self::deposit_event(Event::StakeRemoved(hotkey, stake_removed));

// Done and ok.
Ok(())
Expand Down

0 comments on commit 2462b53

Please sign in to comment.