-
Notifications
You must be signed in to change notification settings - Fork 955
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
Governance Abstain
vote
#2128
Governance Abstain
vote
#2128
Conversation
Abstain
vote and adjusts tallyAbstain
vote
core/src/ledger/governance/utils.rs
Outdated
let at_least_two_thirds_voted = self.total_yay_power | ||
+ self.total_nay_power | ||
+ self.total_abstain_power | ||
>= self.total_voting_power / 3 * 2; |
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.
>= self.total_voting_power / 3 * 2; | |
>= self.total_voting_power * 2 / 3; |
in general, we should practice multiply-then-divide
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 think the operators precedence in Rust already evaluates multiplications before divisions, but I can change it. Do you think at this point it's better to split the fraction among the two sides of the inequality an be (yay + nay + abstain) * 3 >= total * 2
?
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.
how you have it is fine, I just prefer * 3 / 2
. admittedly this is somewhat of an aesthetic choice
core/src/ledger/governance/utils.rs
Outdated
>= self.total_voting_power / 3 * 2; | ||
|
||
let at_least_two_thirds_nay = self.total_nay_power | ||
>= (self.total_nay_power + self.total_yay_power) / 3 * 2; |
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.
>= (self.total_nay_power + self.total_yay_power) / 3 * 2; | |
>= (self.total_nay_power + self.total_yay_power) * 2 / 3; |
core/src/ledger/governance/utils.rs
Outdated
(TallyVote::Offline(vote), TallyVote::Offline(other_vote)) => { | ||
vote.is_same_side(other_vote) | ||
} | ||
_ => false, |
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.
when would this case happen? shouldn't this be impossible?
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.
Never, it's just the the method is implemented on the TallyVote
enum which contains two variants, one for the on-chain votes and the other one for off-chain votes and we still need the pattern matching to be exhaustive, so we need to cover also the case in which the two instances are actually two different variants. We can return an error instead of false
to make it more clear
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.
wherever a case isn't expected to happen, we should return an error
core/src/ledger/governance/utils.rs
Outdated
nay_voting_power += vote_power; | ||
} else { |
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.
vote.is_abstain()
would be more defensive, in case we add another voting option in the future
core/src/ledger/governance/utils.rs
Outdated
} else { | ||
if validator_vote.is_nay() { | ||
nay_voting_power -= voting_power; | ||
} else { |
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.
ditto
core/src/ledger/governance/utils.rs
Outdated
yay_voting_power -= voting_power; | ||
if validator_vote.is_yay() { | ||
yay_voting_power -= voting_power; | ||
} else { |
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.
ditto
core/src/ledger/governance/utils.rs
Outdated
abstain_voting_power += voting_power; | ||
if validator_vote.is_yay() { | ||
yay_voting_power -= voting_power; | ||
} else { |
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.
ditto
core/src/ledger/governance/utils.rs
Outdated
nay_voting_power += voting_power; | ||
} else { |
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.
ditto
@@ -2095,7 +2095,7 @@ fn proposal_submission() -> Result<()> { | |||
let mut client = run!(test, Bin::Client, query_proposal, Some(15))?; | |||
client.exp_string("Proposal Id: 0")?; | |||
client.exp_string( | |||
"passed with 120900.000000 yay votes and 0.000000 nay votes (0.%)", | |||
"passed with 120000.000000 yay votes and 900.000000 nay votes (0.%)", |
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.
why did this change? 🤔
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.
In test we submit two votes, a yay
with the validator (120000 voting power) and a nay
with a delegator (900 voting power) and previously we were not seeing the nay votes before because of a bug in the is_same_side
function. I've tagged you at the wrong line
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.
ah
/// Rappresent an invalid proposal vote | ||
/// Represent an abstain proposal vote | ||
Abstain, | ||
/// Represent an invalid proposal vote | ||
Invalid, |
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.
when does this case happen?
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.
Actually nowhere, I'm removing it thanks!
let both_yay = self.is_yay() && other.is_yay(); | ||
let both_nay = !self.is_yay() && !other.is_yay(); | ||
|
||
both_yay || !both_nay |
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.
@cwgoes here's the bug for the wrong e2e tally, it should have been both_yay || both_nay
c79675f
to
20dc3b3
Compare
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.
lgtm
Describe your changes
Closes #2090.
Implements the
Abstain
governance vote. Also reviews the tally process for the different proposal types.Indicate on which release or other PRs this topic is based on
Commit 3a0ecd8 on
base
(v0.25.0)Checklist before merging to
draft