Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Governance: Voters put money where mouth is #1183

Merged
merged 8 commits into from
Dec 10, 2018
4 changes: 4 additions & 0 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
launch_period: 5 * MINUTES, // 1 day per public referendum
voting_period: 5 * MINUTES, // 3 days to discuss & vote on an active referendum
minimum_deposit: 50 * DOLLARS, // 12000 as the minimum deposit for a referendum
public_delay: 0,
_genesis_phantom_data: Default::default(),
}),
council_seats: Some(CouncilSeatsConfig {
Expand All @@ -113,6 +114,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
council_voting: Some(CouncilVotingConfig {
cooloff_period: 4 * DAYS,
voting_period: 1 * DAYS,
enact_delay_period: 0,
_genesis_phantom_data: Default::default(),
}),
timestamp: Some(TimestampConfig {
Expand Down Expand Up @@ -226,6 +228,7 @@ pub fn testnet_genesis(
launch_period: 9,
voting_period: 18,
minimum_deposit: 10,
public_delay: 0,
_genesis_phantom_data: Default::default(),
}),
council_seats: Some(CouncilSeatsConfig {
Expand All @@ -246,6 +249,7 @@ pub fn testnet_genesis(
council_voting: Some(CouncilVotingConfig {
cooloff_period: 75,
voting_period: 20,
enact_delay_period: 0,
_genesis_phantom_data: Default::default(),
}),
timestamp: Some(TimestampConfig {
Expand Down
2 changes: 2 additions & 0 deletions srml/council/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ mod tests {
launch_period: 1,
voting_period: 3,
minimum_deposit: 1,
public_delay: 0,
_genesis_phantom_data: Default::default(),
}.build_storage().unwrap().0);
t.extend(seats::GenesisConfig::<Test> {
Expand All @@ -150,6 +151,7 @@ mod tests {
t.extend(voting::GenesisConfig::<Test> {
cooloff_period: 2,
voting_period: 1,
enact_delay_period: 0,
_genesis_phantom_data: Default::default(),
}.build_storage().unwrap().0);
runtime_io::TestExternalities::new(t)
Expand Down
34 changes: 22 additions & 12 deletions srml/council/src/voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ decl_storage! {
trait Store for Module<T: Trait> as CouncilVoting {
pub CooloffPeriod get(cooloff_period) config(): T::BlockNumber = T::BlockNumber::sa(1000);
pub VotingPeriod get(voting_period) config(): T::BlockNumber = T::BlockNumber::sa(3);
/// Number of blocks by which to delay enactment of successful, non-unanimous-council-instigated referendum proposals.
pub EnactDelayPeriod get(enact_delay_period) config(): T::BlockNumber = T::BlockNumber::sa(0);
pub Proposals get(proposals) build(|_| vec![0u8; 0]): Vec<(T::BlockNumber, T::Hash)>; // ordered by expiry.
pub ProposalOf get(proposal_of): map T::Hash => Option<T::Proposal>;
pub ProposalVoters get(proposal_voters): map T::Hash => Vec<T::AccountId>;
Expand Down Expand Up @@ -215,10 +217,18 @@ impl<T: Trait> Module<T> {
Self::deposit_event(RawEvent::TallyReferendum(proposal_hash.clone(), tally.0, tally.1, tally.2));
if tally.0 > tally.1 + tally.2 {
Self::kill_veto_of(&proposal_hash);
match tally {
(_, 0, 0) => <democracy::Module<T>>::internal_start_referendum(proposal, democracy::VoteThreshold::SuperMajorityAgainst, Zero::zero()).map(|_| ())?,
_ => <democracy::Module<T>>::internal_start_referendum(proposal, democracy::VoteThreshold::SimpleMajority, Zero::zero()).map(|_| ())?,
// If there were no nay-votes from the council, then it's weakly uncontroversial; we enact immediately.
let period = match tally.1 {
0 => Zero::zero(),
_ => Self::enact_delay_period(),
};
// If all council members voted yes, then it's strongly unconversial; we require a negative
// super-majority at referendum in order to defeat it.
Copy link
Contributor

@ltfschoen ltfschoen Dec 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nitpick) typo uncontroversial

let threshold = match tally {
(_, 0, 0) => democracy::VoteThreshold::SuperMajorityAgainst,
_ => democracy::VoteThreshold::SimpleMajority,
};
<democracy::Module<T>>::internal_start_referendum(proposal, threshold, period).map(|_| ())?;
}
}
}
Expand Down Expand Up @@ -267,8 +277,8 @@ mod tests {
with_externalities(&mut new_test_ext(true), || {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
assert_ok!(Democracy::internal_start_referendum(proposal.clone(), VoteThreshold::SuperMajorityApprove), 0);
assert_eq!(Democracy::active_referendums(), vec![(0, 4, proposal, VoteThreshold::SuperMajorityApprove)]);
assert_ok!(Democracy::internal_start_referendum(proposal.clone(), VoteThreshold::SuperMajorityApprove, 0), 0);
assert_eq!(Democracy::active_referendums(), vec![(0, 4, proposal, VoteThreshold::SuperMajorityApprove, 0)]);
Copy link
Contributor

@ltfschoen ltfschoen Dec 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would there be any benefit to using Zero::zero() for each of these instead of 0 (as was done in e1853be)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not within tests, where the type is concrete. Zero::zero() is needed when the type is abstract.


let cancellation = cancel_referendum_proposal(0);
let hash = cancellation.blake2_256().into();
Expand All @@ -290,7 +300,7 @@ mod tests {
with_externalities(&mut new_test_ext(true), || {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
assert_ok!(Democracy::internal_start_referendum(proposal.clone(), VoteThreshold::SuperMajorityApprove), 0);
assert_ok!(Democracy::internal_start_referendum(proposal.clone(), VoteThreshold::SuperMajorityApprove, 0), 0);

let cancellation = cancel_referendum_proposal(0);
let hash = cancellation.blake2_256().into();
Expand All @@ -301,7 +311,7 @@ mod tests {

System::set_block_number(2);
assert_ok!(CouncilVoting::end_block(System::block_number()));
assert_eq!(Democracy::active_referendums(), vec![(0, 4, proposal, VoteThreshold::SuperMajorityApprove)]);
assert_eq!(Democracy::active_referendums(), vec![(0, 4, proposal, VoteThreshold::SuperMajorityApprove, 0)]);
});
}

Expand All @@ -310,7 +320,7 @@ mod tests {
with_externalities(&mut new_test_ext(true), || {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
assert_ok!(Democracy::internal_start_referendum(proposal.clone(), VoteThreshold::SuperMajorityApprove), 0);
assert_ok!(Democracy::internal_start_referendum(proposal.clone(), VoteThreshold::SuperMajorityApprove, 0), 0);

let cancellation = cancel_referendum_proposal(0);
let hash = cancellation.blake2_256().into();
Expand All @@ -320,7 +330,7 @@ mod tests {

System::set_block_number(2);
assert_ok!(CouncilVoting::end_block(System::block_number()));
assert_eq!(Democracy::active_referendums(), vec![(0, 4, proposal, VoteThreshold::SuperMajorityApprove)]);
assert_eq!(Democracy::active_referendums(), vec![(0, 4, proposal, VoteThreshold::SuperMajorityApprove, 0)]);
});
}

Expand Down Expand Up @@ -384,7 +394,7 @@ mod tests {
System::set_block_number(4);
assert_ok!(CouncilVoting::end_block(System::block_number()));
assert_eq!(CouncilVoting::proposals().len(), 0);
assert_eq!(Democracy::active_referendums(), vec![(0, 7, set_balance_proposal(42), VoteThreshold::SimpleMajority)]);
assert_eq!(Democracy::active_referendums(), vec![(0, 7, set_balance_proposal(42), VoteThreshold::SimpleMajority, 0)]);
});
}

Expand Down Expand Up @@ -449,7 +459,7 @@ mod tests {
System::set_block_number(2);
assert_ok!(CouncilVoting::end_block(System::block_number()));
assert_eq!(CouncilVoting::proposals().len(), 0);
assert_eq!(Democracy::active_referendums(), vec![(0, 5, proposal, VoteThreshold::SuperMajorityAgainst)]);
assert_eq!(Democracy::active_referendums(), vec![(0, 5, proposal, VoteThreshold::SuperMajorityAgainst, 0)]);
});
}

Expand All @@ -467,7 +477,7 @@ mod tests {
System::set_block_number(2);
assert_ok!(CouncilVoting::end_block(System::block_number()));
assert_eq!(CouncilVoting::proposals().len(), 0);
assert_eq!(Democracy::active_referendums(), vec![(0, 5, proposal, VoteThreshold::SimpleMajority)]);
assert_eq!(Democracy::active_referendums(), vec![(0, 5, proposal, VoteThreshold::SimpleMajority, 0)]);
});
}

Expand Down
12 changes: 6 additions & 6 deletions srml/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ mod tests {
fn simple_passing_should_work() {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap();
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap();
Copy link
Contributor

@ltfschoen ltfschoen Dec 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per previous comment, any benefit in using Zero::zero() instead of 0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not within tests, where the type is concrete.

assert_ok!(Democracy::vote(Origin::signed(1), r.into(), true));

assert_eq!(Democracy::voters_for(r), vec![1]);
Expand All @@ -598,7 +598,7 @@ mod tests {
fn cancel_referendum_should_work() {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap();
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap();
assert_ok!(Democracy::vote(Origin::signed(1), r.into(), true));
assert_ok!(Democracy::cancel_referendum(r.into()));

Expand All @@ -612,7 +612,7 @@ mod tests {
fn simple_failing_should_work() {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap();
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap();
assert_ok!(Democracy::vote(Origin::signed(1), r.into(), false));

assert_eq!(Democracy::voters_for(r), vec![1]);
Expand All @@ -629,7 +629,7 @@ mod tests {
fn controversial_voting_should_work() {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap();
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap();
assert_ok!(Democracy::vote(Origin::signed(1), r.into(), true));
assert_ok!(Democracy::vote(Origin::signed(2), r.into(), false));
assert_ok!(Democracy::vote(Origin::signed(3), r.into(), false));
Expand All @@ -649,7 +649,7 @@ mod tests {
fn controversial_low_turnout_voting_should_work() {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap();
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap();
assert_ok!(Democracy::vote(Origin::signed(5), r.into(), false));
assert_ok!(Democracy::vote(Origin::signed(6), r.into(), true));

Expand All @@ -668,7 +668,7 @@ mod tests {
assert_eq!(Balances::total_issuance(), 210);

System::set_block_number(1);
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap();
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap();
assert_ok!(Democracy::vote(Origin::signed(4), r.into(), true));
assert_ok!(Democracy::vote(Origin::signed(5), r.into(), false));
assert_ok!(Democracy::vote(Origin::signed(6), r.into(), true));
Expand Down