Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
acab9a3
Block builder (substrate)
gavofyork Feb 12, 2018
9acd3f9
Fix wasm build
gavofyork Feb 12, 2018
ca5900f
Bulid on any block
gavofyork Feb 13, 2018
d11cfe1
Test for block builder.
gavofyork Feb 13, 2018
b973ccc
Block import tests for client.
gavofyork Feb 13, 2018
ec61865
Tidy ups
gavofyork Feb 13, 2018
cec06a7
Repotted client
gavofyork Feb 13, 2018
38cd36a
Avoid pointless work
gavofyork Feb 13, 2018
8b7abca
All backend stuff now manages optional storage.
gavofyork Feb 13, 2018
9dba812
Native runtime-io now supports empty storage items.
gavofyork Feb 13, 2018
0f591c6
Finish up the API transition.
gavofyork Feb 14, 2018
79c6b4c
Merge branch 'master' into gav-optional-storage
gavofyork Feb 15, 2018
a802b7e
Build fix.
gavofyork Feb 15, 2018
3928c1c
Fix tests.
gavofyork Feb 15, 2018
002ab5f
Merge branch 'master' into gav-optional-storage
gavofyork Feb 16, 2018
61db63f
Remerge in changes to client.
gavofyork Feb 16, 2018
5d1a3a7
Final fixes.
gavofyork Feb 16, 2018
212d370
Unrevert typos
gavofyork Feb 17, 2018
780e549
Remove accidentally committed change
gavofyork Feb 18, 2018
e552875
Bring back zero copy
gavofyork Feb 18, 2018
0a08196
Fix merge.
gavofyork Feb 18, 2018
e25960b
Refactor out some duped code
gavofyork Feb 19, 2018
9042880
Merge branch 'master' into gav-demo
gavofyork Feb 20, 2018
af3a413
Add docs.
gavofyork Feb 20, 2018
2b13856
More mssing doc.
gavofyork Feb 20, 2018
08060a6
Fix up wasm build.
gavofyork Feb 20, 2018
036142c
Introduce substrate-demo
gavofyork Feb 20, 2018
38bf4d7
Remove bad files.
gavofyork Feb 20, 2018
a2fb006
Tidy up unneeded code.
gavofyork Feb 20, 2018
775cb5a
Add needed file.
gavofyork Feb 20, 2018
0b83481
Initial staging ground for interior wasm smart-contracts.
gavofyork Feb 20, 2018
3413d14
More work on Ext & calls.
gavofyork Feb 22, 2018
0a82fd2
Fix logic
gavofyork Feb 23, 2018
b098eb2
comment
gavofyork Feb 23, 2018
73c4141
Remove unneeded call depth.
gavofyork Feb 25, 2018
9ef9c01
Use BTreeMap rather than HashMap in demo runtime.
gavofyork Feb 25, 2018
59c371f
Initial draft of stakeholder democracy.
gavofyork Feb 25, 2018
696f22a
Tests for referenda.
gavofyork Feb 26, 2018
98b74bc
Design of the approval voting module for council election.
gavofyork Feb 27, 2018
87bc061
Implement next_tally.
gavofyork Feb 28, 2018
f5ad966
More work on governance.
gavofyork Feb 28, 2018
afcff76
Submit candidacy.
gavofyork Mar 1, 2018
264384d
presenting a winner.
gavofyork Mar 1, 2018
822a5dc
Final bit of core logic for the council.
gavofyork Mar 1, 2018
9a1d638
remove inactive voter.
gavofyork Mar 1, 2018
4618367
Space out votes by a minimum period.
gavofyork Mar 1, 2018
9af17a5
Candidacy tests
gavofyork Mar 2, 2018
511775c
More candidate tests.
gavofyork Mar 2, 2018
2eeb88e
More tests for voting.
gavofyork Mar 2, 2018
5ea3f2b
Test for tally
gavofyork Mar 2, 2018
bcb2b39
More tests, for runners-up.
gavofyork Mar 2, 2018
3541d4e
test: second tally uses runners-up.
gavofyork Mar 2, 2018
a0c405f
Tests: various error cases with present.
gavofyork Mar 2, 2018
899e26e
tests: presenting losers
gavofyork Mar 2, 2018
4777806
cleanups.
gavofyork Mar 2, 2018
f0d5f53
Merge branch 'master' into gav-demo
gavofyork Mar 2, 2018
f276b4d
tests: Retract inactive voter
gavofyork Mar 2, 2018
05b6a8d
Additional docs & test.
gavofyork Mar 2, 2018
2bf2799
Add one vote worth of time for voters to unregister before they becom…
gavofyork Mar 2, 2018
999c082
Avoid allowing same accounts to be doubly-elected.
gavofyork Mar 2, 2018
0c9265f
test: against double presentations.
gavofyork Mar 2, 2018
3c911cd
Update docs
gavofyork Mar 2, 2018
002ddab
Simultaneous referendums and multiple voting variants.
gavofyork Mar 3, 2018
b8cc3a1
Introduce logic for deposits.
gavofyork Mar 3, 2018
9aeb95c
Deposits, not fees.
gavofyork Mar 3, 2018
fffbadd
cleanups.
gavofyork Mar 3, 2018
6dfe148
Introduce minimum deposit
gavofyork Mar 3, 2018
907fac7
Tests for public referenda.
gavofyork Mar 4, 2018
0bbd6b3
Tests for public referenda.
gavofyork Mar 4, 2018
8df2342
remove string constants <-- @rphmeier
gavofyork Mar 4, 2018
c73e3f9
Ensure council always sorted by expiry.
gavofyork Mar 4, 2018
0bb5791
Initial council vote logic.
gavofyork Mar 4, 2018
f780504
More tests for council voting.
gavofyork Mar 5, 2018
25b8c20
council vetoing & tests.
gavofyork Mar 5, 2018
7ef0b17
Another few tests for council_vote.
gavofyork Mar 5, 2018
8b37acf
Final tests.
gavofyork Mar 6, 2018
bb7f398
Move council over to new Keyring API.
gavofyork Mar 6, 2018
8be2cc8
Move democracy module over no new Keyring API
gavofyork Mar 6, 2018
7e6e40d
Introduce stake reservation; make panicking tests better.
gavofyork Mar 6, 2018
7e8e404
Genesis map.
gavofyork Mar 7, 2018
2d66a63
Use a struct!
gavofyork Mar 7, 2018
22d4829
Tests for staking reserved balances & slashing.
gavofyork Mar 10, 2018
5450807
Public function dispatching.
gavofyork Mar 10, 2018
e09096c
Safe panic.
gavofyork Mar 10, 2018
128fa23
Fix tests and avoid use of old keys.
gavofyork Mar 10, 2018
d347030
Fix grumbles.
gavofyork Mar 11, 2018
b6897d5
Minor typos.
gavofyork Mar 11, 2018
6029553
Cleanups and introduce all dispatchable endpoints.
gavofyork Mar 12, 2018
f3439c9
Additional function ids for derivation.
gavofyork Mar 12, 2018
23b030a
Formatting.
gavofyork Mar 12, 2018
016a7b6
Remove stray printlns.
gavofyork Mar 14, 2018
0f81021
Merge branch 'master' into gav-demo
gavofyork Mar 14, 2018
5c9a40a
Update wasm.
gavofyork Mar 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Initial council vote logic.
  • Loading branch information
