diff --git a/node/cli/src/chain_spec.rs b/node/cli/src/chain_spec.rs index fd53d64612ca1..318adbff2c447 100644 --- a/node/cli/src/chain_spec.rs +++ b/node/cli/src/chain_spec.rs @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/srml/council/src/lib.rs b/srml/council/src/lib.rs index 629b0ed9e1b92..f3fbf3168a5e0 100644 --- a/srml/council/src/lib.rs +++ b/srml/council/src/lib.rs @@ -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:: { @@ -150,6 +151,7 @@ mod tests { t.extend(voting::GenesisConfig:: { cooloff_period: 2, voting_period: 1, + enact_delay_period: 0, _genesis_phantom_data: Default::default(), }.build_storage().unwrap().0); runtime_io::TestExternalities::new(t) diff --git a/srml/council/src/voting.rs b/srml/council/src/voting.rs index 7f5f3f80a783f..82b2b6f5f76c7 100644 --- a/srml/council/src/voting.rs +++ b/srml/council/src/voting.rs @@ -122,6 +122,8 @@ decl_storage! { trait Store for Module 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; pub ProposalVoters get(proposal_voters): map T::Hash => Vec; @@ -215,10 +217,18 @@ impl Module { 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) => >::internal_start_referendum(proposal, democracy::VoteThreshold::SuperMajorityAgainst, Zero::zero()).map(|_| ())?, - _ => >::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. + let threshold = match tally { + (_, 0, 0) => democracy::VoteThreshold::SuperMajorityAgainst, + _ => democracy::VoteThreshold::SimpleMajority, + }; + >::internal_start_referendum(proposal, threshold, period).map(|_| ())?; } } } @@ -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)]); let cancellation = cancel_referendum_proposal(0); let hash = cancellation.blake2_256().into(); @@ -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(); @@ -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)]); }); } @@ -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(); @@ -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)]); }); } @@ -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)]); }); } @@ -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)]); }); } @@ -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)]); }); } diff --git a/srml/democracy/src/lib.rs b/srml/democracy/src/lib.rs index 166bddd090aa9..352e72f84f193 100644 --- a/srml/democracy/src/lib.rs +++ b/srml/democracy/src/lib.rs @@ -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(); assert_ok!(Democracy::vote(Origin::signed(1), r.into(), true)); assert_eq!(Democracy::voters_for(r), vec![1]); @@ -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())); @@ -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]); @@ -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)); @@ -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)); @@ -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));