-
Notifications
You must be signed in to change notification settings - Fork 45
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
Fix/staking bug #1162
Merged
Merged
Fix/staking bug #1162
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
✅ Deploy Preview for kleros-v2 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for kleros-v2-contracts ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
jaybuidl
force-pushed
the
fix/staking-bug
branch
from
September 6, 2023 08:39
6460b34
to
5ea062e
Compare
jaybuidl
force-pushed
the
fix/staking-bug
branch
from
September 9, 2023 06:53
a861cc3
to
7d90db7
Compare
Code Climate has analyzed commit 7d90db7 and detected 4 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
jaybuidl
approved these changes
Sep 9, 2023
Kudos, SonarCloud Quality Gate passed! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Compatibility: ABI change 🗯
Smart contract ABI is changing.
Package: Contracts
Court smart contracts
Type: Bug 🐛
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
List of changes made in this PR:
Previously drawing iterations were capped with required number of jurors and the argument
_iterations
didn't really do anything. It makes sense in the old version where we don't have post-draw check and each iteration will draw someone anyway. But in this version we skip jurors, so I decided to remove this cap and use an iteration number (which is ever-increasing) as a nonce for obtaining a drawing number, thus each time you call draw() function it'll draw different jurors in the process, unlike before, since each call will use different nonces.Staking logic now considers the implicit staking in parent courts, thus insolvency is now checked not by the stake in a particular court but by the total number of tokens deposited by the juror. If this number is lower than the total number of locked tokens the juror won't pass the post-draw check.
Also penalty now doesn't update the stake, instead it simply removes tokens from total juror's balance, which is actually closer to V1 logic-wise.
So in short, we now have 3 closely related, but different entities:
1. totalStaked, which reflects the number of tokens deposited by the juror. If the juror is fully unstaked, or for some reason has
totalLocked > totalStaked
, then locked tokens will reflect it instead2. stakedPnkByCourt - number of tokens that were explicitely staked in a particular court. We need it as a duplication of sortition stakes, in case the sortition module is replaced
3. Sortition Stakes - includes all, explicit stakes and implicit stakes in parent courts.
Locked tokens are now taken into account during staking. E.g. if a juror has 0 tokens staked and 150 locked then to stake 1000 he'll only need to transfer 850 tokens. It only applies when total locked amount is higher than total staked
Staking 0 isn't allowed if
currentStake == 0
to avoid some unexpected behaviour