Skip to content

Introduce stake lock after add_stake operation. #1666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: devnet-ready
Choose a base branch
from

Conversation

shamil-gadelshin
Copy link
Collaborator

Description

This PR addresses the stake manipulation problem. It introduces a stake lock after each stake deposit operation (like add_stake or add_stake_limit). The lock is the block number after which stake removal is allowed. It calculates as "current_block + subnet tempo".

It relates to both MEV and "stake delta" problems.

The PR removes the commented code related to #1641 in the first commit.

Related Issue(s)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Breaking Change

Code that removes the stake immediately will stop working.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run cargo fmt and cargo clippy to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@shamil-gadelshin shamil-gadelshin added breaking-change This PR introduces a noteworthy breaking change skip-cargo-audit This PR fails cargo audit but needs to be merged anyway labels May 21, 2025
Copy link

@opentensor/cerebrum / @opentensor/gyrus / @opentensor/cortex breaking change detected! Please prepare accordingly!

@shamil-gadelshin
Copy link
Collaborator Author

cc @ppolewicz

return Ok(());
}

let stake_lock = StakeLocks::<T>::get(hotkey, netuid);
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest that we remove the key here if lock is expired.

@@ -1176,6 +1094,19 @@ pub mod pallet {
pub type TokenSymbol<T: Config> =
StorageMap<_, Identity, u16, Vec<u8>, ValueQuery, DefaultUnicodeVecU8<T>>;

#[pallet::storage]
/// DMAP ( hot, netuid ) --> lock until block number | Returns the block number of the stake lock
pub type StakeLocks<T: Config> = StorageDoubleMap<
Copy link
Contributor

Choose a reason for hiding this comment

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

The stake locks should be by hotkey, coldkey, and netuid. Otherwise, we will be locking all nominators (all coldkeys) as soon as one coldkey stakes to this hotkey and nobody will be able to unstake until the next epoch.

Also, what happens if a coldkey has a 1000 TAO stake with expired lock and adds 1 TAO more? Should we keep them from unlocking only 1 TAO or the whole 1001 TAO amount?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change This PR introduces a noteworthy breaking change skip-cargo-audit This PR fails cargo audit but needs to be merged anyway
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants