-
Notifications
You must be signed in to change notification settings - Fork 208
Reimplement StakeDelta #1600
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
base: devnet-ready
Are you sure you want to change the base?
Reimplement StakeDelta #1600
Conversation
pallets/subtensor/src/lib.rs
Outdated
} | ||
|
||
pub fn total(&self) -> i128 { | ||
self.coldkey_stake_deltas.values().sum() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider if it helps the runtime to update this on every add/remove that way calling total()
is faster.
Might be worse runtime depending on where we need to update it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data structure is not finalized (probably, we'll use StorageNMap). We'll reconsider the total
operation after that.
pub fn get_stake_delta_for_hotkey_on_subnet(hotkey: &T::AccountId, netuid: u16) -> u64 { | ||
let total_stake = StakeDeltaSinceLastEmissionDrain::<T>::get(netuid, hotkey).total(); | ||
|
||
total_stake.abs().saturated_into() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we know if the sum is positive or negative here?
I think we use it like total_stake.max(0)
, so we discard the negatives. But abs
isn't the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we remove the stake this epoch we will get a negative value. But we should mitigate the stake movement without taking the movement direction into account (add or remove), shouldn't we? We only dampen the movement. Please, correct me if I'm wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we return only an unsigned int so we can't tell if the delta was positive or negative.
We only truly care about positive deltas anyway (at least right now).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we return only an unsigned int so we can't tell if the delta was positive or negative.
Yes, because I was going to reduce any movement effect ("punish any stake movement for the epoch"). I chose "abs" because otherwise "remove_stake" will create a negative value and we'll increase the emissions, which doesn't seem to be a desired outcome.
We only truly care about positive deltas anyway (at least right now).
Ok. I will go with total_stake.max(0)
then. Thanks!
The last changes address PR comments, introduce additional places for stake delta effects, add tests, and simplify stake delta storage map by removing the coldkey from the storage. |
Description
This PR reimplements "stake delta" feature that was removed previously. It saves stake movement into the separate storage by hotkey, coldkey, and netuid. During the
epoch()
function execution stake delta is used as a "damper" to counter large stake movement effects on theepoch
.Related Issue(s)
Type of Change
Breaking Change
The PR changes the
epoch
calculations.Checklist
cargo fmt
andcargo clippy
to ensure my code is formatted and linted correctlyAdditional Notes
The original PR comes as a draft to gather feedback.