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
Merged
Changes from 1 commit
Commits
Show all changes
93 commits
Select commit
Hold shift + click to select a range
acab9a3
Block builder (substrate)
gavofyork 9acd3f9
Fix wasm build
gavofyork ca5900f
Bulid on any block
gavofyork d11cfe1
Test for block builder.
gavofyork b973ccc
Block import tests for client.
gavofyork ec61865
Tidy ups
gavofyork cec06a7
Repotted client
gavofyork 38cd36a
Avoid pointless work
gavofyork 8b7abca
All backend stuff now manages optional storage.
gavofyork 9dba812
Native runtime-io now supports empty storage items.
gavofyork 0f591c6
Finish up the API transition.
gavofyork 79c6b4c
Merge branch 'master' into gav-optional-storage
gavofyork a802b7e
Build fix.
gavofyork 3928c1c
Fix tests.
gavofyork 002ab5f
Merge branch 'master' into gav-optional-storage
gavofyork 61db63f
Remerge in changes to client.
gavofyork 5d1a3a7
Final fixes.
gavofyork 212d370
Unrevert typos
gavofyork 780e549
Remove accidentally committed change
gavofyork e552875
Bring back zero copy
gavofyork 0a08196
Fix merge.
gavofyork e25960b
Refactor out some duped code
gavofyork 9042880
Merge branch 'master' into gav-demo
gavofyork af3a413
Add docs.
gavofyork 2b13856
More mssing doc.
gavofyork 08060a6
Fix up wasm build.
gavofyork 036142c
Introduce substrate-demo
gavofyork 38bf4d7
Remove bad files.
gavofyork a2fb006
Tidy up unneeded code.
gavofyork 775cb5a
Add needed file.
gavofyork 0b83481
Initial staging ground for interior wasm smart-contracts.
gavofyork 3413d14
More work on Ext & calls.
gavofyork 0a82fd2
Fix logic
gavofyork b098eb2
comment
gavofyork 73c4141
Remove unneeded call depth.
gavofyork 9ef9c01
Use BTreeMap rather than HashMap in demo runtime.
gavofyork 59c371f
Initial draft of stakeholder democracy.
gavofyork 696f22a
Tests for referenda.
gavofyork 98b74bc
Design of the approval voting module for council election.
gavofyork 87bc061
Implement next_tally.
gavofyork f5ad966
More work on governance.
gavofyork afcff76
Submit candidacy.
gavofyork 264384d
presenting a winner.
gavofyork 822a5dc
Final bit of core logic for the council.
gavofyork 9a1d638
remove inactive voter.
gavofyork 4618367
Space out votes by a minimum period.
gavofyork 9af17a5
Candidacy tests
gavofyork 511775c
More candidate tests.
gavofyork 2eeb88e
More tests for voting.
gavofyork 5ea3f2b
Test for tally
gavofyork bcb2b39
More tests, for runners-up.
gavofyork 3541d4e
test: second tally uses runners-up.
gavofyork a0c405f
Tests: various error cases with present.
gavofyork 899e26e
tests: presenting losers
gavofyork 4777806
cleanups.
gavofyork f0d5f53
Merge branch 'master' into gav-demo
gavofyork f276b4d
tests: Retract inactive voter
gavofyork 05b6a8d
Additional docs & test.
gavofyork 2bf2799
Add one vote worth of time for voters to unregister before they becom…
gavofyork 999c082
Avoid allowing same accounts to be doubly-elected.
gavofyork 0c9265f
test: against double presentations.
gavofyork 3c911cd
Update docs
gavofyork 002ddab
Simultaneous referendums and multiple voting variants.
gavofyork b8cc3a1
Introduce logic for deposits.
gavofyork 9aeb95c
Deposits, not fees.
gavofyork fffbadd
cleanups.
gavofyork 6dfe148
Introduce minimum deposit
gavofyork 907fac7
Tests for public referenda.
gavofyork 0bbd6b3
Tests for public referenda.
gavofyork 8df2342
remove string constants <-- @rphmeier
gavofyork c73e3f9
Ensure council always sorted by expiry.
gavofyork 0bb5791
Initial council vote logic.
gavofyork f780504
More tests for council voting.
gavofyork 25b8c20
council vetoing & tests.
gavofyork 7ef0b17
Another few tests for council_vote.
gavofyork 8b37acf
Final tests.
gavofyork bb7f398
Move council over to new Keyring API.
gavofyork 8be2cc8
Move democracy module over no new Keyring API
gavofyork 7e6e40d
Introduce stake reservation; make panicking tests better.
gavofyork 7e8e404
Genesis map.
gavofyork 2d66a63
Use a struct!
gavofyork 22d4829
Tests for staking reserved balances & slashing.
gavofyork 5450807
Public function dispatching.
gavofyork e09096c
Safe panic.
gavofyork 128fa23
Fix tests and avoid use of old keys.
gavofyork d347030
Fix grumbles.
gavofyork b6897d5
Minor typos.
gavofyork 6029553
Cleanups and introduce all dispatchable endpoints.
gavofyork f3439c9
Additional function ids for derivation.
gavofyork 23b030a
Formatting.
gavofyork 016a7b6
Remove stray printlns.
gavofyork 0f81021
Merge branch 'master' into gav-demo
gavofyork 5c9a40a
Update wasm.
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
Initial council vote logic.
- Loading branch information
commit 0bb57916a887f4f47d1064f3ca50ecac206643ed
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
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 |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| // Copyright 2017 Parity Technologies (UK) Ltd. | ||
| // This file is part of Substrate Demo. | ||
|
|
||
| // Substrate Demo is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Substrate Demo is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Substrate Demo. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //! Council voting system. | ||
|
|
||
| use rstd::prelude::*; | ||
| use codec::{KeyedVec, Slicable, Input, NonTrivialSlicable}; | ||
| use runtime_support::Hashable; | ||
| use runtime_support::storage; | ||
| use demo_primitives::{Proposal, AccountId, Hash, BlockNumber}; | ||
| use runtime::{system, democracy, council}; | ||
| use runtime::staking::Balance; | ||
|
|
||
| type ProposalHash = [u8; 32]; | ||
|
|
||
| pub const COOLOFF_PERIOD: &[u8] = b"cov:cooloff"; // BlockNumber | ||
| pub const VOTING_PERIOD: &[u8] = b"cov:period"; // BlockNumber | ||
|
|
||
| pub const PROPOSALS: &[u8] = b"cov:prs"; // Vec<(expiry: BlockNumber, ProposalHash)> ordered by expiry. | ||
| pub const PROPOSAL_OF: &[u8] = b"cov:pro"; // ProposalHash -> Proposal | ||
| pub const PROPOSAL_VOTERS: &[u8] = b"cov:voters:"; // ProposalHash -> Vec<AccountId> | ||
| pub const COUNCIL_VOTE_OF: &[u8] = b"cov:vote:"; // (ProposalHash, AccountId) -> bool | ||
| pub const VETOED_PROPOSAL: &[u8] = b"cov:veto:"; // ProposalHash -> (BlockNumber, Vec<AccountId>) | ||
|
|
||
| pub fn cooloff_period() -> BlockNumber { | ||
| storage::get(COOLOFF_PERIOD).expect("all parameters must be defined") | ||
| } | ||
|
|
||
| pub fn voting_period() -> BlockNumber { | ||
| storage::get(VOTING_PERIOD).expect("all parameters must be defined") | ||
| } | ||
|
|
||
| pub fn proposals() -> Vec<(BlockNumber, ProposalHash)> { | ||
| storage::get_or_default(PROPOSALS) | ||
| } | ||
|
|
||
| pub fn was_vetoed(proposal: &ProposalHash) -> bool { | ||
| storage::exists(&proposal.to_keyed_vec(VETOED_PROPOSAL)) | ||
| } | ||
|
|
||
| pub fn will_still_be_councillor_at(who: &AccountId, n: BlockNumber) -> bool { | ||
| council::active_council().iter() | ||
| .find(|&&(ref a, _)| a == who) | ||
| .map(|&(_, expires)| expires > n) | ||
| .unwrap_or(false) | ||
| } | ||
|
|
||
| pub fn vote_of(who: &AccountId, proposal: &ProposalHash) -> Option<bool> { | ||
| storage::get(&(*who, *proposal).to_keyed_vec(COUNCIL_VOTE_OF)) | ||
| } | ||
|
|
||
| pub fn take_vote_of(who: &AccountId, proposal: &ProposalHash) -> Option<bool> { | ||
| storage::get(&(*who, *proposal).to_keyed_vec(COUNCIL_VOTE_OF)) | ||
| } | ||
|
|
||
| pub fn tally(proposal_hash: &ProposalHash) -> (u32, u32, u32) { | ||
| generic_tally(proposal_hash, vote_of) | ||
| } | ||
|
|
||
| fn take_tally(proposal_hash: &ProposalHash) -> (u32, u32, u32) { | ||
| generic_tally(proposal_hash, take_vote_of) | ||
| } | ||
|
|
||
| fn generic_tally<F: Fn(&AccountId, &ProposalHash) -> Option<bool>>(proposal_hash: &ProposalHash, vote_of: F) -> (u32, u32, u32) { | ||
| let c = council::active_council(); | ||
| let (approve, reject) = c.iter() | ||
| .filter_map(|&(ref a, _)| vote_of(a, proposal_hash)) | ||
| .map(|approve| if approve { (1, 0) } else { (0, 1) }) | ||
| .fold((0, 0), |(a, b), (c, d)| (a + c, b + d)); | ||
| (approve, reject, c.len() as u32 - approve - reject) | ||
| } | ||
|
|
||
| fn set_proposals(p: &Vec<(BlockNumber, ProposalHash)>) { | ||
| storage::put(PROPOSALS, p) | ||
| } | ||
|
|
||
| fn take_proposal_if_expiring_at(n: BlockNumber) -> Option<(Proposal, ProposalHash)> { | ||
| let mut proposals = proposals(); | ||
| match proposals.first() { | ||
| Some(&(expiry, hash)) if expiry == n => { | ||
| // yes this is horrible, but fixing it will need substantial work in storage. | ||
| set_proposals(&proposals[1..].to_vec()); | ||
| let proposal = storage::take(&hash.to_keyed_vec(PROPOSAL_OF)).expect("all queued proposal hashes must have associated proposals"); | ||
| Some((proposal, hash)) | ||
| } | ||
| _ => None, | ||
| } | ||
| } | ||
|
|
||
| pub mod public { | ||
| use super::*; | ||
|
|
||
| pub fn propose(signed: &AccountId, proposal: &Proposal) { | ||
| let expiry = system::block_number() + voting_period(); | ||
| assert!(will_still_be_councillor_at(signed, expiry)); | ||
|
|
||
| let proposal_hash = proposal.blake2_256(); | ||
| assert!(!was_vetoed(&proposal_hash)); | ||
|
|
||
| let mut proposals = proposals(); | ||
| proposals.push((expiry, proposal_hash)); | ||
| proposals.sort_by_key(|&(expiry, _)| expiry); | ||
| set_proposals(&proposals); | ||
|
|
||
| storage::put(&proposal_hash.to_keyed_vec(PROPOSAL_OF), proposal); | ||
| storage::put(&proposal_hash.to_keyed_vec(PROPOSAL_VOTERS), &vec![*signed]); | ||
| storage::put(&(proposal_hash, *signed).to_keyed_vec(COUNCIL_VOTE_OF), &true); | ||
| } | ||
|
|
||
| pub fn vote(signed: AccountId, proposal: &ProposalHash, approve: bool) { | ||
|
|
||
| } | ||
|
|
||
| pub fn veto(signed: AccountId, proposal: &ProposalHash) { | ||
|
|
||
| } | ||
|
|
||
| pub fn repropose(signed: AccountId, proposal: &Proposal) { | ||
|
|
||
| } | ||
| } | ||
|
|
||
| pub mod privileged { | ||
| use super::*; | ||
|
|
||
| pub fn set_cooloff_period(blocks: BlockNumber) { | ||
| storage::put(COOLOFF_PERIOD, &blocks); | ||
| } | ||
|
|
||
| pub fn set_voting_period(blocks: BlockNumber) { | ||
| storage::put(VOTING_PERIOD, &blocks); | ||
| } | ||
| } | ||
|
|
||
| pub mod internal { | ||
| use super::*; | ||
| use runtime::democracy::VoteThreshold; | ||
| use runtime::democracy::privileged::start_referendum; | ||
|
|
||
| pub fn end_block(now: BlockNumber) { | ||
| while let Some((proposal, proposal_hash)) = take_proposal_if_expiring_at(now) { | ||
| let tally = take_tally(&proposal_hash); | ||
| let vote_threshold = match tally.0 { | ||
| x if x == tally.2 => VoteThreshold::SuperMajorityAgainst, | ||
| x if x > tally.2 / 2 => VoteThreshold::SimpleMajority, | ||
| _ => VoteThreshold::SuperMajorityApprove, | ||
| }; | ||
| start_referendum(proposal, vote_threshold); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
|
|
||
| } |
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
Oops, something went wrong.
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.
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.
Should not it contain all enum values?
Uh oh!
There was an error while loading. Please reload this page.
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.
this really should be a simple match. sure, it's a bit more verbose, but matches have to be exhaustive and we wouldn't have to worry about this breaking if we change discriminant values or add a variant
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.
it'll soon not matter.