gavofyork committed Mar 4, 2018
commit 0bb57916a887f4f47d1064f3ca50ecac206643ed
36 changes: 1 addition & 35 deletions demo/primitives/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ enum InternalFunctionId {
StakingSetValidatorCount = 0x22,
/// Force a new staking era.
StakingForceNewEra = 0x23,

/// Set the per-mille of validator approval required for governance changes.
GovernanceSetApprovalPpmRequired = 0x30,

}

impl InternalFunctionId {
Expand All @@ -61,7 +57,6 @@ impl InternalFunctionId {
InternalFunctionId::StakingSetBondingDuration,
InternalFunctionId::StakingSetValidatorCount,
InternalFunctionId::StakingForceNewEra,
InternalFunctionId::GovernanceSetApprovalPpmRequired,
];
functions.iter().map(|&f| f).find(|&f| value == f as u8)
}
Expand All @@ -85,9 +80,6 @@ pub enum Proposal {
StakingSetValidatorCount(u32),
/// Force a new staking era.
StakingForceNewEra,
/// Set the per-mille of validator approval required for governance changes.
GovernanceSetApprovalPpmRequired(u32),

}

impl Slicable for Proposal {
Expand All @@ -106,8 +98,6 @@ impl Slicable for Proposal {
InternalFunctionId::StakingSetValidatorCount =>
Proposal::StakingSetValidatorCount(try_opt!(Slicable::decode(input))),
InternalFunctionId::StakingForceNewEra => Proposal::StakingForceNewEra,
InternalFunctionId::GovernanceSetApprovalPpmRequired =>
Proposal::GovernanceSetApprovalPpmRequired(try_opt!(Slicable::decode(input))),
};

Some(function)
Expand Down Expand Up @@ -142,10 +132,6 @@ impl Slicable for Proposal {
Proposal::StakingForceNewEra => {
(InternalFunctionId::StakingForceNewEra as u8).using_encoded(|s| v.extend(s));
}
Proposal::GovernanceSetApprovalPpmRequired(ref data) => {
(InternalFunctionId::GovernanceSetApprovalPpmRequired as u8).using_encoded(|s| v.extend(s));
data.using_encoded(|s| v.extend(s));
}
}

v
Expand All @@ -167,10 +153,6 @@ enum FunctionId {
StakingUnstake = 0x21,
/// Staking subsystem: transfer stake.
StakingTransfer = 0x22,
/// Make a proposal for the governance system.
GovernancePropose = 0x30,
/// Approve a proposal for the governance system.
GovernanceApprove = 0x31,
}

impl FunctionId {
Expand All @@ -179,7 +161,7 @@ impl FunctionId {
use self::*;
let functions = [FunctionId::StakingStake, FunctionId::StakingUnstake,
Copy link
Member

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?

Copy link
Contributor

@rphmeier rphmeier Mar 12, 2018

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

Copy link
Member Author

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.

FunctionId::StakingTransfer, FunctionId::SessionSetKey, FunctionId::TimestampSet,
FunctionId::GovernancePropose, FunctionId::GovernanceApprove];
];
functions.iter().map(|&f| f).find(|&f| value == f as u8)
}
}
Expand All @@ -198,10 +180,6 @@ pub enum Function {
StakingUnstake,
/// Staking subsystem: transfer stake.
StakingTransfer(::AccountId, u64),
/// Make a proposal for the governance system.
GovernancePropose(Proposal),
/// Approve a proposal for the governance system.
GovernanceApprove(BlockNumber),
}

