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
Implement next_tally.
  • Loading branch information
gavofyork committed Feb 28, 2018
commit 87bc061ae9ea2d8995d77fb6c156c19d4cf9039a
135 changes: 100 additions & 35 deletions demo/runtime/src/runtime/council.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,64 +66,119 @@ use runtime::staking::Balance;
// vec<voter> (all voters. order unimportant - just need to be enumerable.)
// voter -> (last round, Vec<bool>)

const CURRENT_VOTE: &[u8] = b"cou:cur";
type VoteIndex = u32;

const ACTIVE_COUNCIL: &[u8] = b"cou:act";

const APPROVALS_OF: &[u8] = b"cou:apr:";
const VOTERS: &[u8] = b"cou:vrs";
const CANDIDATES: &[u8] = b"cou:can";

const VOTE_COUNT: &[u8] = b"cou:vco";

const CANDIDACY_BOND: &[u8] = b"cou:cbo";
const VOTING_BOND: &[u8] = b"cou:vbo";

const CARRY_COUNT: &[u8] = b"cou:cco";
const PRESENTATION_DURATION: &[u8] = b"cou:pdu";
const TERM_DURATION: &[u8] = b"cou:trm";
const DESIRED_SEATS: &[u8] = b"cou:sts";

const NEXT_FINALISE: &[u8] = b"cou:nxt";
const STAKE_SNAPSHOT: &[u8] = b"cou:sss";
const WINNERS: &[u8] = b"cou:win";

/// How much should be locked up in order to submit one's candidacy.
pub fn candidacy_bond() -> Balance {
unimplemented!();
storage::get(CANDIDACY_BOND)
.expect("all core parameters of council module must be in place")
}

/// How much should be locked up in order to be able to submit votes.
pub fn voting_bond() -> Balance {
unimplemented!();
storage::get(VOTING_BOND)
.expect("all core parameters of council module must be in place")
}

/// How long to give each top candidate to present themselves after the vote ends.
pub fn presentation_duration() -> BlockNumber {
unimplemented!();
storage::get(PRESENTATION_DURATION)
.expect("all core parameters of council module must be in place")
}

/// How long each position is active for.
pub fn term_duration() -> BlockNumber {
storage::get(TERM_DURATION)
.expect("all core parameters of council module must be in place")
}

/// Number of accounts that should be sitting on the council.
pub fn desired_seats() -> u32 {
storage::get(DESIRED_SEATS)
.expect("all core parameters of council module must be in place")
}

/// How many runners-up should have their approvals persist until the next vote.
pub fn carry_count() -> u32 {
unimplemented!();
storage::get(CARRY_COUNT)
.expect("all core parameters of council module must be in place")
}

