Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add elections-phragmen #292

Merged
merged 4 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
34 changes: 33 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"frame/balances/ring",
"frame/chainrelay/eth/backing",
"frame/chainrelay/eth/relay",
"frame/elections-phragmen",
"frame/staking",
"frame/support",
"frame/treasury",
Expand Down
124 changes: 63 additions & 61 deletions bin/node/cli/res/canary.json

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use node_runtime::Block;
use node_runtime::{
AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig, CouncilConfig, EthBackingConfig,
EthRelayConfig, GrandpaConfig, ImOnlineConfig, IndicesConfig, KtonConfig, SessionConfig, SessionKeys, StakerStatus,
StakingConfig, SudoConfig, SystemConfig, WASM_BINARY,
StakingConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, WASM_BINARY,
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sc_chain_spec::ChainSpecExtension;
Expand Down Expand Up @@ -98,7 +98,7 @@ pub fn get_authority_keys_from_seed(

/// Helper function to create GenesisConfig for darwinia
/// is_testnet: under test net we will use Alice & Bob as seed to generate keys,
/// but in production enviroment, these accounts will use preset keys
/// but in production enviroment, these accounts will use preset keys
pub fn darwinia_genesis(
initial_authorities: Vec<(
AccountId,
Expand Down Expand Up @@ -154,6 +154,10 @@ pub fn darwinia_genesis(
members: endowed_accounts.iter().cloned().collect::<Vec<_>>()[..(num_endowed_accounts + 1) / 2].to_vec(),
phantom: Default::default(),
}),
pallet_collective_Instance2: Some(TechnicalCommitteeConfig {
members: endowed_accounts.iter().cloned().collect::<Vec<_>>()[..(num_endowed_accounts + 1) / 2].to_vec(),
phantom: Default::default(),
}),
pallet_contracts: Some(ContractsConfig {
current_schedule: pallet_contracts::Schedule {
enable_println, // this should only be enabled on development chains
Expand All @@ -166,6 +170,7 @@ pub fn darwinia_genesis(
pallet_im_online: Some(ImOnlineConfig { keys: vec![] }),
pallet_authority_discovery: Some(AuthorityDiscoveryConfig { keys: vec![] }),
pallet_grandpa: Some(GrandpaConfig { authorities: vec![] }),
pallet_membership_Instance1: Some(Default::default()),

pallet_eth_backing: Some(EthBackingConfig {
ring_redeem_address: hex!["dbc888d701167cbfb86486c516aafbefc3a4de6e"].into(),
Expand Down
2 changes: 1 addition & 1 deletion bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ frame-executive = { version = "2.0.0", default-features = false, git = "https://
frame-support = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
frame-system = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
frame-system-rpc-runtime-api = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }

pallet-authority-discovery = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
pallet-authorship = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
pallet-babe = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
pallet-collective = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
pallet-contracts = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
pallet-contracts-rpc-runtime-api = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
pallet-elections-phragmen = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
pallet-finality-tracker = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
pallet-grandpa = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
pallet-im-online = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
Expand Down
88 changes: 70 additions & 18 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,73 @@ impl pallet_collective::Trait<CouncilCollective> for Runtime {
type Event = Event;
}

//type TechnicalCollective = pallet_collective::Instance2;
//impl pallet_collective::Trait<TechnicalCollective> for Runtime {
// type Origin = Origin;
// type Proposal = Call;
// type Event = Event;
//}
// mod support_kton_in_futures {
// use sp_runtime::traits::Convert;
//
//impl pallet_membership::Trait<pallet_membership::Instance1> for Runtime {
// type Event = Event;
// type AddOrigin = pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
// type RemoveOrigin = pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
// type SwapOrigin = pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
// type ResetOrigin = pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
// type MembershipInitialized = TechnicalCommittee;
// type MembershipChanged = TechnicalCommittee;
//}
// use crate::Balance;
//
// /// Struct that handles the conversion of Balance -> `u64`. This is used for staking's election
// /// calculation.
// pub struct CurrencyToVoteHandler;
//
// impl CurrencyToVoteHandler {
// fn factor() -> Balance {
// (Balances::total_issuance() / u64::max_value() as Balance).max(1)
// }
// }
//
// impl Convert<Balance, u64> for CurrencyToVoteHandler {
// fn convert(x: Balance) -> u64 {
// (x / Self::factor()) as u64
// }
// }
//
// impl Convert<u128, Balance> for CurrencyToVoteHandler {
// fn convert(x: u128) -> Balance {
// x * Self::factor()
// }
// }
// }
//
// parameter_types! {
// pub const CandidacyBond: Balance = 10 * COIN;
// pub const VotingBond: Balance = 1 * COIN;
// pub const TermDuration: BlockNumber = 7 * DAYS;
// pub const DesiredMembers: u32 = 13;
// pub const DesiredRunnersUp: u32 = 7;
// }
//
// impl pallet_elections_phragmen::Trait for Runtime {
// type Event = Event;
// type Currency = Balances;
// type ChangeMembers = Council;
// type CurrencyToVote = support_kton_in_futures::CurrencyToVoteHandler;
// type CandidacyBond = CandidacyBond;
// type VotingBond = VotingBond;
// type LoserCandidate = ();
// type BadReport = ();
// type KickedMember = ();
// type DesiredMembers = DesiredMembers;
// type DesiredRunnersUp = DesiredRunnersUp;
// type TermDuration = TermDuration;
// }

type TechnicalCollective = pallet_collective::Instance2;
impl pallet_collective::Trait<TechnicalCollective> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
}

impl pallet_membership::Trait<pallet_membership::Instance1> for Runtime {
type Event = Event;
type AddOrigin = pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
type RemoveOrigin = pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
type SwapOrigin = pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
type ResetOrigin = pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
type MembershipInitialized = TechnicalCommittee;
type MembershipChanged = TechnicalCommittee;
}

parameter_types! {
pub const ContractTransferFee: Balance = 1 * MILLI;
Expand Down Expand Up @@ -500,8 +551,9 @@ construct_runtime!(
TransactionPayment: pallet_transaction_payment::{Module, Storage},
Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
Council: pallet_collective::<Instance1>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
// TechnicalCommittee: pallet_collective::<Instance2>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
// TechnicalMembership: pallet_membership::<Instance1>::{Module, Call, Storage, Event<T>, Config<T>},
// Elections: pallet_elections_phragmen::{Module, Call, Storage, Event<T>},
TechnicalCommittee: pallet_collective::<Instance2>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
TechnicalMembership: pallet_membership ::<Instance1>,
FinalityTracker: pallet_finality_tracker::{Module, Call, Inherent},
Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},
Contracts: pallet_contracts,
Expand Down Expand Up @@ -673,7 +725,7 @@ impl_runtime_apis! {
Contracts::get_storage(address, key).map_err(|rpc_err| {
use pallet_contracts::GetStorageError;
use pallet_contracts_rpc_runtime_api::{GetStorageError as RpcGetStorageError};
/// Map the contract error into the RPC layer error.
// Map the contract error into the RPC layer error.
match rpc_err {
GetStorageError::ContractDoesntExist => RpcGetStorageError::ContractDoesntExist,
GetStorageError::IsTombstone => RpcGetStorageError::IsTombstone,
Expand Down
37 changes: 37 additions & 0 deletions frame/elections-phragmen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "pallet-elections-phragmen"
version = "2.0.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"

[dependencies]
# crates.io
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }

# github.com
frame-support = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
frame-system = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sp-phragmen = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sp-runtime = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sp-std = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }

[dev-dependencies]
hex-literal = "0.2.1"
serde = { version = "1.0.101" }

sp-core = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sp-io = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
substrate-test-utils = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }

darwinia-ring = { path = "../balances/ring" }

[features]
default = ["std"]
std = [
"codec/std",
"frame-support/std",
"sp-runtime/std",
"sp-phragmen/std",
"frame-system/std",
"sp-std/std",
]
Loading