Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
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
30 changes: 13 additions & 17 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdj
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
use sp_api::impl_runtime_apis;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_core::{
crypto::KeyTypeId,
u32_trait::{_1, _2, _3, _4, _5},
OpaqueMetadata,
};
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_inherents::{CheckInherentsResult, InherentData};
use sp_runtime::{
create_runtime_str,
Expand Down Expand Up @@ -550,7 +546,7 @@ impl pallet_staking::Config for Runtime {
/// A super-majority of the council can cancel the slash.
type SlashCancelOrigin = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>,
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 4>,
>;
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
Expand Down Expand Up @@ -796,30 +792,30 @@ impl pallet_democracy::Config for Runtime {
type MinimumDeposit = MinimumDeposit;
/// A straight majority of the council can decide what their next motion is.
type ExternalOrigin =
pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>;
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 2>;
/// A super-majority can have the next scheduled referendum be a straight majority-carries vote.
type ExternalMajorityOrigin =
pallet_collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>;
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 4>;
/// A unanimous council can have the next scheduled referendum be a straight default-carries
/// (NTB) vote.
type ExternalDefaultOrigin =
pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, CouncilCollective>;
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 1, 1>;
/// Two thirds of the technical committee can have an ExternalMajority/ExternalDefault vote
/// be tabled immediately and with a shorter voting/enactment period.
type FastTrackOrigin =
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechnicalCollective>;
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 2, 3>;
type InstantOrigin =
pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>;
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 1, 1>;
type InstantAllowed = frame_support::traits::ConstBool<true>;
type FastTrackVotingPeriod = FastTrackVotingPeriod;
// To cancel a proposal which has been passed, 2/3 of the council must agree to it.
type CancellationOrigin =
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>;
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 2, 3>;
// To cancel a proposal before it has been passed, the technical committee must be unanimous or
// Root must agree.
type CancelProposalOrigin = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>,
pallet_collective::EnsureProportionAtLeast<AccountId, TechnicalCollective, 1, 1>,
>;
type BlacklistOrigin = EnsureRoot<AccountId>;
// Any single technical committee member may veto a coming council proposal, however they can
Expand Down Expand Up @@ -909,7 +905,7 @@ impl pallet_collective::Config<TechnicalCollective> for Runtime {

type EnsureRootOrHalfCouncil = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>,
pallet_collective::EnsureProportionMoreThan<AccountId, CouncilCollective, 1, 2>,
>;
impl pallet_membership::Config<pallet_membership::Instance1> for Runtime {
type Event = Event;
Expand Down Expand Up @@ -951,11 +947,11 @@ impl pallet_treasury::Config for Runtime {
type Currency = Balances;
type ApproveOrigin = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_3, _5, AccountId, CouncilCollective>,
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 5>,
>;
type RejectOrigin = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>,
pallet_collective::EnsureProportionMoreThan<AccountId, CouncilCollective, 1, 2>,
>;
type Event = Event;
type OnSlash = ();
Expand Down Expand Up @@ -1226,7 +1222,7 @@ impl pallet_society::Config for Runtime {
type RotationPeriod = RotationPeriod;
type MaxLockDuration = MaxLockDuration;
type FounderSetOrigin =
pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
pallet_collective::EnsureProportionMoreThan<AccountId, CouncilCollective, 1, 2>;
type SuspensionJudgementOrigin = pallet_society::EnsureFounder<Runtime>;
type MaxCandidateIntake = MaxCandidateIntake;
type ChallengePeriod = ChallengePeriod;
Expand Down
35 changes: 17 additions & 18 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#![recursion_limit = "128"]

use scale_info::TypeInfo;
use sp_core::u32_trait::Value as U32;
use sp_io::storage;
use sp_runtime::{traits::Hash, RuntimeDebug};
use sp_std::{marker::PhantomData, prelude::*, result};
Expand Down Expand Up @@ -1011,43 +1010,43 @@ impl<
}
}

pub struct EnsureMembers<N: U32, AccountId, I: 'static>(PhantomData<(N, AccountId, I)>);
pub struct EnsureMembers<AccountId, I: 'static, const N: u32>(PhantomData<(AccountId, I)>);
impl<
O: Into<Result<RawOrigin<AccountId, I>, O>> + From<RawOrigin<AccountId, I>>,
N: U32,
AccountId,
I,
> EnsureOrigin<O> for EnsureMembers<N, AccountId, I>
const N: u32,
> EnsureOrigin<O> for EnsureMembers<AccountId, I, N>
{
type Success = (MemberCount, MemberCount);
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
RawOrigin::Members(n, m) if n >= N::VALUE => Ok((n, m)),
RawOrigin::Members(n, m) if n >= N => Ok((n, m)),
r => Err(O::from(r)),
})
}

#[cfg(feature = "runtime-benchmarks")]
fn successful_origin() -> O {
O::from(RawOrigin::Members(N::VALUE, N::VALUE))
O::from(RawOrigin::Members(N, N))
}
}

pub struct EnsureProportionMoreThan<N: U32, D: U32, AccountId, I: 'static>(
PhantomData<(N, D, AccountId, I)>,
pub struct EnsureProportionMoreThan<AccountId, I: 'static, const N: u32, const D: u32>(
PhantomData<(AccountId, I)>,
);
impl<
O: Into<Result<RawOrigin<AccountId, I>, O>> + From<RawOrigin<AccountId, I>>,
N: U32,
D: U32,
AccountId,
I,
> EnsureOrigin<O> for EnsureProportionMoreThan<N, D, AccountId, I>
const N: u32,
const D: u32,
> EnsureOrigin<O> for EnsureProportionMoreThan<AccountId, I, N, D>
{
type Success = ();
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
RawOrigin::Members(n, m) if n * D::VALUE > N::VALUE * m => Ok(()),
RawOrigin::Members(n, m) if n * D > N * m => Ok(()),
r => Err(O::from(r)),
})
}
Expand All @@ -1058,21 +1057,21 @@ impl<
}
}

pub struct EnsureProportionAtLeast<N: U32, D: U32, AccountId, I: 'static>(
PhantomData<(N, D, AccountId, I)>,
pub struct EnsureProportionAtLeast<AccountId, I: 'static, const N: u32, const D: u32>(
PhantomData<(AccountId, I)>,
);
impl<
O: Into<Result<RawOrigin<AccountId, I>, O>> + From<RawOrigin<AccountId, I>>,
N: U32,
D: U32,
AccountId,
I,
> EnsureOrigin<O> for EnsureProportionAtLeast<N, D, AccountId, I>
const N: u32,
const D: u32,
> EnsureOrigin<O> for EnsureProportionAtLeast<AccountId, I, N, D>
{
type Success = ();
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
RawOrigin::Members(n, m) if n * D::VALUE >= N::VALUE * m => Ok(()),
RawOrigin::Members(n, m) if n * D >= N * m => Ok(()),
r => Err(O::from(r)),
})
}
Expand Down
7 changes: 2 additions & 5 deletions frame/collective/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ use frame_support::{
Hashable,
};
use frame_system::{EventRecord, Phase};
use sp_core::{
u32_trait::{_3, _4},
H256,
};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
Expand Down Expand Up @@ -142,7 +139,7 @@ impl Config<Instance2> for Test {
}
impl mock_democracy::Config for Test {
type Event = Event;
type ExternalMajorityOrigin = EnsureProportionAtLeast<_3, _4, u64, Instance1>;
type ExternalMajorityOrigin = EnsureProportionAtLeast<u64, Instance1, 3, 4>;
}
impl Config for Test {
type Origin = Origin;
Expand Down
15 changes: 7 additions & 8 deletions frame/support/src/traits/tokens/imbalance/split_two_ways.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,26 @@
//! Means for splitting an imbalance into two and hanlding them differently.
use super::super::imbalance::{Imbalance, OnUnbalanced};
use sp_core::u32_trait::Value as U32;
use sp_runtime::traits::Saturating;
use sp_std::{marker::PhantomData, ops::Div};

/// Split an unbalanced amount two ways between a common divisor.
pub struct SplitTwoWays<Balance, Imbalance, Part1, Target1, Part2, Target2>(
PhantomData<(Balance, Imbalance, Part1, Target1, Part2, Target2)>,
pub struct SplitTwoWays<Balance, Imbalance, Target1, Target2, const PART1: u32, const PART2: u32>(
PhantomData<(Balance, Imbalance, Target1, Target2)>,
);

impl<
Balance: From<u32> + Saturating + Div<Output = Balance>,
I: Imbalance<Balance>,
Part1: U32,
Target1: OnUnbalanced<I>,
Part2: U32,
Target2: OnUnbalanced<I>,
> OnUnbalanced<I> for SplitTwoWays<Balance, I, Part1, Target1, Part2, Target2>
const PART1: u32,
const PART2: u32,
> OnUnbalanced<I> for SplitTwoWays<Balance, I, Target1, Target2, PART1, PART2>
{
fn on_nonzero_unbalanced(amount: I) {
let total: u32 = Part1::VALUE + Part2::VALUE;
let amount1 = amount.peek().saturating_mul(Part1::VALUE.into()) / total.into();
let total: u32 = PART1 + PART2;
let amount1 = amount.peek().saturating_mul(PART1.into()) / total.into();
let (imb1, imb2) = amount.split(amount1);
Target1::on_unbalanced(imb1);
Target2::on_unbalanced(imb2);
Expand Down
2 changes: 0 additions & 2 deletions primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ pub use hashing::{blake2_128, blake2_256, keccak_256, twox_128, twox_256, twox_6
pub mod crypto;
pub mod hexdisplay;

pub mod u32_trait;

pub mod ecdsa;
pub mod ed25519;
pub mod hash;
Expand Down
Loading