diff --git a/Cargo.lock b/Cargo.lock index cfe2298..c6d3807 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -188,6 +188,7 @@ dependencies = [ "pallet-balances", "pallet-collator-selection", "pallet-collective", + "pallet-democracy", "pallet-identity", "pallet-membership", "pallet-message-queue", diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index a68288b..f056c19 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -1,4 +1,4 @@ -use ajuna_runtime::{AccountId, AuraId, Signature}; +use ajuna_runtime::{AccountId, AuraId, Signature, EXISTENTIAL_DEPOSIT}; use cumulus_primitives_core::ParaId; use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; use sc_service::ChainType; @@ -185,7 +185,21 @@ fn testnet_genesis( }, "collatorSelection": { "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), - "candidacyBond": 0_u64, + "candidacyBond": EXISTENTIAL_DEPOSIT * 16, + }, + "council": { + "members": vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + ] + }, + "technicalCommittee": { + "members": vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + ] }, "session": { "keys": invulnerables diff --git a/runtime/ajuna/Cargo.toml b/runtime/ajuna/Cargo.toml index 20da432..848f0e0 100644 --- a/runtime/ajuna/Cargo.toml +++ b/runtime/ajuna/Cargo.toml @@ -33,6 +33,7 @@ pallet-aura = { workspace = true } pallet-authorship = { workspace = true } pallet-balances = { workspace = true } pallet-collective = { workspace = true } +pallet-democracy = { workspace = true } pallet-identity = { workspace = true } pallet-membership = { workspace = true } pallet-message-queue = { workspace = true } @@ -113,6 +114,7 @@ std = [ "pallet-balances/std", "pallet-collective/std", "pallet-collator-selection/std", + "pallet-democracy/std", "pallet-identity/std", "pallet-membership/std", "pallet-message-queue/std", @@ -160,6 +162,7 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-collective/runtime-benchmarks", + "pallet-democracy/runtime-benchmarks", "pallet-identity/runtime-benchmarks", "pallet-membership/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", @@ -192,6 +195,7 @@ try-runtime = [ "pallet-balances/try-runtime", "pallet-collator-selection/try-runtime", "pallet-collective/try-runtime", + "pallet-democracy/try-runtime", "pallet-identity/try-runtime", "pallet-membership/try-runtime", "pallet-message-queue/try-runtime", diff --git a/runtime/ajuna/src/gov.rs b/runtime/ajuna/src/gov.rs new file mode 100644 index 0000000..fdfee2f --- /dev/null +++ b/runtime/ajuna/src/gov.rs @@ -0,0 +1,169 @@ +// Ajuna Node +// Copyright (C) 2022 BlogaTech AG + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +use crate::{ + AccountId, Balance, BlockNumber, Council, CouncilMembership, OriginCaller, Runtime, + RuntimeBlockWeights, RuntimeCall, RuntimeEvent, RuntimeOrigin, TechnicalCommittee, AJUN, DAYS, +}; +use frame_support::{ + parameter_types, + traits::{ConstBool, ConstU32, EitherOfDiverse}, + weights::Weight, +}; +use frame_system::{EnsureRoot, EnsureSignedBy}; +use pallet_collective::{EnsureMember, EnsureProportionAtLeast, EnsureProportionMoreThan}; +use sp_runtime::Perbill; + +pub type EnsureRootOrMoreThanHalfCouncil = EitherOfDiverse< + EnsureRoot, + EnsureProportionMoreThan, +>; + +pub type EnsureRootOrMoreThanHalfTechnicalCommittee = EitherOfDiverse< + EnsureRoot, + EnsureProportionAtLeast, +>; + +pub type EnsureRootOrAllTechnicalCommittee = EitherOfDiverse< + EnsureRoot, + EnsureProportionAtLeast, +>; + +/// Council collective instance declaration. +/// +/// The council primarily serves to optimize and balance the inclusive referendum system +/// by being allowed to propose external democracy proposals, which can be fast tracked and +/// bypass the one active referendum at a time rule. +/// +/// It also controls the treasury. +type CouncilCollectiveInstance = pallet_collective::Instance2; + +parameter_types! { + pub CouncilMotionDuration: BlockNumber = 3 * DAYS; + pub MaxProposalWeight: Weight = Perbill::from_percent(50) * RuntimeBlockWeights::get().max_block; + pub CouncilMaxMembers: u32 = 100; +} + +impl pallet_collective::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type Proposal = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type MotionDuration = CouncilMotionDuration; + type MaxProposals = ConstU32<100>; + type MaxMembers = CouncilMaxMembers; + type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote; + type WeightInfo = pallet_collective::weights::SubstrateWeight; + type SetMembersOrigin = EnsureRootOrMoreThanHalfCouncil; + type MaxProposalWeight = MaxProposalWeight; +} + +/// Helper pallet to manage Council members. +type CouncilMembershipInstance = pallet_membership::Instance2; +impl pallet_membership::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type AddOrigin = EnsureRootOrMoreThanHalfCouncil; + type RemoveOrigin = EnsureRootOrMoreThanHalfCouncil; + type SwapOrigin = EnsureRootOrMoreThanHalfCouncil; + type ResetOrigin = EnsureRootOrMoreThanHalfCouncil; + type PrimeOrigin = EnsureRootOrMoreThanHalfCouncil; + type MembershipInitialized = Council; + type MembershipChanged = Council; + type MaxMembers = CouncilMaxMembers; + type WeightInfo = pallet_membership::weights::SubstrateWeight; +} + +/// The technical committee primarily serves to safeguard against malicious referenda +/// and fast track critical referenda. +pub type TechnicalCommitteeInstance = pallet_collective::Instance1; + +parameter_types! { + pub const TechnicalMotionDuration: BlockNumber = 3 * DAYS; + pub const TechnicalCommitteeMaxMembers: u32 = 100; +} + +impl pallet_collective::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type Proposal = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type MotionDuration = TechnicalMotionDuration; + type MaxProposals = ConstU32<100>; + type MaxMembers = TechnicalCommitteeMaxMembers; + type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote; + type WeightInfo = pallet_collective::weights::SubstrateWeight; + type SetMembersOrigin = EnsureRootOrMoreThanHalfCouncil; + type MaxProposalWeight = MaxProposalWeight; +} + +/// Helper pallet to manage TechnicalCommittee members. +type TechnicalCommitteeMembershipInstance = pallet_membership::Instance1; +impl pallet_membership::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type AddOrigin = EnsureRootOrMoreThanHalfCouncil; + type RemoveOrigin = EnsureRootOrMoreThanHalfCouncil; + type SwapOrigin = EnsureRootOrMoreThanHalfCouncil; + type ResetOrigin = EnsureRootOrMoreThanHalfCouncil; + type PrimeOrigin = EnsureRootOrMoreThanHalfCouncil; + type MembershipInitialized = TechnicalCommittee; + type MembershipChanged = TechnicalCommittee; + type MaxMembers = TechnicalCommitteeMaxMembers; + type WeightInfo = pallet_membership::weights::SubstrateWeight; +} + +parameter_types! { + pub const ThreeDays: BlockNumber = 3 * DAYS; + pub const TwentyEightDays: BlockNumber = 28 * DAYS; + pub const ThirtyDays: BlockNumber = 30 * DAYS; + pub EnactmentPeriod: BlockNumber = 7 * DAYS; + pub const MinimumDeposit: Balance = AJUN; +} + +impl pallet_democracy::Config for Runtime { + type WeightInfo = pallet_democracy::weights::SubstrateWeight; + type RuntimeEvent = RuntimeEvent; + type Scheduler = pallet_scheduler::Pallet; + type Preimages = pallet_preimage::Pallet; + type Currency = pallet_balances::Pallet; + type EnactmentPeriod = EnactmentPeriod; + type LaunchPeriod = TwentyEightDays; + type VotingPeriod = TwentyEightDays; + type VoteLockingPeriod = EnactmentPeriod; + type MinimumDeposit = MinimumDeposit; + type InstantAllowed = ConstBool; + type FastTrackVotingPeriod = ThreeDays; + type CooloffPeriod = TwentyEightDays; + type MaxVotes = ConstU32<100>; + type MaxProposals = ConstU32<100>; + type MaxDeposits = ConstU32<100>; + type MaxBlacklisted = ConstU32<100>; + type ExternalOrigin = EnsureRootOrMoreThanHalfCouncil; + type ExternalMajorityOrigin = EnsureRootOrMoreThanHalfCouncil; + type ExternalDefaultOrigin = EnsureRootOrMoreThanHalfCouncil; + // Initially, we want that only the council can submit proposals to + // prevent malicious proposals. + type SubmitOrigin = EnsureSignedBy; + type FastTrackOrigin = EnsureRootOrMoreThanHalfTechnicalCommittee; + type InstantOrigin = EnsureRootOrMoreThanHalfTechnicalCommittee; + // To cancel a proposal that has passed. + type CancellationOrigin = EnsureRoot; + type BlacklistOrigin = EnsureRootOrMoreThanHalfCouncil; + // To cancel a proposal before it has passed, and slash its backers. + type CancelProposalOrigin = EnsureRootOrAllTechnicalCommittee; + // Any single technical committee member may veto a coming council proposal, however they can + // only do it once and it lasts only for the cooloff period. + type VetoOrigin = EnsureMember; + type PalletsOrigin = OriginCaller; + type Slash = pallet_treasury::Pallet; +} diff --git a/runtime/ajuna/src/lib.rs b/runtime/ajuna/src/lib.rs index 74308e4..5998a67 100644 --- a/runtime/ajuna/src/lib.rs +++ b/runtime/ajuna/src/lib.rs @@ -22,10 +22,12 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +mod gov; mod proxy_type; mod weights; pub mod xcm_config; +use crate::gov::EnsureRootOrMoreThanHalfCouncil; use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use smallvec::smallvec; use sp_api::impl_runtime_apis; @@ -50,7 +52,7 @@ use frame_support::{ traits::{ fungible::HoldConsideration, tokens::{PayFromAccount, UnityAssetBalanceConversion}, - ConstBool, Contains, EitherOfDiverse, Footprint, TransformOrigin, + ConstBool, Contains, LinearStoragePrice, TransformOrigin, }, weights::{ constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient, @@ -62,7 +64,6 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, }; -use pallet_collective::{EnsureProportionAtLeast, EnsureProportionMoreThan}; use pallet_identity::legacy::IdentityInfo; use pallet_transaction_payment::CurrencyAdapter; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; @@ -73,20 +74,26 @@ use xcm_config::XcmOriginToTransactDispatchOrigin; pub use sp_runtime::BuildStorage; // Polkadot imports -use parachains_common::{ - message_queue::{NarrowOriginToSibling, ParaIdToSibling}, - BlockNumber, Hash, Header, -}; -use polkadot_runtime_common::{ - xcm_sender::NoPriceForMessageDelivery, BlockHashCount, SlowAdjustingFeeUpdate, -}; -use sp_runtime::traits::{Convert, IdentifyAccount, IdentityLookup, Verify}; +use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; // XCM Imports use staging_xcm::latest::prelude::BodyId; +use parachains_common::{ + message_queue::{NarrowOriginToSibling, ParaIdToSibling}, + BlockNumber, Hash, Header, +}; +use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; +use sp_runtime::traits::{IdentifyAccount, IdentityLookup, Verify}; + +parameter_types! { + pub const OneDay: BlockNumber = DAYS; + pub const OneWeek: BlockNumber = 7 * DAYS; + pub const TwoWeeks: BlockNumber = 14 * DAYS; +} + /// The address format for describing accounts. pub type Address = MultiAddress; @@ -333,7 +340,10 @@ impl Contains for BaseCallFilter { RuntimeCall::Sudo(_) | RuntimeCall::Treasury(_) | RuntimeCall::Council(_) | - RuntimeCall::CouncilMembership(_) => true + RuntimeCall::CouncilMembership(_) | + RuntimeCall::TechnicalCommittee(_) | + RuntimeCall::TechnicalCommitteeMembership(_) | + RuntimeCall::Democracy(_) => true } } } @@ -427,7 +437,7 @@ impl pallet_balances::Config for Runtime { type ReserveIdentifier = [u8; 8]; type FreezeIdentifier = (); type MaxFreezes = (); - type RuntimeHoldReason = (); + type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = (); } @@ -459,42 +469,6 @@ parameter_types! { pub MaxProposalWeight: Weight = Perbill::from_percent(50) * RuntimeBlockWeights::get().max_block; } -type CouncilCollective = pallet_collective::Instance2; -impl pallet_collective::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type Proposal = RuntimeCall; - type RuntimeEvent = RuntimeEvent; - type MotionDuration = Weekly; - type MaxProposals = frame_support::traits::ConstU32<100>; - type MaxMembers = CouncilMaxMembers; - type DefaultVote = pallet_collective::PrimeDefaultVote; - type WeightInfo = weights::pallet_collective::WeightInfo; - type SetMembersOrigin = EnsureRoot; - type MaxProposalWeight = MaxProposalWeight; -} - -type EnsureRootOrMoreThanHalfCouncil = EitherOfDiverse< - EnsureRoot, - EnsureProportionMoreThan, ->; -type EnsureRootOrAtLeastTwoThirdsCouncil = EitherOfDiverse< - EnsureRoot, - EnsureProportionAtLeast, ->; - -impl pallet_membership::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type AddOrigin = EnsureRootOrMoreThanHalfCouncil; - type RemoveOrigin = EnsureRootOrMoreThanHalfCouncil; - type SwapOrigin = EnsureRootOrMoreThanHalfCouncil; - type ResetOrigin = EnsureRootOrAtLeastTwoThirdsCouncil; - type PrimeOrigin = EnsureRootOrAtLeastTwoThirdsCouncil; - type MembershipInitialized = Council; - type MembershipChanged = Council; - type MaxMembers = CouncilMaxMembers; - type WeightInfo = weights::pallet_membership::WeightInfo; -} - parameter_types! { pub TreasuryAccount: AccountId = Treasury::account_id(); pub const SpendPayoutPeriod: u32 = 5; @@ -509,7 +483,7 @@ impl pallet_treasury::Config for Runtime { type ProposalBond = FivePercent; type ProposalBondMinimum = MinimumProposalBond; type ProposalBondMaximum = (); - type SpendPeriod = Weekly; + type SpendPeriod = OneWeek; type Burn = ZeroPercent; type PalletId = TreasuryPalletId; type BurnDestination = (); @@ -660,7 +634,6 @@ impl pallet_collator_selection::Config for Runtime { type UpdateOrigin = CollatorSelectionUpdateOrigin; type PotId = PotId; type MaxCandidates = MaxCandidates; - type MinEligibleCollators = MinEligibleCollators; type MaxInvulnerables = MaxInvulnerables; // should be a multiple of session or things will get inconsistent type KickThreshold = Period; @@ -668,6 +641,7 @@ impl pallet_collator_selection::Config for Runtime { type ValidatorIdOf = pallet_collator_selection::IdentityCollator; type ValidatorRegistration = Session; type WeightInfo = weights::pallet_collator_selection::WeightInfo; + type MinEligibleCollators = MinEligibleCollators; } pub const fn deposit(items: u32, bytes: u32) -> Balance { @@ -777,11 +751,11 @@ impl pallet_scheduler::Config for Runtime { type Preimages = Preimage; } -pub struct ConvertDeposit; -impl Convert for ConvertDeposit { - fn convert(a: Footprint) -> u128 { - (a.count as u128) * 2 + (a.size as u128) - } +parameter_types! { + pub const PreimageBaseDeposit: Balance = deposit(2, 64); + pub const PreimageByteDeposit: Balance = deposit(0, 1); + pub const PreimageHoldReason: RuntimeHoldReason = + RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage); } impl pallet_preimage::Config for Runtime { @@ -789,7 +763,12 @@ impl pallet_preimage::Config for Runtime { type WeightInfo = weights::pallet_preimage::WeightInfo; type Currency = Balances; type ManagerOrigin = EnsureRoot; - type Consideration = HoldConsideration; + type Consideration = HoldConsideration< + AccountId, + Balances, + PreimageHoldReason, + LinearStoragePrice, + >; } // Create the runtime by composing the FRAME pallets that were previously configured. @@ -830,8 +809,15 @@ construct_runtime!( // Governance Sudo: pallet_sudo = 40, Treasury: pallet_treasury = 41, + // type CouncilCollectiveInstance = pallet_collective::Instance2 Council: pallet_collective:: = 42, + // type CouncilMembershipInstance = pallet_membership::Instance2; CouncilMembership: pallet_membership:: = 43, + // pub type TechnicalCommitteeInstance = pallet_collective::Instance1; + TechnicalCommittee: pallet_collective:: = 44, + // type TechnicalCommitteeMembershipInstance = pallet_membership::Instance1; + TechnicalCommitteeMembership: pallet_membership:: = 45, + Democracy: pallet_democracy = 46, } ); @@ -842,21 +828,23 @@ extern crate frame_benchmarking; #[cfg(feature = "runtime-benchmarks")] mod benches { define_benchmarks!( + [cumulus_pallet_xcmp_queue, XcmpQueue] [frame_system, SystemBench::] [pallet_balances, Balances] - [pallet_session, SessionBench::] - [pallet_timestamp, Timestamp] - [pallet_multisig, Multisig] - [pallet_utility, Utility] [pallet_collator_selection, CollatorSelection] - [cumulus_pallet_xcmp_queue, XcmpQueue] - [pallet_treasury, Treasury] [pallet_collective, Council] - [pallet_membership, CouncilMembership] + // [pallet_collective, TechnicalCommittee] // writes to the same file [pallet_identity, Identity] + [pallet_membership, CouncilMembership] + // [pallet_membership, TechnicalCommitteeMembership] // writes to the same file + [pallet_multisig, Multisig] [pallet_preimage, Preimage] [pallet_proxy, Proxy] [pallet_scheduler, Scheduler] + [pallet_session, SessionBench::] + [pallet_timestamp, Timestamp] + [pallet_treasury, Treasury] + [pallet_utility, Utility] ); } diff --git a/runtime/ajuna/src/proxy_type.rs b/runtime/ajuna/src/proxy_type.rs index 95874c7..3f0152d 100644 --- a/runtime/ajuna/src/proxy_type.rs +++ b/runtime/ajuna/src/proxy_type.rs @@ -62,6 +62,9 @@ impl InstanceFilter for ProxyType { RuntimeCall::Session(..) | RuntimeCall::Council(..) | RuntimeCall::CouncilMembership(..) | + RuntimeCall::TechnicalCommittee(..) | + RuntimeCall::TechnicalCommitteeMembership(..) | + RuntimeCall::Democracy(..) | RuntimeCall::Treasury(..) | RuntimeCall::Vesting(orml_vesting::Call::claim{..}) | RuntimeCall::Vesting(orml_vesting::Call::claim_for{..}) | diff --git a/runtime/ajuna/src/xcm_config.rs b/runtime/ajuna/src/xcm_config.rs index 183c96a..30d0bdd 100644 --- a/runtime/ajuna/src/xcm_config.rs +++ b/runtime/ajuna/src/xcm_config.rs @@ -18,10 +18,9 @@ use super::{ AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, }; -use core::{marker::PhantomData, ops::ControlFlow}; use frame_support::{ parameter_types, - traits::{ConstU32, Contains, Everything, Nothing, ProcessMessageError}, + traits::{ConstU32, Contains, Everything, Nothing}, weights::Weight, }; use frame_system::EnsureRoot; @@ -33,15 +32,13 @@ use staging_xcm::latest::prelude::*; use staging_xcm_builder::CurrencyAdapter; use staging_xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, - CreateMatcher, EnsureXcmOrigin, FixedWeightBounds, FrameTransactionalProcessor, IsConcrete, - MatchXcm, NativeAsset, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, - SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, - SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WithComputedOrigin, -}; -use staging_xcm_executor::{ - traits::{Properties, ShouldExecute}, - XcmExecutor, + DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, + FrameTransactionalProcessor, IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, + UsingComponents, WithComputedOrigin, WithUniqueTopic, }; +use staging_xcm_executor::XcmExecutor; parameter_types! { pub const RelayLocation: Location = Location::parent(); @@ -53,7 +50,7 @@ parameter_types! { pub CheckingAccount: AccountId = PolkadotXcm::check_account(); } -/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used +/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used /// when determining ownership of accounts for asset transacting and when attempting to use XCM /// `Transact` in order to determine the dispatch Origin. pub type LocationToAccountId = ( @@ -72,7 +69,7 @@ pub type LocalAssetTransactor = CurrencyAdapter< Balances, // Use this currency when it is a fungible asset matching the given location or name: IsConcrete, - // Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID: + // Do a simple punn to convert an AccountId32 Location into a native chain account ID: LocationToAccountId, // Our chain's account ID type (we can't get away without mentioning it explicitly): AccountId, @@ -88,7 +85,7 @@ pub type XcmOriginToTransactDispatchOrigin = ( // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for // foreign chains who want to have a local sovereign account on this chain which they control. SovereignSignedViaLocation, - // Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when + // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when // recognized. RelayChainAsNative, // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when @@ -115,84 +112,22 @@ impl Contains for ParentOrParentsExecutivePlurality { } } -//TODO: move DenyThenTry to polkadot's xcm module. -/// Deny executing the xcm message if it matches any of the Deny filter regardless of anything else. -/// If it passes the Deny, and matches one of the Allow cases then it is let through. -pub struct DenyThenTry(PhantomData, PhantomData) -where - Deny: ShouldExecute, - Allow: ShouldExecute; - -impl ShouldExecute for DenyThenTry -where - Deny: ShouldExecute, - Allow: ShouldExecute, -{ - fn should_execute( - origin: &Location, - message: &mut [Instruction], - max_weight: Weight, - properties: &mut Properties, - ) -> Result<(), ProcessMessageError> { - Deny::should_execute(origin, message, max_weight, properties)?; - Allow::should_execute(origin, message, max_weight, properties) - } -} - -// See issue -pub struct DenyReserveTransferToRelayChain; -impl ShouldExecute for DenyReserveTransferToRelayChain { - fn should_execute( - origin: &Location, - message: &mut [Instruction], - _max_weight: Weight, - _properties: &mut Properties, - ) -> Result<(), ProcessMessageError> { - message.matcher().match_next_inst_while( - |_| true, - |inst| match inst { - InitiateReserveWithdraw { - reserve: Location { parents: 1, interior: Here }, - .. - } | - DepositReserveAsset { dest: Location { parents: 1, interior: Here }, .. } | - TransferReserveAsset { dest: Location { parents: 1, interior: Here }, .. } => { - Err(ProcessMessageError::Unsupported) // Deny - }, - // An unexpected reserve transfer has arrived from the Relay Chain. Generally, - // `IsReserve` should not allow this, but we just log it here. - ReserveAssetDeposited { .. } - if matches!(origin, Location { parents: 1, interior: Here }) => - { - log::warn!( - target: "xcm::barrier", - "Unexpected ReserveAssetDeposited from the Relay Chain", - ); - Ok(ControlFlow::Continue(())) - }, - _ => Ok(ControlFlow::Continue(())), - }, - )?; - - // Permit everything else - Ok(()) - } -} - -pub type Barrier = DenyThenTry< - DenyReserveTransferToRelayChain, - ( - TakeWeightCredit, - WithComputedOrigin< - ( - AllowTopLevelPaidExecutionFrom, - AllowExplicitUnpaidExecutionFrom, - // ^^^ Parent and its exec plurality get free execution - ), - UniversalLocation, - ConstU32<8>, - >, - ), +pub type Barrier = TrailingSetTopicAsId< + DenyThenTry< + DenyReserveTransferToRelayChain, + ( + TakeWeightCredit, + WithComputedOrigin< + ( + AllowTopLevelPaidExecutionFrom, + AllowExplicitUnpaidExecutionFrom, + // ^^^ Parent and its exec plurality get free execution + ), + UniversalLocation, + ConstU32<8>, + >, + ), + >, >; pub struct XcmConfig; @@ -231,17 +166,12 @@ pub type LocalOriginToLocation = SignedToAccountId32, // ..and XCMP to communicate with the sibling chains. XcmpQueue, -); - -#[cfg(feature = "runtime-benchmarks")] -parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); -} +)>; impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent;