From b75f44123feadd3f12aeefc37d6e8bc6ffd98b14 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Tue, 11 Feb 2020 00:37:28 +0800 Subject: [PATCH 1/2] fix: ci --- .maintain/ci/script.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.maintain/ci/script.sh b/.maintain/ci/script.sh index cb7563645..f5c08efd8 100755 --- a/.maintain/ci/script.sh +++ b/.maintain/ci/script.sh @@ -18,6 +18,7 @@ case $TARGET in # Unit test "native") + rustup target add wasm32-unknown-unknown cargo test --release --all --locked "$@" ;; From de919694950a48faf2944811eddf6da22451b4cc Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Tue, 11 Feb 2020 21:43:08 +0800 Subject: [PATCH 2/2] fix: #176 --- Cargo.lock | 32 ++++++++++++++++ bin/node/cli/src/chain_spec.rs | 15 ++++---- bin/node/runtime/Cargo.toml | 8 ++-- bin/node/runtime/src/lib.rs | 38 +++++++++--------- frame/staking/src/lib.rs | 70 +++++++++++++++++----------------- 5 files changed, 98 insertions(+), 65 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1b45a82e9..74ceb5316 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3193,6 +3193,7 @@ dependencies = [ "pallet-authority-discovery", "pallet-authorship", "pallet-babe", + "pallet-collective", "pallet-contracts", "pallet-contracts-rpc-runtime-api", "pallet-finality-tracker", @@ -3200,6 +3201,7 @@ dependencies = [ "pallet-im-online", "pallet-indices", "pallet-membership", + "pallet-nicks", "pallet-offences", "pallet-randomness-collective-flip", "pallet-session", @@ -3482,6 +3484,22 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-collective" +version = "2.0.0" +source = "git+https://github.com/paritytech/substrate.git?rev=c2fccb36ffacd118fc3502aa93453580a07dc402#c2fccb36ffacd118fc3502aa93453580a07dc402" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "safe-mix", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-contracts" version = "2.0.0" @@ -3613,6 +3631,20 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-nicks" +version = "2.0.0" +source = "git+https://github.com/paritytech/substrate.git?rev=c2fccb36ffacd118fc3502aa93453580a07dc402#c2fccb36ffacd118fc3502aa93453580a07dc402" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "serde", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-offences" version = "2.0.0" diff --git a/bin/node/cli/src/chain_spec.rs b/bin/node/cli/src/chain_spec.rs index 62bba22d6..0164d2a7a 100644 --- a/bin/node/cli/src/chain_spec.rs +++ b/bin/node/cli/src/chain_spec.rs @@ -21,9 +21,9 @@ use hex_literal::hex; use node_runtime::constants::currency::*; use node_runtime::Block; use node_runtime::{ - AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig, GrandpaConfig, ImOnlineConfig, - IndicesConfig, KtonConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig, SudoConfig, SystemConfig, - WASM_BINARY, + AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig, CouncilConfig, GrandpaConfig, + ImOnlineConfig, IndicesConfig, KtonConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig, SudoConfig, + SystemConfig, WASM_BINARY, }; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sc_chain_spec::ChainSpecExtension; @@ -137,6 +137,7 @@ pub fn darwinia_genesis( } else { vec![initial_authorities[0].clone().1, initial_authorities[1].clone().1] }; + let num_endowed_accounts = endowed_accounts.len(); const RING_ENDOWMENT: Balance = 20_000_000 * COIN; const KTON_ENDOWMENT: Balance = 10 * COIN; @@ -166,10 +167,10 @@ pub fn darwinia_genesis( .collect::>(), }), // pallet_democracy: Some(DemocracyConfig::default()), - // pallet_collective_Instance1: Some(CouncilConfig { - // members: endowed_accounts.iter().cloned().collect::>()[..(num_endowed_accounts + 1) / 2].to_vec(), - // phantom: Default::default(), - // }), + pallet_collective_Instance1: Some(CouncilConfig { + members: endowed_accounts.iter().cloned().collect::>()[..(num_endowed_accounts + 1) / 2].to_vec(), + phantom: Default::default(), + }), // pallet_collective_Instance2: Some(TechnicalCommitteeConfig { // members: endowed_accounts.iter().cloned().collect::>()[..(num_endowed_accounts + 1) / 2].to_vec(), // phantom: Default::default(), diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index 792448d70..21c91040f 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -35,7 +35,7 @@ node-primitives = { default-features = false, path = "../primitives" } pallet-authority-discovery = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } pallet-authorship = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } pallet-babe = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } -#pallet-collective = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } +pallet-collective = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } pallet-contracts = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } pallet-contracts-rpc-runtime-api = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } frame-executive = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } @@ -44,7 +44,7 @@ pallet-grandpa = { version = "2.0.0", default-features = false, git = "https://g pallet-im-online = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } pallet-indices = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } pallet-membership = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } -#pallet-nicks = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } +pallet-nicks = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } pallet-offences = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } pallet-randomness-collective-flip = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } pallet-session = { version = "2.0.0", default-features = false, features = ["historical"], git = "https://github.com/paritytech/substrate.git", rev = "c2fccb36ffacd118fc3502aa93453580a07dc402" } @@ -79,7 +79,7 @@ std = [ "pallet-babe/std", "sp-block-builder/std", "codec/std", -# "pallet-collective/std", + "pallet-collective/std", "pallet-contracts-rpc-runtime-api/std", "pallet-contracts/std", "frame-executive/std", @@ -89,7 +89,7 @@ std = [ "pallet-indices/std", "sp-inherents/std", "pallet-membership/std", -# "pallet-nicks/std", + "pallet-nicks/std", "node-primitives/std", "sp-offchain/std", "pallet-offences/std", diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 684494eb8..e4c971e7f 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -246,12 +246,12 @@ impl pallet_session::historical::Trait for Runtime { type FullIdentificationOf = ExposureOf; } -//type CouncilCollective = pallet_collective::Instance1; -//impl pallet_collective::Trait for Runtime { -// type Origin = Origin; -// type Proposal = Call; -// type Event = Event; -//} +type CouncilCollective = pallet_collective::Instance1; +impl pallet_collective::Trait for Runtime { + type Origin = Origin; + type Proposal = Call; + type Event = Event; +} //type TechnicalCollective = pallet_collective::Instance2; //impl pallet_collective::Trait for Runtime { @@ -379,15 +379,15 @@ parameter_types! { pub const MaxLength: usize = 16; } -//impl pallet_nicks::Trait for Runtime { -// type Event = Event; -// type Currency = Balances; -// type ReservationFee = ReservationFee; -// type Slashed = Treasury; -// type ForceOrigin = pallet_collective::EnsureMember; -// type MinLength = MinLength; -// type MaxLength = MaxLength; -//} +impl pallet_nicks::Trait for Runtime { + type Event = Event; + type Currency = Balances; + type ReservationFee = ReservationFee; + type Slashed = MockTreasury; + type ForceOrigin = pallet_collective::EnsureMember; + type MinLength = MinLength; + type MaxLength = MaxLength; +} impl frame_system::offchain::CreateTransaction for Runtime { type Public = ::Signer; @@ -465,8 +465,8 @@ impl pallet_staking::Trait for Runtime { type BondingDurationInEra = BondingDurationInEra; type BondingDurationInBlockNumber = BondingDurationInBlockNumber; type SlashDeferDuration = SlashDeferDuration; - // /// A super-majority of the council can cancel the slash. - // type SlashCancelOrigin = pallet_collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>; + /// 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 RingRewardRemainder = (); @@ -494,7 +494,7 @@ construct_runtime!( Indices: pallet_indices, TransactionPayment: pallet_transaction_payment::{Module, Storage}, Session: pallet_session::{Module, Call, Storage, Event, Config}, -// Council: pallet_collective::::{Module, Call, Storage, Origin, Event, Config}, + Council: pallet_collective::::{Module, Call, Storage, Origin, Event, Config}, // TechnicalCommittee: pallet_collective::::{Module, Call, Storage, Origin, Event, Config}, // TechnicalMembership: pallet_membership::::{Module, Call, Storage, Event, Config}, FinalityTracker: pallet_finality_tracker::{Module, Call, Inherent}, @@ -506,7 +506,7 @@ construct_runtime!( AuthorityDiscovery: pallet_authority_discovery::{Module, Call, Config}, Offences: pallet_offences::{Module, Call, Storage, Event}, RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage}, -// Nicks: pallet_nicks::{Module, Call, Storage, Event}, + Nicks: pallet_nicks::{Module, Call, Storage, Event}, Balances: pallet_ring::{default, Error}, Kton: pallet_kton::{default, Error}, diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index fe021bb53..b4dab64bd 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -668,8 +668,8 @@ pub trait Trait: frame_system::Trait { /// applied immediately, without opportunity for intervention. type SlashDeferDuration: Get; - // /// The origin which can cancel a deferred slash. Root can always do this. - // type SlashCancelOrigin: EnsureOrigin; + /// The origin which can cancel a deferred slash. Root can always do this. + type SlashCancelOrigin: EnsureOrigin; /// Interface for interacting with a session module. type SessionInterface: self::SessionInterface; @@ -1501,39 +1501,39 @@ decl_module! { ForceEra::put(Forcing::ForceAlways); } -// /// Cancel enactment of a deferred slash. Can be called by either the root origin or -// /// the `T::SlashCancelOrigin`. -// /// passing the era and indices of the slashes for that era to kill. -// /// -// /// # -// /// - One storage write. -// /// # -// #[weight = SimpleDispatchInfo::FreeOperational] -// fn cancel_deferred_slash(origin, era: EraIndex, slash_indices: Vec) { -// T::SlashCancelOrigin::try_origin(origin) -// .map(|_| ()) -// .or_else(ensure_root)?; -// -// let mut slash_indices = slash_indices; -// slash_indices.sort_unstable(); -// let mut unapplied = ::UnappliedSlashes::get(&era); -// -// for (removed, index) in slash_indices.into_iter().enumerate() { -// let index = index as usize; -// -// // if `index` is not duplicate, `removed` must be <= index. -// ensure!(removed <= index, Error::::DuplicateIndex); -// -// // all prior removals were from before this index, since the -// // list is sorted. -// let index = index - removed; -// ensure!(index < unapplied.len(), Error::::InvalidSlashIndex); -// -// unapplied.remove(index); -// } -// -// ::UnappliedSlashes::insert(&era, &unapplied); -// } + /// Cancel enactment of a deferred slash. Can be called by either the root origin or + /// the `T::SlashCancelOrigin`. + /// passing the era and indices of the slashes for that era to kill. + /// + /// # + /// - One storage write. + /// # + #[weight = SimpleDispatchInfo::FreeOperational] + fn cancel_deferred_slash(origin, era: EraIndex, slash_indices: Vec) { + T::SlashCancelOrigin::try_origin(origin) + .map(|_| ()) + .or_else(ensure_root)?; + + let mut slash_indices = slash_indices; + slash_indices.sort_unstable(); + let mut unapplied = ::UnappliedSlashes::get(&era); + + for (removed, index) in slash_indices.into_iter().enumerate() { + let index = index as usize; + + // if `index` is not duplicate, `removed` must be <= index. + ensure!(removed <= index, Error::::DuplicateIndex); + + // all prior removals were from before this index, since the + // list is sorted. + let index = index - removed; + ensure!(index < unapplied.len(), Error::::InvalidSlashIndex); + + unapplied.remove(index); + } + + ::UnappliedSlashes::insert(&era, &unapplied); + } } }