From cef7fd5e79ff41cc27f6a303829e1930aeb54bfb Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Wed, 12 Jun 2024 15:36:02 +0200 Subject: [PATCH] update penpal --- Cargo.lock | 36 +-- Cargo.toml | 9 +- integration-tests/Cargo.toml | 2 +- integration-tests/penpal/Cargo.toml | 147 +++++----- integration-tests/penpal/build.rs | 5 +- integration-tests/penpal/src/lib.rs | 193 +++++++------ .../penpal/src/weights/block_weights.rs | 2 +- .../penpal/src/weights/extrinsic_weights.rs | 2 +- integration-tests/penpal/src/weights/mod.rs | 2 +- .../penpal/src/weights/paritydb_weights.rs | 2 +- .../penpal/src/weights/rocksdb_weights.rs | 2 +- integration-tests/penpal/src/xcm_config.rs | 262 ++++++++++-------- pallets/polimec-receiver/Cargo.toml | 5 +- pallets/polimec-receiver/src/lib.rs | 4 +- runtimes/polimec/src/xcm_config.rs | 40 ++- 15 files changed, 399 insertions(+), 314 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 99254cfaf..66446de14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2351,20 +2351,6 @@ dependencies = [ "sp-trie", ] -[[package]] -name = "cumulus-primitives-timestamp" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d1d900bd9e76607a4a0734cbb2b004d86177d2d6938b5d25eb812c6c1b7500" -dependencies = [ - "cumulus-primitives-core", - "futures", - "parity-scale-codec", - "sp-inherents", - "sp-std", - "sp-timestamp", -] - [[package]] name = "cumulus-primitives-utility" version = "0.7.3" @@ -8165,8 +8151,9 @@ dependencies = [ [[package]] name = "penpal-runtime" -version = "0.9.27" +version = "0.14.3" dependencies = [ + "assets-common", "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", @@ -8174,7 +8161,6 @@ dependencies = [ "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", "cumulus-primitives-core", - "cumulus-primitives-timestamp", "cumulus-primitives-utility", "frame-benchmarking", "frame-executive", @@ -8183,7 +8169,7 @@ dependencies = [ "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", - "hex-literal 0.3.4", + "hex-literal 0.4.1", "log", "pallet-asset-tx-payment", "pallet-assets", @@ -8209,15 +8195,18 @@ dependencies = [ "polkadot-runtime-parachains", "scale-info", "smallvec", + "snowbridge-rococo-common", "sp-api", "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", "sp-session", "sp-std", + "sp-storage", "sp-transaction-pool", "sp-version", "staging-parachain-info", @@ -8456,6 +8445,7 @@ dependencies = [ name = "polimec-receiver" version = "0.1.0" dependencies = [ + "cumulus-pallet-xcm", "frame-benchmarking", "frame-support", "frame-system", @@ -8463,7 +8453,6 @@ dependencies = [ "parity-scale-codec", "polimec-common", "polkadot-parachain-primitives", - "polkadot-runtime-parachains", "scale-info", "serde", "sp-core", @@ -12788,6 +12777,17 @@ dependencies = [ "subtle 2.5.0", ] +[[package]] +name = "snowbridge-rococo-common" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dc8ddfb7bec2140079a788c312010f793d75fde1f996128517b0c14270296a4" +dependencies = [ + "frame-support", + "log", + "staging-xcm", +] + [[package]] name = "socket2" version = "0.4.10" diff --git a/Cargo.toml b/Cargo.toml index 12ed40892..f203915a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -131,6 +131,7 @@ sp-authority-discovery = { version = "26.0.0", default-features = false } sp-consensus-babe = { version = "0.32.0", default-features = false } pallet-message-queue = { version = "31.0.0", default-features = false } sp-weights = { version = "27.0.0", default-features = false } +sp-storage = { version = "19.0.0", default-features = false } # FRAME pallet-aura = { version = "27.0.0", default-features = false } @@ -154,7 +155,7 @@ pallet-preimage = { version = "28.0.0", default-features = false } pallet-grandpa = { version = "28.0.0", default-features = false } pallet-transaction-payment-rpc = { version = "30.0.0" } pallet-vesting = { version = "28.0.0", default-features = false } -pallet-staking = { version = "28.0.0", default-features = false } +pallet-staking = { version = "28.0.1", default-features = false } pallet-proxy = { version = "28.0.0", default-features = false } pallet-identity = { version = "28.0.0", default-features = false } @@ -182,10 +183,12 @@ cumulus-pallet-xcmp-queue = { version = "0.7.0", default-features = false } cumulus-primitives-core = { version = "0.7.0", default-features = false } cumulus-primitives-timestamp = { version = "0.7.0", default-features = false } cumulus-primitives-utility = { version = "0.7.3", default-features = false } -pallet-collator-selection = { version = "9.0.0", default-features = false } +pallet-collator-selection = { version = "9.0.2", default-features = false } parachain-info = { version = "0.7.0", package = 'staging-parachain-info', default-features = false } parachains-common = { version = "7.0.0", default-features = false } cumulus-primitives-aura = { version = "0.7.0", default-features = false } +assets-common = { version = "0.7.0", default-features = false } +snowbridge-rococo-common = { version = "0.1.0", default-features = false } # Client-only (with default enabled) cumulus-client-cli = { version = "0.7.0" } @@ -234,4 +237,4 @@ polimec-runtime = { path = "runtimes/polimec" } asset-hub-polkadot-runtime = { git = 'https://github.com/polkadot-fellows/runtimes', default-features = false, rev = '59172d5fb8feea2646490618bead3b2b4fb06220' } polkadot-runtime-constants = { git = 'https://github.com/polkadot-fellows/runtimes', default-features = false, rev = '59172d5fb8feea2646490618bead3b2b4fb06220' } system-parachains-constants = { git = 'https://github.com/polkadot-fellows/runtimes', default-features = false, rev = '59172d5fb8feea2646490618bead3b2b4fb06220' } -polkadot-runtime = { git = 'https://github.com/polkadot-fellows/runtimes', default-features = false, rev = '59172d5fb8feea2646490618bead3b2b4fb06220' } \ No newline at end of file +polkadot-runtime = { git = 'https://github.com/polkadot-fellows/runtimes', default-features = false, rev = '59172d5fb8feea2646490618bead3b2b4fb06220' } diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index dafad096f..0dfd6fb00 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -76,7 +76,7 @@ pallet-treasury.workspace = true polkadot-runtime.workspace = true asset-hub-polkadot-runtime.workspace = true polimec-runtime.workspace = true -penpal-runtime = { path = "./penpal", default-features = false } +penpal-runtime = { path = "penpal", default-features = false } [features] default = [ "instant-mode", "std", "development-settings"] diff --git a/integration-tests/penpal/Cargo.toml b/integration-tests/penpal/Cargo.toml index 798390948..1ad914288 100644 --- a/integration-tests/penpal/Cargo.toml +++ b/integration-tests/penpal/Cargo.toml @@ -1,90 +1,94 @@ [package] name = "penpal-runtime" -version = "0.9.27" +version = "0.14.3" authors = ["Anonymous"] description = "A parachain for communication back and forth with XCM of assets and uniques." license = "Unlicense" homepage = "https://substrate.io" -repository = "https://github.com/paritytech/polkadot-sdk" -edition = "2021" +repository.workspace = true +edition.workspace = true [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] [build-dependencies] -substrate-wasm-builder = { optional = true , workspace = true} +substrate-wasm-builder = { workspace = true, optional = true } [dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -hex-literal.workspace = true -log.workspace = true -scale-info = { version = "2.7.0", default-features = false, features = ["derive"] } -smallvec = "1.10.0" +parity-scale-codec = { workspace = true, default-features = false, features = ["derive"] } +hex-literal = { version = "0.4.1", optional = true } +log = { version = "0.4.20", default-features = false } +scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } +smallvec = "1.11.0" # Local polimec-receiver.workspace = true polimec-common.workspace = true # Substrate -frame-benchmarking = { workspace = true, optional = true } -frame-executive.workspace = true -frame-support.workspace = true -frame-system.workspace = true -frame-system-benchmarking = { workspace = true, optional = true } -frame-system-rpc-runtime-api.workspace = true -frame-try-runtime = { workspace = true, optional = true } -pallet-aura.workspace = true -pallet-authorship.workspace = true -pallet-balances.workspace = true -pallet-message-queue.workspace = true -pallet-session.workspace = true -pallet-sudo.workspace = true -pallet-timestamp.workspace = true -pallet-transaction-payment.workspace = true -pallet-transaction-payment-rpc-runtime-api.workspace = true -pallet-asset-tx-payment.workspace = true -pallet-assets.workspace = true -sp-api.workspace = true -sp-block-builder.workspace = true -sp-consensus-aura.workspace = true -sp-core.workspace = true -sp-inherents.workspace = true -sp-offchain.workspace = true -sp-runtime.workspace = true -sp-session.workspace = true -sp-std.workspace = true -sp-transaction-pool.workspace = true -sp-version.workspace = true +frame-benchmarking = { workspace = true, default-features = false, optional = true } +frame-executive = { workspace = true, default-features = false } +frame-support = { workspace = true, default-features = false } +frame-system = { workspace = true, default-features = false } +frame-system-benchmarking = { workspace = true, default-features = false, optional = true } +frame-system-rpc-runtime-api = { workspace = true, default-features = false } +frame-try-runtime = { workspace = true, default-features = false, optional = true } +pallet-aura = { workspace = true, default-features = false } +pallet-authorship = { workspace = true, default-features = false } +pallet-balances = { workspace = true, default-features = false } +pallet-session = { workspace = true, default-features = false } +pallet-sudo = { workspace = true, default-features = false } +pallet-timestamp = { workspace = true, default-features = false } +pallet-transaction-payment = { workspace = true, default-features = false } +pallet-transaction-payment-rpc-runtime-api = { workspace = true, default-features = false } +pallet-asset-tx-payment = { workspace = true, default-features = false } +pallet-assets = { workspace = true, default-features = false } +sp-api = { workspace = true, default-features = false } +sp-block-builder = { workspace = true, default-features = false } +sp-consensus-aura = { workspace = true, default-features = false } +sp-core = { workspace = true, default-features = false } +sp-genesis-builder = { workspace = true, default-features = false } +sp-inherents = { workspace = true, default-features = false } +sp-offchain = { workspace = true, default-features = false } +sp-runtime = { workspace = true, default-features = false } +sp-session = { workspace = true, default-features = false } +sp-std = { workspace = true, default-features = false } +sp-storage = { workspace = true, default-features = false } +sp-transaction-pool = { workspace = true, default-features = false } +sp-version = { workspace = true, default-features = false } polkadot-runtime-parachains.workspace = true # Polkadot -polkadot-primitives.workspace = true -pallet-xcm.workspace = true -polkadot-parachain-primitives.workspace = true -polkadot-runtime-common.workspace = true -xcm.workspace = true -xcm-builder.workspace = true -xcm-executor.workspace = true +polkadot-primitives = { workspace = true, default-features = false } +pallet-xcm = { workspace = true, default-features = false } +polkadot-parachain-primitives = { workspace = true, default-features = false } +polkadot-runtime-common = { workspace = true, default-features = false } +xcm = { workspace = true, default-features = false } +xcm-builder = { workspace = true, default-features = false } +xcm-executor = { workspace = true, default-features = false } # Cumulus -cumulus-pallet-aura-ext.workspace = true -cumulus-pallet-dmp-queue.workspace = true -cumulus-pallet-parachain-system.workspace = true -cumulus-pallet-session-benchmarking.workspace = true -cumulus-pallet-xcm.workspace = true -cumulus-pallet-xcmp-queue.workspace = true -cumulus-primitives-core.workspace = true -cumulus-primitives-timestamp.workspace = true -cumulus-primitives-utility.workspace = true -pallet-collator-selection.workspace = true -parachain-info.workspace = true -parachains-common.workspace = true +cumulus-pallet-aura-ext = { workspace = true, default-features = false } +pallet-message-queue = { workspace = true, default-features = false } +cumulus-pallet-dmp-queue = { workspace = true, default-features = false } +cumulus-pallet-parachain-system = { workspace = true, default-features = false, features = ["parameterized-consensus-hook"] } +cumulus-pallet-session-benchmarking = { workspace = true, default-features = false } +cumulus-pallet-xcm = { workspace = true, default-features = false } +cumulus-pallet-xcmp-queue = { workspace = true, default-features = false } +cumulus-primitives-core = { workspace = true, default-features = false } +cumulus-primitives-utility = { workspace = true, default-features = false } +pallet-collator-selection = { workspace = true, default-features = false } +parachain-info = { workspace = true, default-features = false } +parachains-common = { workspace = true, default-features = false } +assets-common = { workspace = true, default-features = false } +snowbridge-rococo-common = { workspace = true, default-features = false } pallet-vesting.workspace = true [features] -default = [ "std" ] +default = ["std"] std = [ - "codec/std", + "assets-common/std", + "parity-scale-codec/std", "cumulus-pallet-aura-ext/std", "cumulus-pallet-dmp-queue/std", "cumulus-pallet-parachain-system/std", @@ -92,15 +96,14 @@ std = [ "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", "cumulus-primitives-core/std", - "cumulus-primitives-timestamp/std", "cumulus-primitives-utility/std", - "frame-benchmarking/std", + "frame-benchmarking?/std", "frame-executive/std", "frame-support/std", "frame-system-benchmarking?/std", "frame-system-rpc-runtime-api/std", "frame-system/std", - "frame-try-runtime/std", + "frame-try-runtime?/std", "log/std", "pallet-asset-tx-payment/std", "pallet-assets/std", @@ -114,26 +117,25 @@ std = [ "pallet-timestamp/std", "pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment/std", - "pallet-vesting/std", "pallet-xcm/std", "parachain-info/std", "parachains-common/std", - "polimec-common/std", - "polimec-receiver/std", "polkadot-parachain-primitives/std", "polkadot-primitives/std", "polkadot-runtime-common/std", - "polkadot-runtime-parachains/std", "scale-info/std", + "snowbridge-rococo-common/std", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-offchain/std", "sp-runtime/std", "sp-session/std", "sp-std/std", + "sp-storage/std", "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", @@ -143,6 +145,7 @@ std = [ ] runtime-benchmarks = [ + "assets-common/runtime-benchmarks", "cumulus-pallet-dmp-queue/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", @@ -153,6 +156,7 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", + "hex-literal", "pallet-asset-tx-payment/runtime-benchmarks", "pallet-assets/runtime-benchmarks", "pallet-balances/runtime-benchmarks", @@ -160,15 +164,12 @@ runtime-benchmarks = [ "pallet-message-queue/runtime-benchmarks", "pallet-sudo/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", - "pallet-vesting/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "parachains-common/runtime-benchmarks", - "polimec-common/runtime-benchmarks", - "polimec-receiver/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-primitives/runtime-benchmarks", "polkadot-runtime-common/runtime-benchmarks", - "polkadot-runtime-parachains/runtime-benchmarks", + "snowbridge-rococo-common/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", @@ -195,12 +196,10 @@ try-runtime = [ "pallet-sudo/try-runtime", "pallet-timestamp/try-runtime", "pallet-transaction-payment/try-runtime", - "pallet-vesting/try-runtime", "pallet-xcm/try-runtime", "parachain-info/try-runtime", - "polimec-common/try-runtime", - "polimec-receiver/try-runtime", "polkadot-runtime-common/try-runtime", - "polkadot-runtime-parachains/try-runtime", "sp-runtime/try-runtime", ] + +experimental = ["pallet-aura/experimental"] diff --git a/integration-tests/penpal/build.rs b/integration-tests/penpal/build.rs index a2cf8fdb6..adc4272c6 100644 --- a/integration-tests/penpal/build.rs +++ b/integration-tests/penpal/build.rs @@ -1,7 +1,4 @@ -// Polimec Blockchain – https://www.polimec.org/ -// Copyright (C) Polimec 2022. All rights reserved. - -// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// Copyright (C) Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Substrate is free software: you can redistribute it and/or modify diff --git a/integration-tests/penpal/src/lib.rs b/integration-tests/penpal/src/lib.rs index 90a1a477f..45377deaa 100644 --- a/integration-tests/penpal/src/lib.rs +++ b/integration-tests/penpal/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2019-2022 Parity Technologies (UK) Ltd. +// Copyright (C) Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify @@ -14,11 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -//! The Penpal runtime is designed as a test runtime that can be created using an arbitrary parachain id. -//! (and as such multiple parachains can be on the same relay node - though make sure you have enough relay -//! nodes running to support this or you will get the not scheduled on a core error message.) +//! The PenPal runtime is designed as a test runtime that can be created with an arbitrary `ParaId`, +//! such that multiple instances of the parachain can be on the same parent relay. Ensure that you +//! have enough nodes running to support this or you will get scheduling errors. //! -//! The penpal runtime's primary use is as a partner when testing statemine/t with reserve asset transfers. +//! The PenPal runtime's primary use is for testing interactions between System parachains and +//! other chains that are not trusted teleporters. + #![cfg_attr(not(feature = "std"), no_std)] // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] @@ -30,14 +32,18 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); mod weights; pub mod xcm_config; +use assets_common::MultiLocationForAssetId; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ - construct_runtime, + construct_runtime, derive_impl, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, pallet_prelude::Weight, parameter_types, - traits::{AsEnsureOriginWithArg, ConstU32, ConstU64, ConstU8, Everything, TransformOrigin}, + traits::{ + AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, Everything, TransformOrigin, WithdrawReasons, + }, weights::{ constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, FeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, @@ -48,7 +54,8 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, }; -use polimec_common::migration_types::MigrationInfo; +use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; +use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use smallvec::smallvec; use sp_api::impl_runtime_apis; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; @@ -64,22 +71,19 @@ use sp_std::prelude::*; #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use xcm_config::{AssetsToBlockAuthor, XcmConfig, XcmOriginToTransactDispatchOrigin}; +use xcm_config::{AssetsToBlockAuthor, XcmOriginToTransactDispatchOrigin}; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; // Polkadot imports -use polkadot_runtime_common::{xcm_sender::NoPriceForMessageDelivery, BlockHashCount, SlowAdjustingFeeUpdate}; +use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; // XCM Imports -use frame_support::traits::WithdrawReasons; -use parachains_common::{ - message_queue::{NarrowOriginToSibling, ParaIdToSibling}, - AccountId, Signature, -}; +use parachains_common::{AccountId, Signature}; +use polimec_common::migration_types::MigrationInfo; use sp_runtime::traits::Convert; use xcm::latest::prelude::BodyId; @@ -128,7 +132,10 @@ pub type SignedExtra = ( /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; -pub type Migrations = (pallet_balances::migration::MigrateToTrackInactive,); +pub type Migrations = ( + pallet_balances::migration::MigrateToTrackInactive, + pallet_collator_selection::migration::v1::MigrateToV1, +); /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< @@ -227,7 +234,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("penpal-parachain"), impl_name: create_runtime_str!("penpal-parachain"), authoring_version: 1, - spec_version: 9430, + spec_version: 1, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -275,12 +282,12 @@ const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts( /// Maximum number of blocks simultaneously accepted by the Runtime, not yet included /// into the relay chain. -pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1; +const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1; /// How many parachain blocks are processed by the relay chain per parent. Limits the /// number of blocks authored per slot. -pub const BLOCK_PROCESSING_VELOCITY: u32 = 1; +const BLOCK_PROCESSING_VELOCITY: u32 = 1; /// Relay chain slot duration, in milliseconds. -pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; +const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; /// The version information used to identify this runtime when compiled natively. #[cfg(feature = "std")] @@ -320,6 +327,7 @@ parameter_types! { // Configure FRAME pallets to include in runtime. +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { /// The data to be stored in an account. type AccountData = pallet_balances::AccountData; @@ -360,8 +368,6 @@ impl frame_system::Config for Runtime { type RuntimeEvent = RuntimeEvent; /// The ubiquitous origin type. type RuntimeOrigin = RuntimeOrigin; - /// The ubiquitous task type. - type RuntimeTask = RuntimeTask; /// This is used as an identifier of the chain. 42 is the generic substrate prefix. type SS58Prefix = SS58Prefix; /// Weight information for the extrinsics of this pallet. @@ -433,12 +439,12 @@ parameter_types! { // pub type AssetsForceOrigin = // EnsureOneOf, EnsureXcm>>; -impl pallet_assets::Config for Runtime { +impl pallet_assets::Config for Runtime { type ApprovalDeposit = ApprovalDeposit; type AssetAccountDeposit = AssetAccountDeposit; type AssetDeposit = AssetDeposit; type AssetId = AssetId; - type AssetIdParameter = codec::Compact; + type AssetIdParameter = parity_scale_codec::Compact; type Balance = Balance; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = (); @@ -457,11 +463,43 @@ impl pallet_assets::Config for Runtime { } parameter_types! { - pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); - pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); + // we just reuse the same deposits + pub const ForeignAssetsAssetDeposit: Balance = AssetDeposit::get(); + pub const ForeignAssetsAssetAccountDeposit: Balance = AssetAccountDeposit::get(); + pub const ForeignAssetsApprovalDeposit: Balance = ApprovalDeposit::get(); + pub const ForeignAssetsAssetsStringLimit: u32 = AssetsStringLimit::get(); + pub const ForeignAssetsMetadataDepositBase: Balance = MetadataDepositBase::get(); + pub const ForeignAssetsMetadataDepositPerByte: Balance = MetadataDepositPerByte::get(); +} + +/// Another pallet assets instance to store foreign assets from bridgehub. +pub type ForeignAssetsInstance = pallet_assets::Instance2; +impl pallet_assets::Config for Runtime { + type ApprovalDeposit = ForeignAssetsApprovalDeposit; + type AssetAccountDeposit = ForeignAssetsAssetAccountDeposit; + type AssetDeposit = ForeignAssetsAssetDeposit; + type AssetId = MultiLocationForAssetId; + type AssetIdParameter = MultiLocationForAssetId; + type Balance = Balance; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = xcm_config::XcmBenchmarkHelper; + type CallbackHandle = (); + type CreateOrigin = AsEnsureOriginWithArg>; + type Currency = Balances; + type Extra = (); + type ForceOrigin = EnsureRoot; + type Freezer = (); + type MetadataDepositBase = ForeignAssetsMetadataDepositBase; + type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte; + type RemoveItemsLimit = frame_support::traits::ConstU32<1000>; + type RuntimeEvent = RuntimeEvent; + type StringLimit = ForeignAssetsAssetsStringLimit; + type WeightInfo = pallet_assets::weights::SubstrateWeight; } parameter_types! { + pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); + pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent; } @@ -486,20 +524,6 @@ impl cumulus_pallet_parachain_system::Config for Runtime { impl parachain_info::Config for Runtime {} -impl cumulus_pallet_aura_ext::Config for Runtime {} - -impl cumulus_pallet_xcmp_queue::Config for Runtime { - type ChannelInfo = ParachainSystem; - type ControllerOrigin = EnsureRoot; - type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; - type MaxInboundSuspended = sp_core::ConstU32<1_000>; - type PriceForSiblingDelivery = NoPriceForMessageDelivery; - type RuntimeEvent = RuntimeEvent; - type VersionWrapper = PolkadotXcm; - type WeightInfo = (); - type XcmpQueue = TransformOrigin; -} - parameter_types! { pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block; } @@ -507,18 +531,33 @@ parameter_types! { impl pallet_message_queue::Config for Runtime { type HeapSize = sp_core::ConstU32<{ 64 * 1024 }>; type MaxStale = sp_core::ConstU32<8>; - #[cfg(feature = "runtime-benchmarks")] - type MessageProcessor = pallet_message_queue::mock_helpers::NoopMessageProcessor; - #[cfg(not(feature = "runtime-benchmarks"))] - type MessageProcessor = - xcm_builder::ProcessXcmMessage, RuntimeCall>; + type MessageProcessor = xcm_builder::ProcessXcmMessage< + AggregateMessageOrigin, + xcm_executor::XcmExecutor, + RuntimeCall, + >; // The XCMP queue pallet is only ever able to handle the `Sibling(ParaId)` origin: type QueueChangeHandler = NarrowOriginToSibling; type QueuePausedQuery = NarrowOriginToSibling; type RuntimeEvent = RuntimeEvent; type ServiceWeight = MessageQueueServiceWeight; type Size = u32; - type WeightInfo = pallet_message_queue::weights::SubstrateWeight; + type WeightInfo = (); +} + +impl cumulus_pallet_aura_ext::Config for Runtime {} + +impl cumulus_pallet_xcmp_queue::Config for Runtime { + type ChannelInfo = ParachainSystem; + type ControllerOrigin = EnsureRoot; + type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; + type MaxInboundSuspended = sp_core::ConstU32<1_000>; + type PriceForSiblingDelivery = NoPriceForMessageDelivery; + type RuntimeEvent = RuntimeEvent; + type VersionWrapper = PolkadotXcm; + type WeightInfo = (); + // Enqueue XCMP messages from siblings for later processing. + type XcmpQueue = TransformOrigin; } parameter_types! { @@ -541,17 +580,17 @@ impl pallet_session::Config for Runtime { } impl pallet_aura::Config for Runtime { - type AllowMultipleBlocksPerSlot = frame_support::traits::ConstBool; + type AllowMultipleBlocksPerSlot = ConstBool; type AuthorityId = AuraId; type DisabledValidators = (); type MaxAuthorities = ConstU32<100_000>; + #[cfg(feature = "experimental")] + type SlotDuration = pallet_aura::MinimumPeriodTimesTwo; } parameter_types! { pub const PotId: PalletId = PalletId(*b"PotStake"); - pub const MaxCandidates: u32 = 1000; pub const SessionLength: BlockNumber = 6 * HOURS; - pub const MaxInvulnerables: u32 = 100; pub const ExecutiveBody: BodyId = BodyId::Executive; } @@ -562,9 +601,9 @@ impl pallet_collator_selection::Config for Runtime { type Currency = Balances; // should be a multiple of session or things will get inconsistent type KickThreshold = Period; - type MaxCandidates = MaxCandidates; - type MaxInvulnerables = MaxInvulnerables; - type MinEligibleCollators = frame_support::traits::ConstU32<1>; + type MaxCandidates = ConstU32<100>; + type MaxInvulnerables = ConstU32<20>; + type MinEligibleCollators = ConstU32<4>; type PotId = PotId; type RuntimeEvent = RuntimeEvent; type UpdateOrigin = CollatorSelectionUpdateOrigin; @@ -577,7 +616,7 @@ impl pallet_collator_selection::Config for Runtime { impl pallet_asset_tx_payment::Config for Runtime { type Fungibles = Assets; type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter< - pallet_assets::BalanceToAssetBalance, + pallet_assets::BalanceToAssetBalance, AssetsToBlockAuthor, >; type RuntimeEvent = RuntimeEvent; @@ -594,7 +633,6 @@ parameter_types! { pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons = WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE); } - impl pallet_vesting::Config for Runtime { type BlockNumberProvider = System; type BlockNumberToBalance = ConvertInto; @@ -637,8 +675,6 @@ impl polimec_receiver::Config for Runtime { type Vesting = Vesting; } -impl polkadot_runtime_parachains::origin::Config for Runtime {} - // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime @@ -650,7 +686,6 @@ construct_runtime!( } = 1, Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 2, ParachainInfo: parachain_info::{Pallet, Storage, Config} = 3, - ParachainOrigin: polkadot_runtime_parachains::origin = 4, // Monetary stuff. Balances: pallet_balances::{Pallet, Call, Storage, Config, Event} = 10, @@ -668,26 +703,25 @@ construct_runtime!( XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event} = 30, PolkadotXcm: pallet_xcm::{Pallet, Call, Event, Origin, Config} = 31, CumulusXcm: cumulus_pallet_xcm::{Pallet, Event, Origin} = 32, - MessageQueue: pallet_message_queue = 34, + MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event} = 34, // The main stage. - Assets: pallet_assets::{Pallet, Call, Storage, Event} = 50, - Vesting: pallet_vesting = 51, + Assets: pallet_assets::::{Pallet, Call, Storage, Event} = 50, + ForeignAssets: pallet_assets::::{Pallet, Call, Storage, Event} = 51, + Vesting: pallet_vesting = 52, + PolimecReceiver: polimec_receiver = 69, Sudo: pallet_sudo::{Pallet, Call, Storage, Event, Config} = 255, } ); -#[cfg(feature = "runtime-benchmarks")] -#[macro_use] -extern crate frame_benchmarking; - #[cfg(feature = "runtime-benchmarks")] mod benches { - define_benchmarks!( + frame_benchmarking::define_benchmarks!( [frame_system, SystemBench::] [pallet_balances, Balances] + [pallet_message_queue, MessageQueue] [pallet_session, SessionBench::] [pallet_sudo, Sudo] [pallet_timestamp, Timestamp] @@ -880,7 +914,8 @@ impl_runtime_apis! { fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig ) -> Result, sp_runtime::RuntimeString> { - use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey}; + use frame_benchmarking::{Benchmarking, BenchmarkBatch}; + use sp_storage::TrackedStorageKey; use frame_system_benchmarking::Pallet as SystemBench; impl frame_system_benchmarking::Config for Runtime {} @@ -909,31 +944,19 @@ impl_runtime_apis! { Ok(batches) } } -} - -struct CheckInherents; -impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { - fn check_inherents( - block: &Block, - relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof, - ) -> sp_inherents::CheckInherentsResult { - let relay_chain_slot = - relay_state_proof.read_slot().expect("Could not read the relay chain slot from the proof"); - - let inherent_data = cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration( - relay_chain_slot, - sp_std::time::Duration::from_secs(6), - ) - .create_inherent_data() - .expect("Could not create the timestamp inherent data"); + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } - inherent_data.check_extrinsics(block) + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } } } cumulus_pallet_parachain_system::register_validate_block! { Runtime = Runtime, BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, - CheckInherents = CheckInherents, } diff --git a/integration-tests/penpal/src/weights/block_weights.rs b/integration-tests/penpal/src/weights/block_weights.rs index d87144b01..e4dfb61f5 100644 --- a/integration-tests/penpal/src/weights/block_weights.rs +++ b/integration-tests/penpal/src/weights/block_weights.rs @@ -1,6 +1,6 @@ // This file is part of Substrate. -// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// Copyright (C) Parity Technologies (UK) Ltd. // SPDX-License-Identifier: Apache-2.0 // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/integration-tests/penpal/src/weights/extrinsic_weights.rs b/integration-tests/penpal/src/weights/extrinsic_weights.rs index 55b3706db..e7fab659d 100644 --- a/integration-tests/penpal/src/weights/extrinsic_weights.rs +++ b/integration-tests/penpal/src/weights/extrinsic_weights.rs @@ -1,6 +1,6 @@ // This file is part of Substrate. -// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// Copyright (C) Parity Technologies (UK) Ltd. // SPDX-License-Identifier: Apache-2.0 // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/integration-tests/penpal/src/weights/mod.rs b/integration-tests/penpal/src/weights/mod.rs index ef1ab0d1a..b473d49e2 100644 --- a/integration-tests/penpal/src/weights/mod.rs +++ b/integration-tests/penpal/src/weights/mod.rs @@ -1,6 +1,6 @@ // This file is part of Substrate. -// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// Copyright (C) Parity Technologies (UK) Ltd. // SPDX-License-Identifier: Apache-2.0 // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/integration-tests/penpal/src/weights/paritydb_weights.rs b/integration-tests/penpal/src/weights/paritydb_weights.rs index 4338d928d..256797038 100644 --- a/integration-tests/penpal/src/weights/paritydb_weights.rs +++ b/integration-tests/penpal/src/weights/paritydb_weights.rs @@ -1,6 +1,6 @@ // This file is part of Substrate. -// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// Copyright (C) Parity Technologies (UK) Ltd. // SPDX-License-Identifier: Apache-2.0 // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/integration-tests/penpal/src/weights/rocksdb_weights.rs b/integration-tests/penpal/src/weights/rocksdb_weights.rs index 1d115d963..3dd817aa6 100644 --- a/integration-tests/penpal/src/weights/rocksdb_weights.rs +++ b/integration-tests/penpal/src/weights/rocksdb_weights.rs @@ -1,6 +1,6 @@ // This file is part of Substrate. -// Copyright (C) 2022 Parity Technologies (UK) Ltd. +// Copyright (C) Parity Technologies (UK) Ltd. // SPDX-License-Identifier: Apache-2.0 // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/integration-tests/penpal/src/xcm_config.rs b/integration-tests/penpal/src/xcm_config.rs index 0d5b5b9d6..bb1df9416 100644 --- a/integration-tests/penpal/src/xcm_config.rs +++ b/integration-tests/penpal/src/xcm_config.rs @@ -1,7 +1,4 @@ -// Polimec Blockchain – https://www.polimec.org/ -// Copyright (C) Polimec 2022. All rights reserved. - -// Copyright 2019-2022 Parity Technologies (UK) Ltd. +// Copyright (C) Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify @@ -22,11 +19,13 @@ //! This configuration dictates how the Penpal chain will communicate with other chains. //! //! One of the main uses of the penpal chain will be to be a benefactor of reserve asset transfers -//! with statemine as the reserve. At present no derivative tokens are minted on receipt of a -//! ReserveAssetTransferDeposited message but that will but the intension will be to support this soon. +//! with Asset Hub as the reserve. At present no derivative tokens are minted on receipt of a +//! `ReserveAssetTransferDeposited` message but that will but the intension will be to support this +//! soon. use super::{ - AccountId, AllPalletsWithSystem, AssetId as AssetIdPalletAssets, Assets, Balance, Balances, ParachainInfo, - ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, + AccountId, AllPalletsWithSystem, AssetId as AssetIdPalletAssets, Assets, Balance, Balances, ForeignAssets, + ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, + XcmpQueue, }; use core::marker::PhantomData; use frame_support::{ @@ -39,25 +38,28 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_asset_tx_payment::HandleCredit; +use pallet_assets::Instance1; use pallet_xcm::XcmPassthrough; use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::impls::ToAuthor; +use snowbridge_rococo_common::EthereumNetwork; use sp_runtime::traits::Zero; use xcm::latest::prelude::*; +#[allow(deprecated)] use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSubscriptionsFrom, - AllowTopLevelPaidExecutionFrom, AsPrefixedGeneralIndex, ConvertedConcreteId, DenyReserveTransferToRelayChain, - DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, FungibleAdapter, FungiblesAdapter, IsConcrete, LocalMint, - NativeAsset, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, - WithComputedOrigin, + AllowTopLevelPaidExecutionFrom, AsPrefixedGeneralIndex, ConvertedConcreteId, CurrencyAdapter, EnsureXcmOrigin, + FixedWeightBounds, FrameTransactionalProcessor, FungiblesAdapter, IsConcrete, LocalMint, NativeAsset, NoChecking, + ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, StartsWith, TakeWeightCredit, + TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, }; use xcm_executor::{traits::JustTry, XcmExecutor}; parameter_types! { pub const RelayLocation: MultiLocation = MultiLocation::parent(); - pub const RelayNetwork: Option = None; pub const HereLocation: MultiLocation = MultiLocation::here(); + pub const RelayNetwork: Option = None; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorMultiLocation = X1(Parachain(ParachainInfo::parachain_id().into())); } @@ -75,7 +77,8 @@ pub type LocationToAccountId = ( ); /// Means for transacting assets on this chain. -pub type CurrencyTransactor = FungibleAdapter< +#[allow(deprecated)] +pub type CurrencyTransactor = CurrencyAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: @@ -93,12 +96,20 @@ pub type FungiblesTransactor = FungiblesAdapter< // Use this fungibles implementation: Assets, // Use this currency when it is a fungible asset matching the given location or name: - ConvertedConcreteId< - AssetIdPalletAssets, - Balance, - AsPrefixedGeneralIndex, - JustTry, - >, + ( + ConvertedConcreteId< + AssetIdPalletAssets, + Balance, + AsPrefixedGeneralIndex, + JustTry, + >, + ConvertedConcreteId< + AssetIdPalletAssets, + Balance, + AsPrefixedGeneralIndex, + JustTry, + >, + ), // Convert an XCM MultiLocation into a local account id: LocationToAccountId, // Our chain's account ID type (we can't get away without mentioning it explicitly): @@ -110,8 +121,28 @@ pub type FungiblesTransactor = FungiblesAdapter< CheckingAccount, >; +/// `AssetId/Balance` converter for `TrustBackedAssets` +pub type ForeignAssetsConvertedConcreteId = + assets_common::ForeignAssetsConvertedConcreteId, Balance>; + +/// Means for transacting foreign assets from different global consensus. +pub type ForeignFungiblesTransactor = FungiblesAdapter< + // Use this fungibles implementation: + ForeignAssets, + // Use this currency when it is a fungible asset matching the given location or name: + ForeignAssetsConvertedConcreteId, + // Convert an XCM MultiLocation into a local account id: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We dont need to check teleports here. + NoChecking, + // The account to use for tracking teleports. + CheckingAccount, +>; + /// Means for transacting assets on this chain. -pub type AssetTransactors = (CurrencyTransactor, FungiblesTransactor); +pub type AssetTransactors = (CurrencyTransactor, ForeignFungiblesTransactor, FungiblesTransactor); /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, /// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can @@ -126,7 +157,10 @@ pub type XcmOriginToTransactDispatchOrigin = ( RelayChainAsNative, // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when // recognized. - SiblingParachainAsNative, + SiblingParachainAsNative, + // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a + // transaction from the Root origin. + ParentAsSuperuser, // Native signed account converter; this just converts an `AccountId32` origin into a normal // `RuntimeOrigin::Signed` origin of the same 32-byte value. SignedAccountId32AsNative, @@ -154,43 +188,55 @@ match_types! { }; } -pub type Barrier = DenyThenTry< - DenyReserveTransferToRelayChain, - ( - TakeWeightCredit, - // Expected responses are OK. - AllowKnownQueryResponses, - // Allow XCMs with some computed origins to pass through. - WithComputedOrigin< - ( - // If the message is one that immediately attemps to pay for execution, then allow it. - AllowTopLevelPaidExecutionFrom, - // Polimec, Common Good Assets parachain, parent and its exec plurality get free execution - AllowExplicitUnpaidExecutionFrom<( - CommonGoodAssetsParachain, - ParentOrParentsExecutivePlurality, - Polimec, - )>, - // Subscriptions for version tracking are OK. - AllowSubscriptionsFrom, - ), - UniversalLocation, - ConstU32<8>, - >, - ), ->; +pub type Barrier = TrailingSetTopicAsId<( + TakeWeightCredit, + // Expected responses are OK. + AllowKnownQueryResponses, + // Allow XCMs with some computed origins to pass through. + WithComputedOrigin< + ( + // If the message is one that immediately attempts to pay for execution, then + // allow it. + AllowTopLevelPaidExecutionFrom, + // System Assets parachain, parent and its exec plurality get free + // execution + AllowExplicitUnpaidExecutionFrom<(CommonGoodAssetsParachain, ParentOrParentsExecutivePlurality, Polimec)>, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, + ), + UniversalLocation, + ConstU32<8>, + >, +)>; /// Type alias to conveniently refer to `frame_system`'s `Config::AccountId`. pub type AccountIdOf = ::AccountId; -/// Asset filter that allows all assets from a certain location. -pub struct AssetsFrom(PhantomData); -impl> ContainsPair for AssetsFrom { +/// Asset filter that allows all assets from a certain location matching asset id. +pub struct AssetPrefixFrom(PhantomData<(Prefix, Origin)>); +impl ContainsPair for AssetPrefixFrom +where + Prefix: Get, + Origin: Get, +{ + fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool { + let loc = Origin::get(); + &loc == origin && + matches!(asset, MultiAsset { id: AssetId::Concrete(asset_loc), fun: Fungible(_a) } + if asset_loc.starts_with(&Prefix::get())) + } +} + +type AssetsFrom = AssetPrefixFrom; + +/// Asset filter that allows native/relay asset if coming from a certain location. +pub struct NativeAssetFrom(PhantomData); +impl> ContainsPair for NativeAssetFrom { fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool { let loc = T::get(); &loc == origin && matches!(asset, MultiAsset { id: AssetId::Concrete(asset_loc), fun: Fungible(_a) } - if asset_loc.match_and_split(&loc).is_some()) + if *asset_loc == MultiLocation::from(Parent)) } } @@ -209,66 +255,57 @@ where /// A `HandleCredit` implementation that naively transfers the fees to the block author. /// Will drop and burn the assets in case the transfer fails. pub struct AssetsToBlockAuthor(PhantomData); -impl HandleCredit, pallet_assets::Pallet> for AssetsToBlockAuthor +impl HandleCredit, pallet_assets::Pallet> for AssetsToBlockAuthor where - R: pallet_authorship::Config + pallet_assets::Config, + R: pallet_authorship::Config + pallet_assets::Config, AccountIdOf: From + Into, { - fn handle_credit(credit: Credit, pallet_assets::Pallet>) { + fn handle_credit(credit: Credit, pallet_assets::Pallet>) { if let Some(author) = pallet_authorship::Pallet::::author() { // In case of error: Will drop the result triggering the `OnDrop` of the imbalance. - let _ = pallet_assets::Pallet::::resolve(&author, credit); + let _ = pallet_assets::Pallet::::resolve(&author, credit); } } } -pub trait Reserve { - /// Returns assets reserve location. - fn reserve(&self) -> Option; -} - -// Takes the chain part of a MultiAsset -impl Reserve for MultiAsset { - fn reserve(&self) -> Option { - if let AssetId::Concrete(location) = self.id { - let first_interior = location.first_interior(); - let parents = location.parent_count(); - match (parents, first_interior) { - (0, Some(Parachain(id))) => Some(MultiLocation::new(0, X1(Parachain(*id)))), - (1, Some(Parachain(id))) => Some(MultiLocation::new(1, X1(Parachain(*id)))), - (1, _) => Some(MultiLocation::parent()), - _ => None, - } - } else { - None - } - } +// This asset can be added to AH as ForeignAsset and teleported between Penpal and AH +pub const TELEPORTABLE_ASSET_ID: u32 = 2; +parameter_types! { + /// The location that this chain recognizes as the Relay network's Asset Hub. + pub SystemAssetHubLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(1000))); + // ALWAYS ensure that the index in PalletInstance stays up-to-date with + // the Relay Chain's Asset Hub's Assets pallet index + pub SystemAssetHubAssetsPalletLocation: MultiLocation = + MultiLocation::new(1, X2(Parachain(1000), PalletInstance(50))); + pub AssetsPalletLocation: MultiLocation = + MultiLocation::new(0, X1(PalletInstance(50))); + pub CheckingAccount: AccountId = PolkadotXcm::check_account(); + pub LocalTeleportableToAssetHub: MultiLocation = MultiLocation::new( + 0, + X2(PalletInstance(50), GeneralIndex(TELEPORTABLE_ASSET_ID.into())) + ); + pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get()))); } -/// A `FilterAssetLocation` implementation. Filters multi native assets whose -/// reserve is same with `origin`. -pub struct MultiNativeAsset; -impl ContainsPair for MultiNativeAsset { +/// Accepts asset with ID `AssetLocation` and is coming from `Origin` chain. +pub struct AssetFromChain(PhantomData<(AssetLocation, Origin)>); +impl, Origin: Get> ContainsPair + for AssetFromChain +{ fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool { - if let Some(ref reserve) = asset.reserve() { - if reserve == origin { - return true; - } - } - false + log::trace!(target: "xcm::contains", "AssetFromChain asset: {:?}, origin: {:?}", asset, origin); + *origin == Origin::get() && matches!(asset.id, Concrete(id) if id == AssetLocation::get()) } } -parameter_types! { - pub CommonGoodAssetsLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(1000))); - // ALWAYS ensure that the index in PalletInstance stays up-to-date with - // AssetHub's Assets pallet index - pub CommonGoodAssetsPalletLocation: MultiLocation = - MultiLocation::new(1, X2(Parachain(1000), PalletInstance(50))); - pub CheckingAccount: AccountId = PolkadotXcm::check_account(); -} +pub type Reserves = ( + NativeAsset, + AssetsFrom, + NativeAssetFrom, + AssetPrefixFrom, +); -pub type Reserves = (NativeAsset, AssetsFrom); +pub type TrustedTeleporters = AssetFromChain; pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { @@ -282,9 +319,9 @@ impl xcm_executor::Config for XcmConfig { type Barrier = Barrier; type CallDispatcher = RuntimeCall; type FeeManager = (); - type IsReserve = MultiNativeAsset; - // TODO: maybe needed to be replaced by Reserves - type IsTeleporter = NativeAsset; + type IsReserve = Reserves; + // no teleport trust established with other chains + type IsTeleporter = TrustedTeleporters; type MaxAssetsIntoHolding = MaxAssetsIntoHolding; type MessageExporter = (); type OriginConverter = XcmOriginToTransactDispatchOrigin; @@ -294,7 +331,7 @@ impl xcm_executor::Config for XcmConfig { type SafeCallFilter = Everything; type SubscriptionService = PolkadotXcm; type Trader = UsingComponents>; - type TransactionalProcessor = (); + type TransactionalProcessor = FrameTransactionalProcessor; type UniversalAliases = Nothing; type UniversalLocation = UniversalLocation; type Weigher = FixedWeightBounds; @@ -306,29 +343,21 @@ 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 AdminOrigin = EnsureRoot; - // ^ Override for AdvertisedXcmVersion default type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; type Currency = Balances; type CurrencyMatcher = (); type ExecuteXcmOrigin = EnsureXcmOrigin; type MaxLockers = ConstU32<8>; type MaxRemoteLockConsumers = ConstU32<0>; - #[cfg(feature = "runtime-benchmarks")] - type ReachableDest = ReachableDest; type RemoteLockConsumerIdentifier = (); type RuntimeCall = RuntimeCall; type RuntimeEvent = RuntimeEvent; @@ -339,9 +368,7 @@ impl pallet_xcm::Config for Runtime { type UniversalLocation = UniversalLocation; type Weigher = FixedWeightBounds; type WeightInfo = pallet_xcm::TestWeightInfo; - type XcmExecuteFilter = Nothing; - // ^ Disable dispatchable execute on the XCM pallet. - // Needs to be `Everything` for local testing. + type XcmExecuteFilter = Everything; type XcmExecutor = XcmExecutor; type XcmReserveTransferFilter = Everything; type XcmRouter = XcmRouter; @@ -354,3 +381,12 @@ impl cumulus_pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; } + +/// Simple conversion of `u32` into an `AssetId` for use in benchmarking. +pub struct XcmBenchmarkHelper; +#[cfg(feature = "runtime-benchmarks")] +impl pallet_assets::BenchmarkHelper for XcmBenchmarkHelper { + fn create_asset_id_parameter(id: u32) -> MultiLocation { + MultiLocation { parents: 1, interior: X1(Parachain(id)) } + } +} diff --git a/pallets/polimec-receiver/Cargo.toml b/pallets/polimec-receiver/Cargo.toml index b274cef4e..b09904b3c 100644 --- a/pallets/polimec-receiver/Cargo.toml +++ b/pallets/polimec-receiver/Cargo.toml @@ -21,7 +21,7 @@ frame-benchmarking = { workspace = true, optional = true} frame-support.workspace = true frame-system.workspace = true sp-std.workspace = true -polkadot-runtime-parachains.workspace = true +cumulus-pallet-xcm.workspace = true polkadot-parachain-primitives.workspace = true polimec-common.workspace = true sp-runtime.workspace = true @@ -42,7 +42,6 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "polimec-common/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", - "polkadot-runtime-parachains/runtime-benchmarks", "sp-runtime/runtime-benchmarks", ] std = [ @@ -53,7 +52,6 @@ std = [ "log/std", "polimec-common/std", "polkadot-parachain-primitives/std", - "polkadot-runtime-parachains/std", "scale-info/std", "serde/std", "sp-core/std", @@ -65,6 +63,5 @@ try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", "polimec-common/try-runtime", - "polkadot-runtime-parachains/try-runtime", "sp-runtime/try-runtime", ] diff --git a/pallets/polimec-receiver/src/lib.rs b/pallets/polimec-receiver/src/lib.rs index 0ff55fc09..ea5e79c4b 100644 --- a/pallets/polimec-receiver/src/lib.rs +++ b/pallets/polimec-receiver/src/lib.rs @@ -21,6 +21,7 @@ pub use pallet::*; #[frame_support::pallet] pub mod pallet { + use cumulus_pallet_xcm::{ensure_sibling_para, Origin as ParachainOrigin}; use frame_support::{ pallet_prelude::*, traits::{tokens::Balance, Currency, ExistenceRequirement::KeepAlive, VestingSchedule}, @@ -28,7 +29,6 @@ pub mod pallet { use frame_system::pallet_prelude::*; use polimec_common::migration_types::{Migration, MigrationInfo, MigrationOrigin, Migrations, ParticipationType}; use polkadot_parachain_primitives::primitives::{Id as ParaId, Sibling}; - use polkadot_runtime_parachains::origin::{ensure_parachain, Origin as ParachainOrigin}; use sp_runtime::traits::{AccountIdConversion, Convert}; use sp_std::prelude::*; @@ -98,7 +98,7 @@ pub mod pallet { #[pallet::call_index(0)] #[pallet::weight(Weight::from_parts(10_000, 0))] pub fn execute_migrations(origin: OriginFor, migrations: Migrations) -> DispatchResult { - let para_id: ParaId = ensure_parachain(::RuntimeOrigin::from(origin))?; + let para_id: ParaId = ensure_sibling_para(::RuntimeOrigin::from(origin))?; let polimec_id = T::PolimecParaId::get(); let polimec_soverign_account = Sibling(polimec_id).into_account_truncating(); diff --git a/runtimes/polimec/src/xcm_config.rs b/runtimes/polimec/src/xcm_config.rs index 442e0e75f..f39503b81 100644 --- a/runtimes/polimec/src/xcm_config.rs +++ b/runtimes/polimec/src/xcm_config.rs @@ -34,10 +34,10 @@ use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::traits::MaybeEquivalence; use xcm::latest::prelude::*; use xcm_builder::{ - AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSubscriptionsFrom, - AllowTopLevelPaidExecutionFrom, CreateMatcher, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, - FixedRateOfFungible, FixedWeightBounds, FungibleAdapter, FungiblesAdapter, IsConcrete, MatchXcm, - MatchedConvertedConcreteId, MintLocation, NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, + CreateMatcher, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedRateOfFungible, + FixedWeightBounds, FungibleAdapter, FungiblesAdapter, IsConcrete, MatchXcm, MatchedConvertedConcreteId, + MintLocation, NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WithComputedOrigin, }; @@ -226,7 +226,37 @@ match_types! { MultiLocation { parents: 1, interior: X1(Parachain(_)) } }; } - +use polimec_xcm_executor::polimec_traits::OnResponse; +/// Allows only messages if the generic `ResponseHandler` expects them via `expecting_response`. +pub struct AllowKnownQueryResponses(PhantomData); +impl ShouldExecute for AllowKnownQueryResponses { + fn should_execute( + origin: &MultiLocation, + instructions: &mut [Instruction], + _max_weight: Weight, + _properties: &mut Properties, + ) -> Result<(), ProcessMessageError> { + log::trace!( + target: "xcm::barriers", + "AllowKnownQueryResponses origin: {:?}, instructions: {:?}, max_weight: {:?}, properties: {:?}", + origin, instructions, _max_weight, _properties, + ); + instructions + .matcher() + .assert_remaining_insts(2)? + .match_next_inst(|inst| match inst { + QueryResponse { query_id, querier, .. } + if ResponseHandler::expecting_response(origin, *query_id, querier.as_ref()) => + Ok(()), + _ => Err(ProcessMessageError::BadFormat), + })? + .match_next_inst(|inst| match inst { + SetTopic { .. } => Ok(()), + _ => Err(ProcessMessageError::BadFormat), + })?; + Ok(()) + } +} pub type Barrier = DenyThenTry< DenyReserveTransferToRelayChain, (