/// The current council. When there's a vote going on, this should still be used for executive
/// matters.
pub fn active_council() -> Vec<AccountId> {
unimplemented!();
pub fn active_council() -> Vec<(AccountId, BlockNumber)> {
storage::get_or_default(ACTIVE_COUNCIL)
}

/// The block number on which the tally for the next election will happen. `None` only if the
/// desired seats of the council is zero.
pub fn next_tally() -> Option<BlockNumber> {
let desired_seats = desired_seats();
if desired_seats == 0 {
None
} else {
let c = active_council();
let (next_possible, count, coming) =
if let Some((tally_end, comers, leavers)) = next_finalise() {
// if there's a tally in progress, then next tally can begin immediately afterwards
(tally_end, c.len() - leavers.len() + comers as usize, comers)
} else {
(system::block_number(), c.len(), 0)
};
if count < desired_seats as usize {
Some(next_possible)
} else {
// next tally begins once enough council members expire to bring members below desired.
if desired_seats <= coming {
Some(next_possible + term_duration())
} else {
Some(c[c.len() - (desired_seats - coming) as usize].1)
}
}
}
}

/// The accounts holding the seats that will become free on the next tally.
pub fn next_finalise() -> Option<(BlockNumber, u32, Vec<AccountId>)> {
storage::get(NEXT_FINALISE)
}

/// The information on the current vote:
/// - The block number where voting will end;
/// - The specific council members to be replaced.
pub fn current_vote() -> Option<(BlockNumber, Vec<AccountId>)> {
/// The number of seats that will be elected on the next tally.
pub fn empty_seats() -> u32 {
unimplemented!();
}

/// The total number of votes that have happened or are in progress.
pub fn vote_index() -> VoteIndex {
unimplemented!();
storage::get_or_default(VOTE_COUNT)
}

/// The queue of candidate indices that will be cleared.
pub fn candidate_clear_queue() -> {
pub fn candidate_clear_queue(vote: VoteIndex) -> Vec<u32> {
unimplemented!();
}

/// The last cleared vote index that this voter was last active at.
pub fn voter_last_active(voter: &AddressId) -> VoteIndex {
pub fn voter_last_active(voter: &AccountId) -> VoteIndex {
unimplemented!();
}

Expand All @@ -134,7 +189,7 @@ pub mod public {
/// when it was last active until the penultimate vote should result in no approvals.
///
/// May be called by anyone. Returns the voter deposit to `signed`.
pub fn kill_inactive_voter(signed: &AccountId, who: &AddressId) {
pub fn kill_inactive_voter(signed: &AccountId, who: &AccountId) {
unimplemented!();
}

Expand Down Expand Up @@ -164,13 +219,30 @@ pub mod privileged {
/// election when they expire. If more, then a new vote will be started if one is not already
/// in progress.
pub fn set_desired_seats(count: u32) {
unimplemented!();
storage::put(DESIRED_SEATS, &count);
}

/// Remove a particular member. A new vote will be started if one is not already in progress.
/// Remove a particular member. A tally will happen instantly (if not already in a presentation
/// period) to fill the seat if removal means that the desired members are not met.
/// This is effective immediately.
pub fn remove_member(who: AddressId) {
unimplemented!();
pub fn remove_member(who: &AccountId) {
let new_council: Vec<(AccountId, BlockNumber)> = active_council()
.into_iter()
.filter(|i| i.0 != *who)
.collect();
storage::put(ACTIVE_COUNCIL, &new_council);
}

/// Set the presentation duration. If there is current a vote being presented for, will
/// invoke `finalise_vote`.
pub fn set_presentation_duration(count: BlockNumber) {
storage::put(PRESENTATION_DURATION, &count);
}

/// Set the presentation duration. If there is current a vote being presented for, will
/// invoke `finalise_vote`.
pub fn set_term_duration(count: BlockNumber) {
storage::put(TERM_DURATION, &count);
}
}

Expand All @@ -181,27 +253,29 @@ pub mod internal {

/// Current era is ending; we should finish up any proposals.
pub fn end_block() {
if let Some((number, removals)) = current_vote() {
if let Some(number) = next_tally() {
if system::block_number() == number {
close_voting(removals.len() as u32);
close_voting();
}
if system::block_number() == number + presentation_duration() {
finalise_vote(removals);
}
if let Some((number, _, _)) = next_finalise() {
if system::block_number() == number {
finalise_vote();
}
}
}
}

/// Close the voting, snapshot the staking and the number of seats that are actually up for grabs.
fn close_voting(removal_count: u32) {
fn close_voting() {
unimplemented!();
}

/// Finalise the vote, removing each of the `removals` and inserting `seats` of the most approved
/// candidates in their place. If the total council members is less than the desired membership
/// a new vote is started.
/// Clears all presented candidates, returning the bond of the elected ones.
fn finalise_vote(seats: u32, removals: Vec<AccountId>) {
fn finalise_vote() {
unimplemented!();
}

Expand Down Expand Up @@ -258,15 +332,6 @@ mod tests {
assert_eq!(staking::total_stake(), 210u64);

with_env(|e| e.block_number = 1);
public::propose(&alice, &Proposal::StakingSetSessionsPerEra(2));
public::vote(&alice, 1, true);

assert_eq!(public::tally(), (10, 0));

democracy::internal::end_of_an_era();
staking::internal::check_new_era();

assert_eq!(staking::era_length(), 2u64);
});
}
}
2 changes: 2 additions & 0 deletions demo/runtime/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub mod session;
pub mod governance;
#[allow(unused)]
pub mod democracy;
#[allow(unused)]
pub mod council;


// TODO: polkadao