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

refactor: use minime and require limit when evaluating votes #72

Merged
merged 1 commit into from
Oct 4, 2023

Conversation

0x-r4bbit
Copy link
Member

@0x-r4bbit 0x-r4bbit commented Sep 27, 2023

This commit introduces a change that has been largely discussed in #65

Generally the idea is the following:

  • Prior to this commit, the amount of votes to be evaluated is unbounded, meaning we can potentially run out of gas when too many votes have to be evaluated in a single transaction.
  • To account for that, vote processing has to be batched based on a limit that is provided when the contract is called.
  • As a result of batching, finalization of votes can happen over multiple transactions which makes checking balances of voters tricky because evaluation happens at different blocks where balances might have changed.
  • That's why we're also introducing the use of MiniMeToken over standard ERC20 because it allows us to check balances of accounts at certain blocks.

This commit introduces the following changes in both VotingContract and FeaturedVotingContract:

  1. Evaluation of votes now always happens in three places: When a voting is initialized, when votes are casted and when a voting is being finalized.
  2. When initializing a voting or casting votes, the votes are evaluated against the current block, front-ends can therefore show a good estimation of the current vote state.
  3. Only the "new" votes are evaluated, which should equal to the amount of votes being sent.
  4. When finalizaing a vote, all votes are (re)evaluated against the block at which the finalization has started. This means with finalization, all votes are evaluated again to ensure they represent the latest state.

In terms of code this means:

_evaluateVotes() requires and additional limit, as a result of that finializeVoting() and finalizeVotingRoom() require a limit as well. castVotes() derives the limit from the vote amount that's being sent.

@vercel
Copy link

vercel bot commented Sep 27, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
community-dapp ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2023 9:14am

Copy link
Collaborator

@osmaczko osmaczko left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

@0x-r4bbit 0x-r4bbit force-pushed the refactor/remove-safemath branch 2 times, most recently from f172af7 to 9999b49 Compare October 4, 2023 09:06
Base automatically changed from refactor/remove-safemath to master October 4, 2023 09:10
This commit introduces a change that has been largely discussed in #65

Generally the idea is the following:

Prior to this commit, the amount of votes to be evaluated is unbounded, meaning we can potentially run out of gas when too many votes have to be evaluated in a single transaction.
To account for that, vote processing has to be batched based on a limit that is provided when the contract is called.
As a result of batching, finalization of votes can happen over multiple transactions which makes checking balances of voters tricky because evaluation happens at different blocks where balances might have changed.
That's why we're also introducing the use of MiniMeToken over standard ERC20 because it allows us to check balances of accounts at certain blocks.
This commit introduces the following changes in both VotingContract and FeaturedVotingContract:

Evaluation of votes now always happens in three places: When a voting is initialized, when votes are casted and when a voting is being finalized.
When initializing a voting or casting votes, the votes are evaluated against the current block, front-ends can therefore show a good estimation of the current vote state.
Only the "new" votes are evaluated, which should equal to the amount of votes being sent.
When finalizaing a vote, all votes are (re)evaluated against the block at which the finalization has started. This means with finalization, all votes are evaluated again to ensure they represent the latest state.
In terms of code this means:

_evaluateVotes() requires and additional limit, as a result of that finializeVoting() and finalizeVotingRoom() require a limit as well. castVotes() derives the limit from the vote amount that's being sent.
@0x-r4bbit 0x-r4bbit merged commit 7ac15c6 into master Oct 4, 2023
4 checks passed
@0x-r4bbit 0x-r4bbit deleted the refactor/limit-and-minime branch October 4, 2023 09:18
@osmaczko osmaczko linked an issue Oct 13, 2023 that may be closed by this pull request
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.

_evaluateVotes would run out of gas if there are too many voters
2 participants