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 all commits
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
478 changes: 254 additions & 224 deletions Cargo.lock

Large diffs are not rendered by default.

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
126 changes: 64 additions & 62 deletions bin/node/cli/res/canary.json

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use hex_literal::hex;
use node_runtime::constants::currency::*;
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,
AuthorityDiscoveryConfig, BabeConfig, ContractsConfig, CouncilConfig, EthBackingConfig, EthRelayConfig,
GrandpaConfig, ImOnlineConfig, IndicesConfig, KtonConfig, RingConfig, SessionConfig, SessionKeys, StakerStatus,
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 All @@ -188,7 +193,7 @@ pub fn darwinia_genesis(
.collect(),
vesting: vec![],
}),
pallet_ring: Some(BalancesConfig {
pallet_ring: Some(RingConfig {
balances: endowed_accounts
.iter()
.cloned()
Expand Down
4 changes: 2 additions & 2 deletions bin/node/cli/src/factory_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rand::{Rng, SeedableRng};
use codec::{Decode, Encode};
use node_primitives::Signature;
use node_runtime::{
BalancesCall, Call, CheckedExtrinsic, ExistentialDeposit, MinimumPeriod, SignedExtra, UncheckedExtrinsic,
Call, CheckedExtrinsic, ExistentialDeposit, MinimumPeriod, RingCall, SignedExtra, UncheckedExtrinsic,
};
use node_transaction_factory::modes::Mode;
use node_transaction_factory::RuntimeAdapter;
Expand Down Expand Up @@ -144,7 +144,7 @@ impl RuntimeAdapter for FactoryState<Number> {
sign::<Self>(
CheckedExtrinsic {
signed: Some((sender.clone(), Self::build_extra(index, phase))),
function: Call::Balances(BalancesCall::transfer(
function: Call::Ring(RingCall::transfer(
pallet_indices::address::Address::Id(destination.clone().into()),
(*amount).into(),
)),
Expand Down
5 changes: 3 additions & 2 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ serde = { version = "1.0.102", optional = true }
# primitives
sp-api = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sp-authority-discovery = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sp-block-builder = { git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111", default-features = false}
sp-block-builder = { git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111", default-features = false }
sp-consensus-babe = { version = "0.8", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sp-core = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sp-inherents = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
Expand All @@ -36,7 +36,6 @@ 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" }
Expand All @@ -58,6 +57,7 @@ pallet-transaction-payment = { version = "2.0.0", default-features = false, git
pallet-transaction-payment-rpc-runtime-api = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
pallet-utility = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }

pallet-elections-phragmen = { package = "darwinia-elections-phragmen", default-features = false, path = "../../../frame/elections-phragmen" }
pallet-eth-backing = { package = "darwinia-eth-backing", default-features = false, path = "../../../frame/chainrelay/eth/backing" }
pallet-eth-relay = { package = "darwinia-eth-relay", default-features = false, path = "../../../frame/chainrelay/eth/relay" }
pallet-kton = { package = "darwinia-kton", default-features = false, path = "../../../frame/balances/kton" }
Expand Down Expand Up @@ -97,6 +97,7 @@ std = [
"pallet-transaction-payment/std",
"pallet-utility/std",

"pallet-elections-phragmen/std",
"pallet-eth-backing/std",
"pallet-eth-relay/std",
"pallet-kton/std",
Expand Down
32 changes: 30 additions & 2 deletions bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,41 @@ use sp_runtime::{
{Fixed64, Perbill},
};

use crate::{Authorship, Balances, MaximumBlockWeight, NegativeImbalance, System};
use crate::{Authorship, MaximumBlockWeight, NegativeImbalance, Ring, System};
use node_primitives::Balance;

pub struct Author;
impl OnUnbalanced<NegativeImbalance> for Author {
fn on_nonzero_unbalanced(amount: NegativeImbalance) {
Balances::resolve_creating(&Authorship::author(), amount);
Ring::resolve_creating(&Authorship::author(), amount);
}
}

pub mod support_kton_in_the_future {
use sp_runtime::traits::Convert;

use crate::*;

/// Struct that handles the conversion of Balance -> `u64`. This is used for staking's election
/// calculation.
pub struct CurrencyToVoteHandler;

impl CurrencyToVoteHandler {
fn factor() -> Balance {
(Ring::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()
}
}
}

Expand Down
90 changes: 57 additions & 33 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use pallet_timestamp::Call as TimestampCall;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;

pub use pallet_ring::Call as BalancesCall;
pub use pallet_ring::Call as RingCall;
pub use pallet_staking::StakerStatus;

use constants::{currency::*, supply::*, time::*};
Expand All @@ -25,7 +25,7 @@ use frame_support::{
weights::Weight,
};
use frame_system::offchain::TransactionSubmitter;
use impls::{Author, LinearWeightToFee, TargetedFeeAdjustment};
use impls::{support_kton_in_the_future, Author, LinearWeightToFee, TargetedFeeAdjustment};
use pallet_contracts_rpc_runtime_api::ContractExecResult;
use pallet_grandpa::{fg_primitives, AuthorityList as GrandpaAuthorityList};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
Expand Down Expand Up @@ -79,7 +79,7 @@ pub fn native_version() -> NativeVersion {
}
}

type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;
type NegativeImbalance = <Ring as Currency<AccountId>>::NegativeImbalance;

pub type DealWithFees = SplitTwoWays<
Balance,
Expand Down Expand Up @@ -129,7 +129,7 @@ parameter_types! {
impl pallet_utility::Trait for Runtime {
type Event = Event;
type Call = Call;
type Currency = Balances;
type Currency = Ring;
type MultisigDepositBase = MultisigDepositBase;
type MultisigDepositFactor = MultisigDepositFactor;
type MaxSignatories = MaxSignatories;
Expand All @@ -148,7 +148,7 @@ impl pallet_babe::Trait for Runtime {

impl pallet_indices::Trait for Runtime {
type AccountIndex = AccountIndex;
type IsDeadAccount = Balances;
type IsDeadAccount = Ring;
type ResolveHint = pallet_indices::SimpleResolveHint<Self::AccountId, Self::AccountIndex>;
type Event = Event;
}
Expand All @@ -163,7 +163,7 @@ parameter_types! {
}

impl pallet_transaction_payment::Trait for Runtime {
type Currency = Balances;
type Currency = Ring;
type OnTransactionPayment = DealWithFees;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
Expand Down Expand Up @@ -228,22 +228,45 @@ 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;
//}
//
//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 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 = Ring;
type ChangeMembers = Council;
type CurrencyToVote = support_kton_in_the_future::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 All @@ -258,7 +281,7 @@ parameter_types! {
}

impl pallet_contracts::Trait for Runtime {
type Currency = Balances;
type Currency = Ring;
type Time = Timestamp;
type Randomness = RandomnessCollectiveFlip;
type Call = Call;
Expand Down Expand Up @@ -337,7 +360,7 @@ parameter_types! {

impl pallet_nicks::Trait for Runtime {
type Event = Event;
type Currency = Balances;
type Currency = Ring;
type ReservationFee = ReservationFee;
type Slashed = Treasury;
type ForceOrigin = pallet_collective::EnsureMember<AccountId, CouncilCollective>;
Expand Down Expand Up @@ -385,7 +408,7 @@ impl pallet_eth_backing::Trait for Runtime {
type DetermineAccountId = pallet_eth_backing::AccountIdDeterminator<Runtime>;
type EthRelay = EthRelay;
type OnDepositRedeem = Staking;
type Ring = Balances;
type Ring = Ring;
type RingReward = ();
type Kton = Kton;
type KtonReward = ();
Expand All @@ -410,8 +433,8 @@ parameter_types! {
impl pallet_kton::Trait for Runtime {
type Balance = Balance;
type Event = Event;
type RingCurrency = Balances;
type TransferPayment = Balances;
type RingCurrency = Ring;
type TransferPayment = Ring;
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
}
Expand Down Expand Up @@ -449,7 +472,7 @@ impl pallet_staking::Trait for Runtime {
/// A super-majority of the council can cancel the slash.
type SlashCancelOrigin = pallet_collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>;
type SessionInterface = Self;
type RingCurrency = Balances;
type RingCurrency = Ring;
type RingRewardRemainder = Treasury;
// send the slashed funds to the treasury.
type RingSlash = Treasury;
Expand All @@ -473,7 +496,7 @@ parameter_types! {
}

impl pallet_treasury::Trait for Runtime {
type RingCurrency = Balances;
type RingCurrency = Ring;
type KtonCurrency = Kton;
type ApproveOrigin = pallet_collective::EnsureMembers<_4, AccountId, CouncilCollective>;
type RejectOrigin = pallet_collective::EnsureMembers<_2, AccountId, CouncilCollective>;
Expand All @@ -500,8 +523,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 All @@ -515,7 +539,7 @@ construct_runtime!(
EthBacking: pallet_eth_backing,
EthRelay: pallet_eth_relay,
Kton: pallet_kton,
Balances: pallet_ring,
Ring: pallet_ring,
Staking: pallet_staking,
Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},
}
Expand Down Expand Up @@ -673,7 +697,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
2 changes: 1 addition & 1 deletion frame/chainrelay/eth/backing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ codec = { package = "parity-scale-codec", version = "1.0.0", default-features =
serde = { version = "1.0.101", optional = true }

# github.com
ethabi = { default-features = false, git = "https://github.com/AurevoirXavier/ethabi.git", branch = "with_no_std" }
ethabi = { default-features = false, git = "https://github.com/darwinia-network/ethabi.git", branch = "with_no_std" }
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-core = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
Expand Down
Loading