This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Several tweaks needed for Governance 2.0 #11124
Merged
Merged
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
2c7960e
Add stepped curve for referenda
gavofyork f756d98
Treasury SpendOrigin
gavofyork de49a27
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork 788a85f
Add tests
gavofyork 9b967e7
Better Origin Or-gating
gavofyork b84e299
Reciprocal curve
gavofyork c8e8a5c
Tests for reciprical and rounding in PerThings
gavofyork a1a4619
Tweaks and new quad curve
gavofyork 5710058
Const derivation of reciprocal curve parameters
gavofyork 6bde6aa
Remove some unneeded code
gavofyork abb8a8f
Actually useful linear curve
gavofyork 9cecb07
Fixes
gavofyork 31da176
Provisional curves
gavofyork e6c0f02
Rejig 'turnout' as 'support'
gavofyork 7aeab6c
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork ed050ca
Use TypedGet
gavofyork 386977a
Fixes
gavofyork 2cd8a46
Enable curve's ceil to be configured
gavofyork cb567e5
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork 3f424ae
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork 485fd23
Formatting
gavofyork f5d6f45
Fixes
gavofyork 7ce42e8
Fixes
gavofyork b25bc5f
Fixes
gavofyork 45208e0
Remove EnsureOneOf
gavofyork 35764fb
Fixes
gavofyork 3b53be6
Fixes
gavofyork cbadc3e
Fixes
gavofyork 940f4b3
Fixes
gavofyork a091e9d
Formatting
gavofyork 73bbf7c
Fixes
gavofyork ef59083
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork a291d47
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork 8019e33
Update frame/support/src/traits/dispatch.rs
gavofyork 7596264
Grumbles
gavofyork 2b4a20a
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork 40ca11e
Formatting
gavofyork 18c6438
Fixes
gavofyork ed23dc4
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork d04ebd0
APIs of VoteTally should include class
gavofyork 91b1094
Fixes
gavofyork 471b43a
Fix overlay prefix removal result
gavofyork 92cd9a3
Second part of the overlay prefix removal fix.
gavofyork 0239621
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork d504d70
Formatting
gavofyork cace119
Fixes
gavofyork e988654
Add some tests and make clear rounding algo
gavofyork 38f14fd
Fixes
gavofyork 064de3d
Formatting
gavofyork 4f456f8
Revert questionable fix
gavofyork 697bff5
Introduce test for kill_prefix
gavofyork d111c87
Fixes
gavofyork 244c5f4
Formatting
gavofyork 656baff
Fixes
gavofyork bcce142
Fix possible overflow
gavofyork af7b81e
Docs
gavofyork ad9a732
Add benchmark test
gavofyork fd5e03a
Formatting
gavofyork 18c72d3
Merge remote-tracking branch 'origin/master' into gav-gov2-tweaks
gavofyork db730db
Update frame/referenda/src/types.rs
gavofyork c251948
Docs
gavofyork 4088a11
Merge branch 'gav-gov2-tweaks' of github.com:paritytech/substrate int…
gavofyork 9b1bd8b
Fixes
gavofyork d2730c2
Use latest API in tests
gavofyork 5f7b13e
Formatting
gavofyork b58dbbc
Whitespace
gavofyork e1b00d8
Use latest API in tests
gavofyork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Rejig 'turnout' as 'support'
- Loading branch information
commit e6c0f02a95430a429422fadd42290a5256c34480
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,8 +54,8 @@ pub struct Tally< | |
| pub ayes: Votes, | ||
| /// The number of nay votes, expressed in terms of post-conviction lock-vote. | ||
| pub nays: Votes, | ||
| /// The amount of funds currently expressing its opinion. Pre-conviction. | ||
| pub turnout: Votes, | ||
| /// The basic number of aye votes, expressed pre-conviction. | ||
| pub support: Votes, | ||
| /// Dummy. | ||
| dummy: PhantomData<Total>, | ||
| } | ||
|
|
@@ -77,8 +77,8 @@ impl< | |
| self.ayes | ||
| } | ||
|
|
||
| fn turnout(&self) -> Perbill { | ||
| Perbill::from_rational(self.turnout, Total::get()) | ||
| fn support(&self) -> Perbill { | ||
| Perbill::from_rational(self.support, Total::get()) | ||
| } | ||
|
|
||
| fn approval(&self) -> Perbill { | ||
|
|
@@ -87,14 +87,15 @@ impl< | |
|
|
||
| #[cfg(feature = "runtime-benchmarks")] | ||
| fn unanimity() -> Self { | ||
| Self { ayes: Total::get(), nays: Zero::zero(), turnout: Total::get(), dummy: PhantomData } | ||
| Self { ayes: Total::get(), nays: Zero::zero(), support: Total::get(), dummy: PhantomData } | ||
| } | ||
|
|
||
| #[cfg(feature = "runtime-benchmarks")] | ||
| fn from_requirements(turnout: Perbill, approval: Perbill) -> Self { | ||
| let turnout = turnout.mul_ceil(Total::get()); | ||
| let ayes = approval.mul_ceil(turnout); | ||
| Self { ayes, nays: turnout - ayes, turnout, dummy: PhantomData } | ||
| fn from_requirements(support: Perbill, approval: Perbill) -> Self { | ||
| let support = support.mul_ceil(Total::get()); | ||
| let ayes = approval.mul_ceil(support); | ||
| // TODO | ||
| Self { ayes, nays: support - ayes, support, dummy: PhantomData } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -117,30 +118,37 @@ impl< | |
| Self { | ||
| ayes: if vote.aye { votes } else { Zero::zero() }, | ||
| nays: if vote.aye { Zero::zero() } else { votes }, | ||
| turnout: capital, | ||
| support: capital, | ||
| dummy: PhantomData, | ||
| } | ||
| } | ||
|
|
||
| pub fn from_parts(ayes: Votes, nays: Votes, turnout: Votes) -> Self { | ||
| Self { ayes, nays, turnout, dummy: PhantomData } | ||
| pub fn from_parts(ayes_with_conviction: Votes, nays_with_conviction: Votes, ayes: Votes) -> Self { | ||
| Self { | ||
| ayes: ayes_with_conviction, | ||
| nays: nays_with_conviction, | ||
| support: ayes, | ||
| dummy: PhantomData, | ||
| } | ||
| } | ||
|
|
||
| /// Add an account's vote into the tally. | ||
| pub fn add(&mut self, vote: AccountVote<Votes>) -> Option<()> { | ||
| match vote { | ||
| AccountVote::Standard { vote, balance } => { | ||
| let Delegations { votes, capital } = vote.conviction.votes(balance); | ||
| self.turnout = self.turnout.checked_add(&capital)?; | ||
| match vote.aye { | ||
| true => self.ayes = self.ayes.checked_add(&votes)?, | ||
| true => { | ||
| self.support = self.support.checked_add(&capital)?; | ||
| self.ayes = self.ayes.checked_add(&votes)? | ||
| }, | ||
| false => self.nays = self.nays.checked_add(&votes)?, | ||
| } | ||
| }, | ||
| AccountVote::Split { aye, nay } => { | ||
| let aye = Conviction::None.votes(aye); | ||
| let nay = Conviction::None.votes(nay); | ||
| self.turnout = self.turnout.checked_add(&aye.capital)?.checked_add(&nay.capital)?; | ||
| self.support = self.support.checked_add(&aye.capital)?; | ||
| self.ayes = self.ayes.checked_add(&aye.votes)?; | ||
| self.nays = self.nays.checked_add(&nay.votes)?; | ||
| }, | ||
|
|
@@ -153,16 +161,19 @@ impl< | |
| match vote { | ||
| AccountVote::Standard { vote, balance } => { | ||
| let Delegations { votes, capital } = vote.conviction.votes(balance); | ||
| self.turnout = self.turnout.checked_sub(&capital)?; | ||
| match vote.aye { | ||
| true => self.ayes = self.ayes.checked_sub(&votes)?, | ||
| true => { | ||
| self.support = self.support.checked_sub(&capital)?; | ||
| self.ayes = self.ayes.checked_sub(&votes)? | ||
| }, | ||
| false => self.nays = self.nays.checked_sub(&votes)?, | ||
| } | ||
| }, | ||
| // TODO: abstain. | ||
gavofyork marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| AccountVote::Split { aye, nay } => { | ||
| let aye = Conviction::None.votes(aye); | ||
| let nay = Conviction::None.votes(nay); | ||
| self.turnout = self.turnout.checked_sub(&aye.capital)?.checked_sub(&nay.capital)?; | ||
| self.support = self.support.checked_sub(&aye.capital)?; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a change of definition, not a bug right?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. turnout implies all votes, support implies only aye votes?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. From the PR's summary:
|
||
| self.ayes = self.ayes.checked_sub(&aye.votes)?; | ||
| self.nays = self.nays.checked_sub(&nay.votes)?; | ||
| }, | ||
|
|
@@ -172,18 +183,22 @@ impl< | |
|
|
||
| /// Increment some amount of votes. | ||
| pub fn increase(&mut self, approve: bool, delegations: Delegations<Votes>) { | ||
| self.turnout = self.turnout.saturating_add(delegations.capital); | ||
| match approve { | ||
| true => self.ayes = self.ayes.saturating_add(delegations.votes), | ||
| true => { | ||
| self.support = self.support.saturating_add(delegations.capital); | ||
| self.ayes = self.ayes.saturating_add(delegations.votes); | ||
| }, | ||
| false => self.nays = self.nays.saturating_add(delegations.votes), | ||
| } | ||
| } | ||
|
|
||
| /// Decrement some amount of votes. | ||
| pub fn reduce(&mut self, approve: bool, delegations: Delegations<Votes>) { | ||
| self.turnout = self.turnout.saturating_sub(delegations.capital); | ||
| match approve { | ||
| true => self.ayes = self.ayes.saturating_sub(delegations.votes), | ||
| true => { | ||
| self.support = self.support.saturating_sub(delegations.capital); | ||
| self.ayes = self.ayes.saturating_sub(delegations.votes); | ||
| }, | ||
| false => self.nays = self.nays.saturating_sub(delegations.votes), | ||
| } | ||
| } | ||
|
|
@@ -196,7 +211,7 @@ impl< | |
| pub struct Delegations<Balance> { | ||
| /// The number of votes (this is post-conviction). | ||
| pub votes: Balance, | ||
| /// The amount of raw capital, used for the turnout. | ||
| /// The amount of raw capital, used for the support. | ||
| pub capital: Balance, | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.