impl Slicable for Function {
Expand All @@ -220,10 +198,6 @@ impl Slicable for Function {

Function::StakingTransfer(to, amount)
}
FunctionId::GovernancePropose =>
Function::GovernancePropose(try_opt!(Slicable::decode(input))),
FunctionId::GovernanceApprove =>
Function::GovernanceApprove(try_opt!(Slicable::decode(input))),
})
}

Expand All @@ -249,14 +223,6 @@ impl Slicable for Function {
to.using_encoded(|s| v.extend(s));
amount.using_encoded(|s| v.extend(s));
}
Function::GovernancePropose(ref data) => {
(FunctionId::GovernancePropose as u8).using_encoded(|s| v.extend(s));
data.using_encoded(|s| v.extend(s));
}
Function::GovernanceApprove(ref data) => {
(FunctionId::GovernanceApprove as u8).using_encoded(|s| v.extend(s));
data.using_encoded(|s| v.extend(s));
}
}

v
Expand Down
5 changes: 1 addition & 4 deletions demo/runtime/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! Democratic system: Handles administration of general stakeholder voting.

use demo_primitives::Proposal;
use runtime::{staking, system, session, governance};
use runtime::{staking, system, session};

pub fn enact_proposal(proposal: Proposal) {
match proposal {
Expand All @@ -42,8 +42,5 @@ pub fn enact_proposal(proposal: Proposal) {
Proposal::StakingForceNewEra => {
staking::privileged::force_new_era()
}
Proposal::GovernanceSetApprovalPpmRequired(value) => {
governance::privileged::set_approval_ppm_required(value);
}
}
}
169 changes: 169 additions & 0 deletions demo/runtime/src/runtime/council_vote.rs
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 {

}
5 changes: 0 additions & 5 deletions demo/runtime/src/runtime/democracy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ pub const DEPOSIT_OF: &[u8] = b"dem:dep:"; // PropIndex -> (Balance, Vec<Accou
pub const LAUNCH_PERIOD: &[u8] = b"dem:lau"; // BlockNumber
pub const MINIMUM_DEPOSIT: &[u8] = b"dem:min"; // Balance

// council proposals
pub const COUNCIL_PROPOSAL: &[u8] = b"dem:cou:pro"; // (BlockNumber, Proposal)
pub const COUNCIL_VOTE_OF: &[u8] = b"dem:cou:vot:"; // AccountId -> CouncilVote
pub const COUNCIL_VOTERS: &[u8] = b"dem:cou:vts"; // Vec<AccountId>

// referenda
pub const VOTING_PERIOD: &[u8] = b"dem:per"; // BlockNumber
pub const REFERENDUM_COUNT: &[u8] = b"dem:rco"; // ReferendumIndex
Expand Down
Loading