Companion for 10379 (EnsureOneOf) (#4405)

* new ensure one of

* fmt

* Update lib.rs

* Update substrate

Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
Shawn Tabrizi
2021-12-01 18:32:37 -04:00
committed by GitHub
parent 7746039392
commit 3771b90ff1
4 changed files with 177 additions and 198 deletions
+163 -163
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -659,9 +659,9 @@ mod tests {
assert_noop, assert_ok, assert_storage_noop, assert_noop, assert_ok, assert_storage_noop,
dispatch::DispatchError::BadOrigin, dispatch::DispatchError::BadOrigin,
ord_parameter_types, parameter_types, ord_parameter_types, parameter_types,
traits::{OnFinalize, OnInitialize}, traits::{EnsureOneOf, OnFinalize, OnInitialize},
}; };
use frame_system::{EnsureOneOf, EnsureRoot, EnsureSignedBy}; use frame_system::{EnsureRoot, EnsureSignedBy};
use pallet_balances; use pallet_balances;
use primitives::v1::{BlockNumber, Header, Id as ParaId}; use primitives::v1::{BlockNumber, Header, Id as ParaId};
use sp_core::H256; use sp_core::H256;
@@ -821,7 +821,7 @@ mod tests {
pub const Six: u64 = 6; pub const Six: u64 = 6;
} }
type RootOrSix = EnsureOneOf<u64, EnsureRoot<u64>, EnsureSignedBy<Six, u64>>; type RootOrSix = EnsureOneOf<EnsureRoot<u64>, EnsureSignedBy<Six, u64>>;
thread_local! { thread_local! {
pub static LAST_RANDOM: RefCell<Option<(H256, u32)>> = RefCell::new(None); pub static LAST_RANDOM: RefCell<Option<(H256, u32)>> = RefCell::new(None);
+3 -11
View File
@@ -50,13 +50,13 @@ use beefy_primitives::crypto::AuthorityId as BeefyId;
use frame_support::{ use frame_support::{
construct_runtime, match_type, parameter_types, construct_runtime, match_type, parameter_types,
traits::{ traits::{
Contains, Everything, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, Nothing, Contains, EnsureOneOf, Everything, InstanceFilter, KeyOwnerProofSystem, LockIdentifier,
OnRuntimeUpgrade, PrivilegeCmp, Nothing, OnRuntimeUpgrade, PrivilegeCmp,
}, },
weights::Weight, weights::Weight,
PalletId, RuntimeDebug, PalletId, RuntimeDebug,
}; };
use frame_system::{EnsureOneOf, EnsureRoot}; use frame_system::EnsureRoot;
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_mmr_primitives as mmr; use pallet_mmr_primitives as mmr;
@@ -150,7 +150,6 @@ impl Contains<Call> for BaseFilter {
} }
type MoreThanHalfCouncil = EnsureOneOf< type MoreThanHalfCouncil = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>, pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>,
>; >;
@@ -193,7 +192,6 @@ parameter_types! {
} }
type ScheduleOrigin = EnsureOneOf< type ScheduleOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>, pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>,
>; >;
@@ -428,7 +426,6 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
>; >;
type BenchmarkingConfig = runtime_common::elections::BenchmarkConfig; type BenchmarkingConfig = runtime_common::elections::BenchmarkConfig;
type ForceOrigin = EnsureOneOf< type ForceOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>, pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>,
>; >;
@@ -521,7 +518,6 @@ parameter_types! {
} }
type SlashCancelOrigin = EnsureOneOf< type SlashCancelOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>, pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>,
>; >;
@@ -602,7 +598,6 @@ impl pallet_democracy::Config for Runtime {
type FastTrackVotingPeriod = FastTrackVotingPeriod; type FastTrackVotingPeriod = FastTrackVotingPeriod;
// To cancel a proposal which has been passed, 2/3 of the council must agree to it. // To cancel a proposal which has been passed, 2/3 of the council must agree to it.
type CancellationOrigin = EnsureOneOf< type CancellationOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>, pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>,
>; >;
@@ -610,7 +605,6 @@ impl pallet_democracy::Config for Runtime {
// To cancel a proposal before it has been passed, the technical committee must be unanimous or // To cancel a proposal before it has been passed, the technical committee must be unanimous or
// Root must agree. // Root must agree.
type CancelProposalOrigin = EnsureOneOf< type CancelProposalOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>, pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>,
>; >;
@@ -736,7 +730,6 @@ parameter_types! {
} }
type ApproveOrigin = EnsureOneOf< type ApproveOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_3, _5, AccountId, CouncilCollective>, pallet_collective::EnsureProportionAtLeast<_3, _5, AccountId, CouncilCollective>,
>; >;
@@ -1278,7 +1271,6 @@ parameter_types! {
} }
type AuctionInitiate = EnsureOneOf< type AuctionInitiate = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>, pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>,
>; >;
+8 -21
View File
@@ -41,13 +41,13 @@ use beefy_primitives::crypto::AuthorityId as BeefyId;
use frame_support::{ use frame_support::{
construct_runtime, match_type, parameter_types, construct_runtime, match_type, parameter_types,
traits::{ traits::{
Contains, Everything, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, Nothing, Contains, EnsureOneOf, Everything, InstanceFilter, KeyOwnerProofSystem, LockIdentifier,
OnRuntimeUpgrade, PrivilegeCmp, Nothing, OnRuntimeUpgrade, PrivilegeCmp,
}, },
weights::Weight, weights::Weight,
PalletId, RuntimeDebug, PalletId, RuntimeDebug,
}; };
use frame_system::{EnsureOneOf, EnsureRoot}; use frame_system::EnsureRoot;
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_mmr_primitives as mmr; use pallet_mmr_primitives as mmr;
@@ -193,7 +193,6 @@ impl Contains<Call> for BaseFilter {
} }
type MoreThanHalfCouncil = EnsureOneOf< type MoreThanHalfCouncil = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>, pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>,
>; >;
@@ -236,7 +235,6 @@ parameter_types! {
} }
type ScheduleOrigin = EnsureOneOf< type ScheduleOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>, pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>,
>; >;
@@ -469,7 +467,6 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
>; >;
type BenchmarkingConfig = runtime_common::elections::BenchmarkConfig; type BenchmarkingConfig = runtime_common::elections::BenchmarkConfig;
type ForceOrigin = EnsureOneOf< type ForceOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>, pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>,
>; >;
@@ -516,7 +513,6 @@ parameter_types! {
} }
type SlashCancelOrigin = EnsureOneOf< type SlashCancelOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>, pallet_collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>,
>; >;
@@ -603,33 +599,28 @@ impl pallet_democracy::Config for Runtime {
type VotingPeriod = VotingPeriod; type VotingPeriod = VotingPeriod;
type MinimumDeposit = MinimumDeposit; type MinimumDeposit = MinimumDeposit;
/// A straight majority of the council can decide what their next motion is. /// A straight majority of the council can decide what their next motion is.
type ExternalOrigin = frame_system::EnsureOneOf< type ExternalOrigin = EnsureOneOf<
AccountId,
pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>, pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>,
frame_system::EnsureRoot<AccountId>, frame_system::EnsureRoot<AccountId>,
>; >;
/// A 60% super-majority can have the next scheduled referendum be a straight majority-carries vote. /// A 60% super-majority can have the next scheduled referendum be a straight majority-carries vote.
type ExternalMajorityOrigin = frame_system::EnsureOneOf< type ExternalMajorityOrigin = EnsureOneOf<
AccountId,
pallet_collective::EnsureProportionAtLeast<_3, _5, AccountId, CouncilCollective>, pallet_collective::EnsureProportionAtLeast<_3, _5, AccountId, CouncilCollective>,
frame_system::EnsureRoot<AccountId>, frame_system::EnsureRoot<AccountId>,
>; >;
/// A unanimous council can have the next scheduled referendum be a straight default-carries /// A unanimous council can have the next scheduled referendum be a straight default-carries
/// (NTB) vote. /// (NTB) vote.
type ExternalDefaultOrigin = frame_system::EnsureOneOf< type ExternalDefaultOrigin = EnsureOneOf<
AccountId,
pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, CouncilCollective>, pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, CouncilCollective>,
frame_system::EnsureRoot<AccountId>, frame_system::EnsureRoot<AccountId>,
>; >;
/// Two thirds of the technical committee can have an `ExternalMajority/ExternalDefault` vote /// Two thirds of the technical committee can have an `ExternalMajority/ExternalDefault` vote
/// be tabled immediately and with a shorter voting/enactment period. /// be tabled immediately and with a shorter voting/enactment period.
type FastTrackOrigin = frame_system::EnsureOneOf< type FastTrackOrigin = EnsureOneOf<
AccountId,
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechnicalCollective>, pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechnicalCollective>,
frame_system::EnsureRoot<AccountId>, frame_system::EnsureRoot<AccountId>,
>; >;
type InstantOrigin = frame_system::EnsureOneOf< type InstantOrigin = EnsureOneOf<
AccountId,
pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>, pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>,
frame_system::EnsureRoot<AccountId>, frame_system::EnsureRoot<AccountId>,
>; >;
@@ -637,14 +628,12 @@ impl pallet_democracy::Config for Runtime {
type FastTrackVotingPeriod = FastTrackVotingPeriod; type FastTrackVotingPeriod = FastTrackVotingPeriod;
// To cancel a proposal which has been passed, 2/3 of the council must agree to it. // To cancel a proposal which has been passed, 2/3 of the council must agree to it.
type CancellationOrigin = EnsureOneOf< type CancellationOrigin = EnsureOneOf<
AccountId,
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>, pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
>; >;
// To cancel a proposal before it has been passed, the technical committee must be unanimous or // To cancel a proposal before it has been passed, the technical committee must be unanimous or
// Root must agree. // Root must agree.
type CancelProposalOrigin = EnsureOneOf< type CancelProposalOrigin = EnsureOneOf<
AccountId,
pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>, pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
>; >;
@@ -771,7 +760,6 @@ parameter_types! {
} }
type ApproveOrigin = EnsureOneOf< type ApproveOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_3, _5, AccountId, CouncilCollective>, pallet_collective::EnsureProportionAtLeast<_3, _5, AccountId, CouncilCollective>,
>; >;
@@ -1276,7 +1264,6 @@ parameter_types! {
} }
type AuctionInitiate = EnsureOneOf< type AuctionInitiate = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>, EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>, pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>,
>; >;