Enhanced Council. (#2407)

* first --unclean-- working version of locks and weight decay

* Refactor voter activity history.

* Tuning offset calculation and tests

* Remove print.

* Configurable decay ratio.

* Remove spaces.

* Name for activity.

* Fix some style

* Re-write voters as chunked map-vec.

* Adds panic todo.

* Fix some of the grumbles.

* Fix some of the grumbles.

* Chunked approvals vector.

* Introduce voter_index for set_approvas in favor of complexity.

* Add a bit more docs

* Add boolean approvals as scalar.

* Some cleanups TODO removes.

* enhance some error checking.

* No more double_map

* Combined voter info and fee.

* Fix global tests

* Bump.

* Fix line length

* Fix error message.

* Kill As<T>.

* Final fix.

* _Further_ kill As.

* Proper imbalance for fee.

* Bump.

* Fix spacing.

* Update

* Address grumbles.

* Line width.
This commit is contained in:
Kian Peymani
2019-06-07 15:27:32 +02:00
committed by Gavin Wood
parent 5a2282ce82
commit d7ba5c00ba
6 changed files with 1483 additions and 332 deletions
+6 -1
View File
@@ -124,12 +124,14 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
active_council: vec![],
candidacy_bond: 10 * DOLLARS,
voter_bond: 1 * DOLLARS,
voting_fee: 2 * DOLLARS,
present_slash_per_voter: 1 * CENTS,
carry_count: 6,
presentation_duration: 1 * DAYS,
approval_voting_period: 2 * DAYS,
term_duration: 28 * DAYS,
desired_seats: 0,
decay_ratio: 0,
inactive_grace_period: 1, // one additional vote should go by before an inactive voter can be reaped.
}),
timestamp: Some(TimestampConfig {
@@ -234,6 +236,7 @@ pub fn testnet_genesis(
const STASH: u128 = 1 << 20;
const ENDOWMENT: u128 = 1 << 20;
let council_desired_seats = (endowed_accounts.len() / 2 - initial_authorities.len()) as u32;
let mut contract_config = ContractConfig {
signed_claim_handicap: 2,
rent_byte_price: 4,
@@ -299,12 +302,14 @@ pub fn testnet_genesis(
.map(|a| (a.clone(), 1000000)).collect(),
candidacy_bond: 10,
voter_bond: 2,
voting_fee: 5,
present_slash_per_voter: 1,
carry_count: 4,
presentation_duration: 10,
approval_voting_period: 20,
term_duration: 1000000,
desired_seats: (endowed_accounts.len() / 2 - initial_authorities.len()) as u32,
desired_seats: council_desired_seats,
decay_ratio: council_desired_seats / 3,
inactive_grace_period: 1,
}),
timestamp: Some(TimestampConfig {
+3
View File
@@ -182,9 +182,12 @@ impl council::Trait for Runtime {
type Event = Event;
type BadPresentation = ();
type BadReaper = ();
type BadVoterIndex = ();
type LoserCandidate = ();
type OnMembersChanged = CouncilMotions;
}
impl council::motions::Trait for Runtime {
type Origin = Origin;
type Proposal = Call;
+87 -29
View File
@@ -116,6 +116,8 @@ mod tests {
type Event = Event;
type BadPresentation = ();
type BadReaper = ();
type BadVoterIndex = ();
type LoserCandidate = ();
type OnMembersChanged = CouncilMotions;
}
impl motions::Trait for Test {
@@ -124,35 +126,91 @@ mod tests {
type Event = Event;
}
pub fn new_test_ext(with_council: bool) -> runtime_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
t.extend(balances::GenesisConfig::<Test>{
transaction_base_fee: 0,
transaction_byte_fee: 0,
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
existential_deposit: 0,
transfer_fee: 0,
creation_fee: 0,
vesting: vec![],
}.build_storage().unwrap().0);
t.extend(democracy::GenesisConfig::<Test>::default().build_storage().unwrap().0);
t.extend(seats::GenesisConfig::<Test> {
candidacy_bond: 9,
voter_bond: 3,
present_slash_per_voter: 1,
carry_count: 2,
inactive_grace_period: 1,
active_council: if with_council { vec![
(1, 10),
(2, 10),
(3, 10)
] } else { vec![] },
approval_voting_period: 4,
presentation_duration: 2,
desired_seats: 2,
term_duration: 5,
}.build_storage().unwrap().0);
runtime_io::TestExternalities::new(t)
pub struct ExtBuilder {
balance_factor: u64,
decay_ratio: u32,
voting_fee: u64,
voter_bond: u64,
bad_presentation_punishment: u64,
with_council: bool,
}
impl Default for ExtBuilder {
fn default() -> Self {
Self {
balance_factor: 1,
decay_ratio: 24,
voting_fee: 0,
voter_bond: 0,
bad_presentation_punishment: 1,
with_council: false,
}
}
}
impl ExtBuilder {
pub fn with_council(mut self, council: bool) -> Self {
self.with_council = council;
self
}
pub fn balance_factor(mut self, factor: u64) -> Self {
self.balance_factor = factor;
self
}
pub fn decay_ratio(mut self, ratio: u32) -> Self {
self.decay_ratio = ratio;
self
}
pub fn voting_fee(mut self, fee: u64) -> Self {
self.voting_fee = fee;
self
}
pub fn bad_presentation_punishment(mut self, fee: u64) -> Self {
self.bad_presentation_punishment = fee;
self
}
pub fn voter_bond(mut self, fee: u64) -> Self {
self.voter_bond = fee;
self
}
pub fn build(self) -> runtime_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
t.extend(balances::GenesisConfig::<Test>{
transaction_base_fee: 0,
transaction_byte_fee: 0,
balances: vec![
(1, 10 * self.balance_factor),
(2, 20 * self.balance_factor),
(3, 30 * self.balance_factor),
(4, 40 * self.balance_factor),
(5, 50 * self.balance_factor),
(6, 60 * self.balance_factor)
],
existential_deposit: 0,
transfer_fee: 0,
creation_fee: 0,
vesting: vec![],
}.build_storage().unwrap().0);
t.extend(seats::GenesisConfig::<Test> {
candidacy_bond: 3,
voter_bond: self.voter_bond,
present_slash_per_voter: self.bad_presentation_punishment,
carry_count: 2,
inactive_grace_period: 1,
active_council: if self.with_council { vec![
(1, 10),
(2, 10),
(3, 10)
] } else { vec![] },
approval_voting_period: 4,
presentation_duration: 2,
desired_seats: 2,
decay_ratio: self.decay_ratio,
voting_fee: self.voting_fee,
term_duration: 5,
}.build_storage().unwrap().0);
runtime_io::TestExternalities::new(t)
}
}
pub type System = system::Module<Test>;
+16 -16
View File
@@ -326,8 +326,8 @@ mod tests {
use hex_literal::hex;
#[test]
fn basic_environment_works() {
with_externalities(&mut new_test_ext(true), || {
fn motions_basic_environment_works() {
with_externalities(&mut ExtBuilder::default().with_council(true).build(), || {
System::set_block_number(1);
assert_eq!(Balances::free_balance(&42), 0);
assert_eq!(CouncilMotions::proposals(), Vec::<H256>::new());
@@ -340,7 +340,7 @@ mod tests {
#[test]
fn removal_of_old_voters_votes_works() {
with_externalities(&mut new_test_ext(true), || {
with_externalities(&mut ExtBuilder::default().with_council(true).build(), || {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
let hash = BlakeTwo256::hash_of(&proposal);
@@ -374,7 +374,7 @@ mod tests {
#[test]
fn propose_works() {
with_externalities(&mut new_test_ext(true), || {
with_externalities(&mut ExtBuilder::default().with_council(true).build(), || {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
let hash = proposal.blake2_256().into();
@@ -397,8 +397,8 @@ mod tests {
}
#[test]
fn ignoring_non_council_proposals_works() {
with_externalities(&mut new_test_ext(true), || {
fn motions_ignoring_non_council_proposals_works() {
with_externalities(&mut ExtBuilder::default().with_council(true).build(), || {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
assert_noop!(CouncilMotions::propose(Origin::signed(42), 3, Box::new(proposal.clone())), "proposer not on council");
@@ -406,8 +406,8 @@ mod tests {
}
#[test]
fn ignoring_non_council_votes_works() {
with_externalities(&mut new_test_ext(true), || {
fn motions_ignoring_non_council_votes_works() {
with_externalities(&mut ExtBuilder::default().with_council(true).build(), || {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
let hash: H256 = proposal.blake2_256().into();
@@ -417,8 +417,8 @@ mod tests {
}
#[test]
fn ignoring_bad_index_council_vote_works() {
with_externalities(&mut new_test_ext(true), || {
fn motions_ignoring_bad_index_council_vote_works() {
with_externalities(&mut ExtBuilder::default().with_council(true).build(), || {
System::set_block_number(3);
let proposal = set_balance_proposal(42);
let hash: H256 = proposal.blake2_256().into();
@@ -428,8 +428,8 @@ mod tests {
}
#[test]
fn revoting_works() {
with_externalities(&mut new_test_ext(true), || {
fn motions_revoting_works() {
with_externalities(&mut ExtBuilder::default().with_council(true).build(), || {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
let hash: H256 = proposal.blake2_256().into();
@@ -462,8 +462,8 @@ mod tests {
}
#[test]
fn disapproval_works() {
with_externalities(&mut new_test_ext(true), || {
fn motions_disapproval_works() {
with_externalities(&mut ExtBuilder::default().with_council(true).build(), || {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
let hash: H256 = proposal.blake2_256().into();
@@ -491,8 +491,8 @@ mod tests {
}
#[test]
fn approval_works() {
with_externalities(&mut new_test_ext(true), || {
fn motions_approval_works() {
with_externalities(&mut ExtBuilder::default().with_council(true).build(), || {
System::set_block_number(1);
let proposal = set_balance_proposal(42);
let hash: H256 = proposal.blake2_256().into();
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -45,7 +45,7 @@ pub trait ResolveHint<AccountId, AccountIndex> {
fn resolve_hint(who: &AccountId) -> Option<AccountIndex>;
}
/// Simple encode-based resolve hint implemenntation.
/// Simple encode-based resolve hint implementation.
pub struct SimpleResolveHint<AccountId, AccountIndex>(PhantomData<(AccountId, AccountIndex)>);
impl<AccountId: Encode, AccountIndex: From<u32>>
ResolveHint<AccountId, AccountIndex> for SimpleResolveHint<AccountId, AccountIndex>