-
Notifications
You must be signed in to change notification settings - Fork 247
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
Minor fix and refactoring to staking #3279
Conversation
…r to the treasury Signed-off-by: linning <linningde25@gmail.com>
This field is used to temporarily hold the reward and then move to the current_total_stake, this commit directly move the reward to current_total_stake Signed-off-by: linning <linningde25@gmail.com>
Signed-off-by: linning <linningde25@gmail.com>
By using idiomatic Entry and remove the useless weight_balance_cache as there is no repeat opertator in the operator_weights BTreeMap Signed-off-by: linning <linningde25@gmail.com>
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.
Looks good!
@@ -141,6 +150,10 @@ pub(crate) fn operator_take_reward_tax_and_stake<T: Config>( | |||
})?; | |||
} | |||
|
|||
if !to_treasury.is_zero() { | |||
mint_into_treasury::<T>(to_treasury).ok_or(TransitionError::MintBalance)?; |
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.
can't we just make this function handle the edge case instead. Its easy to miss otherwise
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.
Done here #3285
let share_price = SharePrice::new::<T>(total_shares, total_stake); | ||
|
||
// calculate and subtract total withdrew shares from previous epoch | ||
let (total_stake, total_shares) = if !operator.withdrawals_in_epoch.is_zero() { |
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.
I remeber @nazar-pc mentioning about preferring immutable vars over mutable one. easy to reason with IMHO
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.
I like immutable vars most of the time, but I don't think it is suitable for this particular case.
The first commit fixes a minor issue by moving the epoch reward of the unlocked operator to the treasury instead of dropping silently.
The rest of the commits are refactoring to remove unnecessary logic and cleanup the code.
Code contributor checklist: