Skip to content

Fix rounding error in Election.sol#2540

Merged
celo-ci-bot-user merged 7 commits intomasterfrom
asaj/rounding
Jan 28, 2020
Merged

Fix rounding error in Election.sol#2540
celo-ci-bot-user merged 7 commits intomasterfrom
asaj/rounding

Conversation

@asaj
Copy link
Copy Markdown
Contributor

@asaj asaj commented Jan 24, 2020

Description

This PR fixes a rounding error that prevents users from potentially revoking all of their active votes. In some cases, the user may try to revoke all of their active votes, but due to rounding errors getActiveVotesUnitsDelta returns one fewer than their total active vote units. To avoid this, a special case is added for when the value being revoked is exactly equal to the number of active votes for the user.

Note that this does not address all forms of rounding errors with respect to active votes. There still may be cases where, for example, the total number of active votes does not equal the sum of active votes over all (voter, group) pairs.

Tested

Reproduced the issue in unit tests by distributing rewards after making active votes. Confirmed that this fix solved it.

Other changes

None

Related issues

Backwards compatibility

Yes

@asaj asaj requested a review from m-chrzan as a code owner January 24, 2020 18:44
Copy link
Copy Markdown

@nategraf nategraf left a comment

Choose a reason for hiding this comment

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

One important change. Otherwise, looks good! 👍

Comment thread packages/protocol/test/governance/election.ts Outdated
@nategraf nategraf assigned asaj and unassigned nategraf Jan 24, 2020
Co-Authored-By: Victor "Nate" Graf <victor@celo.org>
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 24, 2020

Codecov Report

Merging #2540 into master will increase coverage by 0.32%.
The diff coverage is 49.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2540      +/-   ##
==========================================
+ Coverage   73.26%   73.58%   +0.32%     
==========================================
  Files         555      555              
  Lines       13793    13816      +23     
  Branches     1722     1425     -297     
==========================================
+ Hits        10105    10167      +62     
+ Misses       3407     3369      -38     
+ Partials      281      280       -1
Flag Coverage Δ
#mobile 74.1% <49.29%> (-0.04%) ⬇️
#web 72.86% <ø> (+0.83%) ⬆️
Impacted Files Coverage Δ
packages/mobile/test/schemas.ts 100% <ø> (ø) ⬆️
packages/mobile/src/geth/reducer.ts 73.33% <0%> (-7.92%) ⬇️
packages/mobile/src/geth/actions.ts 100% <100%> (ø) ⬆️
packages/mobile/src/redux/selectors.ts 78.57% <100%> (ø) ⬆️
packages/mobile/src/geth/selectors.ts 100% <100%> (ø)
packages/mobile/src/geth/saga.ts 24.13% <31.57%> (+0.88%) ⬆️
packages/mobile/src/web3/saga.ts 38.31% <39.28%> (+0.87%) ⬆️
packages/mobile/src/invite/JoinCelo.tsx 80.55% <50%> (-0.88%) ⬇️
packages/mobile/src/account/DataSaver.tsx 71.15% <60%> (-2.66%) ⬇️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c7495c6...ca0fefe. Read the comment docs.

@asaj asaj added the automerge label Jan 28, 2020
@celo-ci-bot-user celo-ci-bot-user merged commit 842d826 into master Jan 28, 2020
@celo-ci-bot-user celo-ci-bot-user deleted the asaj/rounding branch January 28, 2020 01:33
aaronmgdr added a commit that referenced this pull request Jan 28, 2020
* master:
  🧹Web cleanup (readme + static dir) (#2562)
  Add readable proposals to governance:view command (#2545)
  Add explicit gas to exchange transactions to prevent errors (#2552)
  Fix off-by-one error in attributing signatures to blocks in CLI (#2559)
  ✅ add test for phone Input component (#2554)
  Add Youtube to Footer +  (#2556)
  Fix rounding error in Election.sol (#2540)
  [Wallet] Bump @celo/client to 0.0.266 (#2551)
  [Wallet] E2E test improvements (#2542)
  Deployed integration (#2550)
  do not fetch affiliates (#2508)
  Added more CLI checks for registering validators and groups (#2491)
  Micro Improvement to web tests (#2527)
  [Wallet] Prompt users with connectivity issues to switch to forno (#2526)
  cli: Fix voter rewards presentation (#2543)
  [Wallet] Fix missing spanish translation  (#2539)
  Downtime slashing when epoch changes (#2436)
nategraf pushed a commit that referenced this pull request Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rounding error prevents revoking active votes for group

4 participants