Skip to content
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

Account for Rounding Errors in Distribution Calculations #4094

Merged
merged 4 commits into from
Apr 10, 2019

Conversation

rigelrozanski
Copy link
Contributor

@rigelrozanski rigelrozanski commented Apr 10, 2019

closes: #4088


  • Targeted PR against correct branch (see CONTRIBUTING.md)

  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.

  • Wrote tests

  • Updated relevant documentation (docs/)

  • Added a relevant changelog entry: sdkch add [section] [stanza] [message]

  • rereviewed Files changed in the github PR explorer


For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@alexanderbez alexanderbez changed the title release 0.34 bugfix patch Account for Rounding Errors in Distribution Calculations Apr 10, 2019
@codecov
Copy link

codecov bot commented Apr 10, 2019

Codecov Report

Merging #4094 into release/v0.34.0 will decrease coverage by 0.03%.
The diff coverage is 9.09%.

@@                 Coverage Diff                 @@
##           release/v0.34.0    #4094      +/-   ##
===================================================
- Coverage            60.02%   59.99%   -0.04%     
===================================================
  Files                  212      212              
  Lines                15121    15129       +8     
===================================================
  Hits                  9077     9077              
- Misses                5421     5429       +8     
  Partials               623      623

@alexanderbez
Copy link
Contributor

Passes test_sim_gaia_multi_seed. I'm running the same seeds against 1k blocks. If that passes, I'll be reasonably confident this solution is acceptable.

Copy link
Member

@jackzampolin jackzampolin left a comment

Choose a reason for hiding this comment

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

Sim 2 passes for me on this branch

@alexanderbez
Copy link
Contributor

All seeds passed!

@alexanderbez alexanderbez merged commit 38e3fdf into release/v0.34.0 Apr 10, 2019
@alexanderbez alexanderbez deleted the rigel/release034-bugfix branch April 10, 2019 22:53
currentStake := val.TokensFromShares(del.GetShares())
if stake.GT(currentStake) {
panic(fmt.Sprintf("calculated final stake for delegator %s greater than current stake: %s, %s",
del.GetDelegatorAddr(), stake, currentStake))
// account for rounding errors due to stake being multiplied by slash fractions
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would these rounding errors lead to stake being too high, if we round up the slash fractions?

updatedFraction := sdk.OneDec().Sub(currentMultiplicand.Mul(newMultiplicand))

// using MulTruncate here conservatively increases the slashing amount
updatedFraction := sdk.OneDec().Sub(currentMultiplicand.MulTruncate(newMultiplicand))
Copy link
Contributor

Choose a reason for hiding this comment

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

++, this looks fine to me - this should lead to more slashing, see comment above

@rigelrozanski rigelrozanski mentioned this pull request May 21, 2019
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/distribution distribution module related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants