diff --git a/.github/workflows/check_tests.yml b/.github/workflows/check_tests.yml index 006561012..077e035a2 100644 --- a/.github/workflows/check_tests.yml +++ b/.github/workflows/check_tests.yml @@ -186,11 +186,38 @@ jobs: sudo rm -rf /usr/local/lib/android sudo rm -rf /usr/share/dotnet df -h - - name: create-chainspec + - name: build benchmarking binary run: | RUSTC_BOOTSTRAP=1 cargo build --release --features runtime-benchmarks + - name: create-calamari-chainspec + run: | ${{ github.workspace }}/target/release/manta build-spec --chain calamari-dev --disable-default-bootnode --raw > ${{ github.workspace }}/tests/data/fork.json - - name: append manta-pay storage + - name: append manta-pay storage for Calamari + run: | + wget -P ${{ github.workspace }}/tests/data https://manta-ops.s3.amazonaws.com/integration-tests-data/storage.json + cd ${{ github.workspace }}/tests + yarn install + yarn + node append_storage.js + - name: Run live benchmarks test + env: + RUST_BACKTRACE: full + RUSTC_WRAPPER: sccache + SCCACHE_CACHE_SIZE: 120G + SCCACHE_DIR: /home/runner/.cache/sccache + run: | + ${{ github.workspace }}/target/release/manta \ + benchmark \ + pallet \ + --chain=${{ github.workspace }}/tests/data/fork.json \ + --pallet=* \ + --extrinsic=* \ + --repeat=1 \ + --steps=2 + - name: create-manta-dev-chainspec + run: | + ${{ github.workspace }}/target/release/manta build-spec --chain manta-dev --disable-default-bootnode --raw > ${{ github.workspace }}/tests/data/fork.json + - name: append manta-pay storage for Manta run: | wget -P ${{ github.workspace }}/tests/data https://manta-ops.s3.amazonaws.com/integration-tests-data/storage.json cd ${{ github.workspace }}/tests diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d246adfc..600231e9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## v4.3.0 ### Added -- [\#1179](https://github.com/Manta-Network/Manta/pull/1179) Name Service Pallet [CA] +- [\#1179](https://github.com/Manta-Network/Manta/pull/1179) Copy Name Service Pallet [CA] - [\#1141](https://github.com/Manta-Network/Manta/pull/1141) manta-farming [MACA] - [\#1036](https://github.com/Manta-Network/Manta/pull/1036) Pallet Staking Lottery [MACA] @@ -11,6 +11,8 @@ ### Fixed - [\#1175](https://github.com/Manta-Network/Manta/pull/1175) Fix congestion test CI [MACA] +- [\#1193](https://github.com/Manta-Network/Manta/pull/1193) Revert to v0942 polkadot binary [MACA] +- [\#1196](https://github.com/Manta-Network/Manta/pull/1196) Fix dex ed [MA] ### Removed - [\#1167](https://github.com/Manta-Network/Manta/pull/1167) Retire dolphin runtime [DO] diff --git a/Cargo.lock b/Cargo.lock index f0e17803f..cd585cccc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14986,7 +14986,7 @@ dependencies = [ [[package]] name = "zenlink-protocol" version = "0.4.4" -source = "git+https://github.com/manta-network/Zenlink?branch=polkadot-v0.9.37#af453d294541b87033a6ee4e22ce5151c581acc1" +source = "git+https://github.com/manta-network/Zenlink?branch=polkadot-v0.9.37#c2acc36bea02e6c2aa38f3b290e255dfd5c164dd" dependencies = [ "frame-benchmarking", "frame-support", @@ -15006,7 +15006,7 @@ dependencies = [ [[package]] name = "zenlink-protocol-rpc" version = "0.4.4" -source = "git+https://github.com/manta-network/Zenlink?branch=polkadot-v0.9.37#af453d294541b87033a6ee4e22ce5151c581acc1" +source = "git+https://github.com/manta-network/Zenlink?branch=polkadot-v0.9.37#c2acc36bea02e6c2aa38f3b290e255dfd5c164dd" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -15021,7 +15021,7 @@ dependencies = [ [[package]] name = "zenlink-protocol-runtime-api" version = "0.4.4" -source = "git+https://github.com/manta-network/Zenlink?branch=polkadot-v0.9.37#af453d294541b87033a6ee4e22ce5151c581acc1" +source = "git+https://github.com/manta-network/Zenlink?branch=polkadot-v0.9.37#c2acc36bea02e6c2aa38f3b290e255dfd5c164dd" dependencies = [ "parity-scale-codec", "sp-api", diff --git a/primitives/manta/src/xcm.rs b/primitives/manta/src/xcm.rs index db2000ab4..a70112562 100644 --- a/primitives/manta/src/xcm.rs +++ b/primitives/manta/src/xcm.rs @@ -26,12 +26,18 @@ use sp_std::marker::PhantomData; use crate::assets::{AssetIdLocationMap, UnitsPerSecond}; use frame_support::{ + ensure, pallet_prelude::Get, - traits::{fungibles::Mutate, tokens::ExistenceRequirement}, + traits::{fungibles::Mutate, tokens::ExistenceRequirement, Contains}, }; use frame_system::Config; use xcm::{ - latest::{prelude::Concrete, Error as XcmError}, + latest::{ + prelude::{BuyExecution, Concrete, DescendOrigin, WithdrawAsset}, + Error as XcmError, + WeightLimit::{Limited, Unlimited}, + Xcm, + }, v1::{ AssetId as XcmAssetId, Fungibility, Junction::{AccountId32, Parachain}, @@ -43,7 +49,7 @@ use xcm_builder::TakeRevenue; use xcm_executor::{ traits::{ Convert as XcmConvert, FilterAssetLocation, MatchesFungible, MatchesFungibles, - TransactAsset, WeightTrader, + ShouldExecute, TransactAsset, WeightTrader, }, Assets, }; @@ -410,3 +416,52 @@ where Ok(asset.clone().into()) } } + +/// Barrier allowing a top level paid message with DescendOrigin instruction first +pub struct AllowTopLevelPaidExecutionDescendOriginFirst(PhantomData); +impl> ShouldExecute for AllowTopLevelPaidExecutionDescendOriginFirst { + fn should_execute( + origin: &MultiLocation, + message: &mut Xcm, + max_weight: u64, + _weight_credit: &mut u64, + ) -> Result<(), ()> { + log::trace!( + target: "xcm::barriers", + "AllowTopLevelPaidExecutionDescendOriginFirst origin: + {:?}, message: {:?}, max_weight: {:?}, weight_credit: {:?}", + origin, message, max_weight, _weight_credit, + ); + ensure!(T::contains(origin), ()); + let mut iter = message.0.iter_mut(); + // Make sure the first instruction is DescendOrigin + iter.next() + .filter(|instruction| matches!(instruction, DescendOrigin(_))) + .ok_or(())?; + + // Then WithdrawAsset + iter.next() + .filter(|instruction| matches!(instruction, WithdrawAsset(_))) + .ok_or(())?; + + // Then BuyExecution + let i = iter.next().ok_or(())?; + match i { + BuyExecution { + weight_limit: Limited(ref mut weight), + .. + } if *weight >= max_weight => { + *weight = max_weight; + Ok(()) + } + BuyExecution { + ref mut weight_limit, + .. + } if weight_limit == &Unlimited => { + *weight_limit = Limited(max_weight); + Ok(()) + } + _ => Err(()), + } + } +} diff --git a/runtime/calamari/src/weights/zenlink_protocol.rs b/runtime/calamari/src/weights/zenlink_protocol.rs index 632db2d69..186b2217e 100644 --- a/runtime/calamari/src/weights/zenlink_protocol.rs +++ b/runtime/calamari/src/weights/zenlink_protocol.rs @@ -17,7 +17,7 @@ //! Autogenerated weights for zenlink_protocol //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-07-07, STEPS: `50`, REPEAT: 40, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-07-11, STEPS: `50`, REPEAT: 40, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("/home/runner/runners/2.280.1/_work/Manta/Manta/tests/data/fork.json"), DB CACHE: 1024 // Executed Command: @@ -66,15 +66,15 @@ pub struct SubstrateWeight(PhantomData); impl zenlink_protocol::WeightInfo for SubstrateWeight { // Storage: ZenlinkProtocol FeeMeta (r:1 w:1) fn set_fee_receiver() -> Weight { - // Minimum execution time: 7_870 nanoseconds. - Weight::from_ref_time(8_202_000) + // Minimum execution time: 7_753 nanoseconds. + Weight::from_ref_time(8_045_000) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: ZenlinkProtocol FeeMeta (r:1 w:1) fn set_fee_point() -> Weight { - // Minimum execution time: 7_468 nanoseconds. - Weight::from_ref_time(7_732_000) + // Minimum execution time: 7_232 nanoseconds. + Weight::from_ref_time(7_540_000) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -83,8 +83,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 40_796 nanoseconds. - Weight::from_ref_time(42_016_000) + // Minimum execution time: 29_470 nanoseconds. + Weight::from_ref_time(32_130_000) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -92,8 +92,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 24_286 nanoseconds. - Weight::from_ref_time(25_607_000) + // Minimum execution time: 22_982 nanoseconds. + Weight::from_ref_time(25_660_000) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(3)) } @@ -103,8 +103,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 65_180 nanoseconds. - Weight::from_ref_time(69_190_000) + // Minimum execution time: 64_517 nanoseconds. + Weight::from_ref_time(65_317_000) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -123,8 +123,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 253_274 nanoseconds. - Weight::from_ref_time(266_628_000) + // Minimum execution time: 253_726 nanoseconds. + Weight::from_ref_time(256_141_000) .saturating_add(T::DbWeight::get().reads(24)) .saturating_add(T::DbWeight::get().writes(20)) } @@ -142,8 +142,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 227_976 nanoseconds. - Weight::from_ref_time(243_089_000) + // Minimum execution time: 230_524 nanoseconds. + Weight::from_ref_time(233_518_000) .saturating_add(T::DbWeight::get().reads(23)) .saturating_add(T::DbWeight::get().writes(32)) } @@ -151,8 +151,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 29_541 nanoseconds. - Weight::from_ref_time(31_770_000) + // Minimum execution time: 31_760 nanoseconds. + Weight::from_ref_time(32_326_000) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(3)) } @@ -161,8 +161,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 65_667 nanoseconds. - Weight::from_ref_time(69_653_000) + // Minimum execution time: 64_871 nanoseconds. + Weight::from_ref_time(70_596_000) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -180,8 +180,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 236_324 nanoseconds. - Weight::from_ref_time(249_001_000) + // Minimum execution time: 238_430 nanoseconds. + Weight::from_ref_time(259_648_000) .saturating_add(T::DbWeight::get().reads(25)) .saturating_add(T::DbWeight::get().writes(29)) } @@ -198,8 +198,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 174_439 nanoseconds. - Weight::from_ref_time(185_116_000) + // Minimum execution time: 174_527 nanoseconds. + Weight::from_ref_time(176_416_000) .saturating_add(T::DbWeight::get().reads(19)) .saturating_add(T::DbWeight::get().writes(14)) } @@ -207,8 +207,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 102_445 nanoseconds. - Weight::from_ref_time(103_807_000) + // Minimum execution time: 102_847 nanoseconds. + Weight::from_ref_time(103_961_000) .saturating_add(T::DbWeight::get().reads(9)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -216,8 +216,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 102_448 nanoseconds. - Weight::from_ref_time(103_698_000) + // Minimum execution time: 102_805 nanoseconds. + Weight::from_ref_time(104_156_000) .saturating_add(T::DbWeight::get().reads(9)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -227,15 +227,15 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 7_870 nanoseconds. - Weight::from_ref_time(8_202_000) + // Minimum execution time: 7_753 nanoseconds. + Weight::from_ref_time(8_045_000) .saturating_add(RocksDbWeight::get().reads(1)) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: ZenlinkProtocol FeeMeta (r:1 w:1) fn set_fee_point() -> Weight { - // Minimum execution time: 7_468 nanoseconds. - Weight::from_ref_time(7_732_000) + // Minimum execution time: 7_232 nanoseconds. + Weight::from_ref_time(7_540_000) .saturating_add(RocksDbWeight::get().reads(1)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -244,8 +244,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol PairStatuses (r:1 w:1) // Storage: ZenlinkProtocol LiquidityPairs (r:0 w:1) fn create_pair() -> Weight { - // Minimum execution time: 40_796 nanoseconds. - Weight::from_ref_time(42_016_000) + // Minimum execution time: 29_470 nanoseconds. + Weight::from_ref_time(32_130_000) .saturating_add(RocksDbWeight::get().reads(3)) .saturating_add(RocksDbWeight::get().writes(2)) } @@ -253,8 +253,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol BootstrapLimits (r:0 w:1) // Storage: ZenlinkProtocol BootstrapRewards (r:0 w:1) fn bootstrap_create() -> Weight { - // Minimum execution time: 24_286 nanoseconds. - Weight::from_ref_time(25_607_000) + // Minimum execution time: 22_982 nanoseconds. + Weight::from_ref_time(25_660_000) .saturating_add(RocksDbWeight::get().reads(1)) .saturating_add(RocksDbWeight::get().writes(3)) } @@ -264,8 +264,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol PairStatuses (r:1 w:1) // Storage: ZenlinkProtocol BootstrapPersonalSupply (r:1 w:1) fn bootstrap_contribute() -> Weight { - // Minimum execution time: 65_180 nanoseconds. - Weight::from_ref_time(69_190_000) + // Minimum execution time: 64_517 nanoseconds. + Weight::from_ref_time(65_317_000) .saturating_add(RocksDbWeight::get().reads(8)) .saturating_add(RocksDbWeight::get().writes(6)) } @@ -284,8 +284,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol ForeignLedger (r:2 w:2) // Storage: AssetManager AssetIdMetadata (r:0 w:4) fn bootstrap_claim() -> Weight { - // Minimum execution time: 253_274 nanoseconds. - Weight::from_ref_time(266_628_000) + // Minimum execution time: 253_726 nanoseconds. + Weight::from_ref_time(256_141_000) .saturating_add(RocksDbWeight::get().reads(24)) .saturating_add(RocksDbWeight::get().writes(20)) } @@ -303,8 +303,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol LiquidityPairs (r:0 w:1) // Storage: ZenlinkProtocol BootstrapEndStatus (r:0 w:1) fn bootstrap_end() -> Weight { - // Minimum execution time: 227_976 nanoseconds. - Weight::from_ref_time(243_089_000) + // Minimum execution time: 230_524 nanoseconds. + Weight::from_ref_time(233_518_000) .saturating_add(RocksDbWeight::get().reads(23)) .saturating_add(RocksDbWeight::get().writes(32)) } @@ -312,8 +312,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol BootstrapRewards (r:1 w:1) // Storage: ZenlinkProtocol BootstrapLimits (r:0 w:1) fn bootstrap_update() -> Weight { - // Minimum execution time: 29_541 nanoseconds. - Weight::from_ref_time(31_770_000) + // Minimum execution time: 31_760 nanoseconds. + Weight::from_ref_time(32_326_000) .saturating_add(RocksDbWeight::get().reads(2)) .saturating_add(RocksDbWeight::get().writes(3)) } @@ -322,8 +322,8 @@ impl WeightInfo for () { // Storage: ParachainInfo ParachainId (r:1 w:0) // Storage: ZenlinkProtocol ForeignLedger (r:4 w:4) fn bootstrap_refund() -> Weight { - // Minimum execution time: 65_667 nanoseconds. - Weight::from_ref_time(69_653_000) + // Minimum execution time: 64_871 nanoseconds. + Weight::from_ref_time(70_596_000) .saturating_add(RocksDbWeight::get().reads(7)) .saturating_add(RocksDbWeight::get().writes(6)) } @@ -341,8 +341,8 @@ impl WeightInfo for () { // Storage: AssetManager AssetIdMetadata (r:0 w:5) // Storage: AssetManager AssetIdLocation (r:0 w:3) fn add_liquidity() -> Weight { - // Minimum execution time: 236_324 nanoseconds. - Weight::from_ref_time(249_001_000) + // Minimum execution time: 238_430 nanoseconds. + Weight::from_ref_time(259_648_000) .saturating_add(RocksDbWeight::get().reads(25)) .saturating_add(RocksDbWeight::get().writes(29)) } @@ -359,8 +359,8 @@ impl WeightInfo for () { // Storage: Assets Account (r:1 w:1) // Storage: AssetManager AssetIdMetadata (r:0 w:2) fn remove_liquidity() -> Weight { - // Minimum execution time: 174_439 nanoseconds. - Weight::from_ref_time(185_116_000) + // Minimum execution time: 174_527 nanoseconds. + Weight::from_ref_time(176_416_000) .saturating_add(RocksDbWeight::get().reads(19)) .saturating_add(RocksDbWeight::get().writes(14)) } @@ -368,8 +368,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol ForeignLedger (r:6 w:6) // Storage: ZenlinkProtocol PairStatuses (r:2 w:0) fn swap_exact_assets_for_assets() -> Weight { - // Minimum execution time: 102_445 nanoseconds. - Weight::from_ref_time(103_807_000) + // Minimum execution time: 102_847 nanoseconds. + Weight::from_ref_time(103_961_000) .saturating_add(RocksDbWeight::get().reads(9)) .saturating_add(RocksDbWeight::get().writes(6)) } @@ -377,8 +377,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol ForeignLedger (r:6 w:6) // Storage: ZenlinkProtocol PairStatuses (r:2 w:0) fn swap_assets_for_exact_assets() -> Weight { - // Minimum execution time: 102_448 nanoseconds. - Weight::from_ref_time(103_698_000) + // Minimum execution time: 102_805 nanoseconds. + Weight::from_ref_time(104_156_000) .saturating_add(RocksDbWeight::get().reads(9)) .saturating_add(RocksDbWeight::get().writes(6)) } diff --git a/runtime/calamari/src/xcm_config.rs b/runtime/calamari/src/xcm_config.rs index 4fa30bcab..0944e9346 100644 --- a/runtime/calamari/src/xcm_config.rs +++ b/runtime/calamari/src/xcm_config.rs @@ -32,8 +32,8 @@ use manta_primitives::{ assets::AssetIdLocationConvert, types::{AccountId, Balance, CalamariAssetId}, xcm::{ - AccountIdToMultiLocation, FirstAssetTrader, IsNativeConcrete, MultiAssetAdapter, - MultiNativeAsset, + AccountIdToMultiLocation, AllowTopLevelPaidExecutionDescendOriginFirst, FirstAssetTrader, + IsNativeConcrete, MultiAssetAdapter, MultiNativeAsset, }, }; use orml_traits::location::AbsoluteReserveProvider; @@ -44,7 +44,7 @@ use sp_runtime::traits::Convert; use sp_std::prelude::*; use xcm::latest::prelude::*; use xcm_builder::{ - AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + Account32Hash, AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, ConvertedConcreteAssetId, EnsureXcmOrigin, FixedRateOfFungible, LocationInverter, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, @@ -93,6 +93,8 @@ pub type LocationToAccountId = ( SiblingParachainConvertsVia, // Straight up local `AccountId32` origins just alias directly to `AccountId`. AccountId32Aliases, + // Converts multilocation into a 32 byte hash for local `AccountId`s + Account32Hash, ); /// This is the type to convert an (incoming) XCM origin into a local `Origin` instance, @@ -164,6 +166,9 @@ match_types! { pub type Barrier = ( // Allows local origin messages which call weight_credit >= weight_limit. TakeWeightCredit, + // Allows execution of Transact XCM instruction from configurable set of origins + // as long as the message is in the format DescendOrigin + WithdrawAsset + BuyExecution + AllowTopLevelPaidExecutionDescendOriginFirst, // Allows non-local origin messages, for example from from the xcmp queue, // which have the ability to deposit assets and pay for their own execution. AllowTopLevelPaidExecutionFrom, diff --git a/runtime/integration-tests/src/xcm_mock/parachain.rs b/runtime/integration-tests/src/xcm_mock/parachain.rs index 7e85dea53..9a2de5350 100644 --- a/runtime/integration-tests/src/xcm_mock/parachain.rs +++ b/runtime/integration-tests/src/xcm_mock/parachain.rs @@ -44,7 +44,10 @@ use manta_primitives::{ }, constants::{ASSET_MANAGER_PALLET_ID, CALAMARI_DECIMAL, WEIGHT_PER_SECOND}, types::{BlockNumber, CalamariAssetId, Header}, - xcm::{FirstAssetTrader, IsNativeConcrete, MultiAssetAdapter, MultiNativeAsset}, + xcm::{ + AllowTopLevelPaidExecutionDescendOriginFirst, FirstAssetTrader, IsNativeConcrete, + MultiAssetAdapter, MultiNativeAsset, + }, }; use pallet_xcm::XcmPassthrough; use polkadot_core_primitives::BlockNumber as RelayBlockNumber; @@ -53,7 +56,7 @@ use polkadot_parachain::primitives::{ }; use xcm::{latest::prelude::*, Version as XcmVersion, VersionedMultiLocation, VersionedXcm}; use xcm_builder::{ - AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + Account32Hash, AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, ConvertedConcreteAssetId, EnsureXcmOrigin, FixedRateOfFungible, LocationInverter, ParentIsPreset, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, @@ -176,6 +179,8 @@ pub type LocationToAccountId = ( // Sibling parachain origins convert to AccountId via the `ParaId::into`. SiblingParachainConvertsVia, AccountId32Aliases, + // Converts multilocation into a 32 byte hash for local `AccountId`s + Account32Hash, ); /// This is the type to convert an (incoming) XCM origin into a local `Origin` instance, @@ -241,6 +246,9 @@ match_types! { pub type Barrier = ( // Allows local origin messages which call weight_credit >= weight_limit. TakeWeightCredit, + // Allows execution of Transact XCM instruction from configurable set of origins + // as long as the message is in the format DescendOrigin + WithdrawAsset + BuyExecution + AllowTopLevelPaidExecutionDescendOriginFirst, // Allows non-local origin messages, for example from from the xcmp queue, // which have the ability to deposit assets and pay for their own execution. AllowTopLevelPaidExecutionFrom, diff --git a/runtime/integration-tests/src/xcm_mock/xcm_tests.rs b/runtime/integration-tests/src/xcm_mock/xcm_tests.rs index b49019f26..9af813eac 100644 --- a/runtime/integration-tests/src/xcm_mock/xcm_tests.rs +++ b/runtime/integration-tests/src/xcm_mock/xcm_tests.rs @@ -38,8 +38,9 @@ use xcm_simulator::TestExt; use super::{ parachain, parachain::{ - create_asset_location, create_asset_metadata, register_assets_on_parachain, AssetManager, - ParaTokenPerSecond, XcmExecutorConfig as ParaXcmExecutorConfig, PALLET_ASSET_INDEX, + create_asset_location, create_asset_metadata, register_assets_on_parachain, AccountId, + AssetManager, ParaTokenPerSecond, RelayNetwork, XcmExecutorConfig as ParaXcmExecutorConfig, + PALLET_ASSET_INDEX, }, relay_chain, MockNet, ParaA, ParaB, ParaC, Relay, *, }; @@ -133,6 +134,141 @@ fn dmp_transact_from_parent_should_pass_barrier() { }); } +#[test] +fn xcmp_transact_from_sibling_tests() { + MockNet::reset(); + + let para_a_source_location = create_asset_location(1, PARA_A_ID); + let para_b_source_location = create_asset_location(1, PARA_B_ID); + + let amount = INITIAL_BALANCE - 1000; + + let para_a_asset_metadata = create_asset_metadata("ParaAToken", "ParaA", 18, 1, false, false); + let para_b_asset_metadata = create_asset_metadata("ParaBToken", "ParaB", 18, 1, false, false); + + let _ = register_assets_on_parachain::( + ¶_a_source_location, + ¶_a_asset_metadata, + Some(0u128), + None, + ); + let b_asset_id_on_a = register_assets_on_parachain::( + ¶_b_source_location, + ¶_b_asset_metadata, + Some(0u128), + None, + ); + + let _ = register_assets_on_parachain::( + ¶_b_source_location, + ¶_b_asset_metadata, + Some(0u128), + None, + ); + let _ = register_assets_on_parachain::( + ¶_a_source_location, + ¶_a_asset_metadata, + Some(0u128), + None, + ); + + let remark = parachain::RuntimeCall::System( + frame_system::Call::::remark_with_event { + remark: vec![1, 2, 3], + }, + ); + let dummy_asset = MultiAsset { + id: Concrete(MultiLocation { + parents: 1, + interior: X1(Parachain(PARA_B_ID)), + }), + fun: Fungible(1000000000), + }; + let dummy_assets = MultiAssets::from(vec![dummy_asset.clone()]); + let origin_location_interior = X1(AccountId32 { + network: Any, + id: ALICE.into(), + }); + let alice_derived_account_on_b = + xcm_builder::Account32Hash::::convert_ref(MultiLocation { + parents: 1, + interior: X2( + Parachain(PARA_A_ID), + AccountId32 { + network: Any, + id: ALICE.into(), + }, + ), + }) + .unwrap(); + + ParaB::execute_with(|| { + assert_ok!(pallet_balances::Pallet::::set_balance( + parachain::RuntimeOrigin::root(), + alice_derived_account_on_b.clone(), + amount, + 0 + )); + }); + + ParaA::execute_with(|| { + assert_ok!(parachain::Assets::mint_into( + b_asset_id_on_a, + &ALICE, + amount + )); + assert_ok!(ParachainPalletXcm::send_xcm( + Here, + (Parent, Parachain(PARA_B_ID)), + Xcm(vec![ + DescendOrigin(origin_location_interior), + WithdrawAsset(dummy_assets.clone()), + BuyExecution { + fees: dummy_asset.clone(), + weight_limit: Unlimited, + }, + Transact { + origin_type: OriginKind::SovereignAccount, + require_weight_at_most: INITIAL_BALANCE as u64, + call: remark.encode().into(), + } + ]), + )); + }); + + ParaB::execute_with(|| { + use parachain::{RuntimeEvent, System}; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::System(frame_system::Event::Remarked { .. }) + ))); + }); + + ParaA::execute_with(|| { + assert_ok!(ParachainPalletXcm::send_xcm( + Here, + (Parent, Parachain(PARA_B_ID)), + Xcm(vec![Transact { + origin_type: OriginKind::SovereignAccount, + require_weight_at_most: INITIAL_BALANCE as u64, + call: remark.encode().into(), + }]), + )); + }); + + ParaB::execute_with(|| { + use parachain::{RuntimeEvent, System}; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Fail { + message_hash: _, + error: XcmError::Barrier, + weight: _ + }) + ))); + }); +} + #[test] fn ump() { MockNet::reset(); diff --git a/runtime/manta/src/weights/zenlink_protocol.rs b/runtime/manta/src/weights/zenlink_protocol.rs index 30918ad7b..e713bb401 100644 --- a/runtime/manta/src/weights/zenlink_protocol.rs +++ b/runtime/manta/src/weights/zenlink_protocol.rs @@ -17,7 +17,7 @@ //! Autogenerated weights for zenlink_protocol //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-07-07, STEPS: `50`, REPEAT: 40, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-07-11, STEPS: `50`, REPEAT: 40, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("/home/runner/runners/2.280.1/_work/Manta/Manta/tests/data/fork.json"), DB CACHE: 1024 // Executed Command: @@ -66,15 +66,15 @@ pub struct SubstrateWeight(PhantomData); impl zenlink_protocol::WeightInfo for SubstrateWeight { // Storage: ZenlinkProtocol FeeMeta (r:1 w:1) fn set_fee_receiver() -> Weight { - // Minimum execution time: 8_067 nanoseconds. - Weight::from_ref_time(8_216_000) + // Minimum execution time: 7_810 nanoseconds. + Weight::from_ref_time(8_142_000) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } // Storage: ZenlinkProtocol FeeMeta (r:1 w:1) fn set_fee_point() -> Weight { - // Minimum execution time: 7_393 nanoseconds. - Weight::from_ref_time(7_819_000) + // Minimum execution time: 7_400 nanoseconds. + Weight::from_ref_time(7_604_000) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -83,8 +83,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 31_381 nanoseconds. - Weight::from_ref_time(31_892_000) + // Minimum execution time: 28_848 nanoseconds. + Weight::from_ref_time(33_175_000) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -92,8 +92,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 25_296 nanoseconds. - Weight::from_ref_time(25_877_000) + // Minimum execution time: 24_782 nanoseconds. + Weight::from_ref_time(25_446_000) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(3)) } @@ -103,8 +103,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 63_772 nanoseconds. - Weight::from_ref_time(65_004_000) + // Minimum execution time: 63_689 nanoseconds. + Weight::from_ref_time(67_938_000) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -123,8 +123,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 253_641 nanoseconds. - Weight::from_ref_time(267_990_000) + // Minimum execution time: 248_654 nanoseconds. + Weight::from_ref_time(250_716_000) .saturating_add(T::DbWeight::get().reads(24)) .saturating_add(T::DbWeight::get().writes(20)) } @@ -142,8 +142,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 231_245 nanoseconds. - Weight::from_ref_time(234_383_000) + // Minimum execution time: 226_155 nanoseconds. + Weight::from_ref_time(240_070_000) .saturating_add(T::DbWeight::get().reads(23)) .saturating_add(T::DbWeight::get().writes(32)) } @@ -151,8 +151,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 32_028 nanoseconds. - Weight::from_ref_time(32_396_000) + // Minimum execution time: 30_750 nanoseconds. + Weight::from_ref_time(31_564_000) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(3)) } @@ -161,8 +161,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 64_260 nanoseconds. - Weight::from_ref_time(68_350_000) + // Minimum execution time: 63_599 nanoseconds. + Weight::from_ref_time(64_611_000) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -180,8 +180,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 238_646 nanoseconds. - Weight::from_ref_time(242_711_000) + // Minimum execution time: 234_124 nanoseconds. + Weight::from_ref_time(248_597_000) .saturating_add(T::DbWeight::get().reads(25)) .saturating_add(T::DbWeight::get().writes(29)) } @@ -198,8 +198,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 175_693 nanoseconds. - Weight::from_ref_time(177_926_000) + // Minimum execution time: 173_355 nanoseconds. + Weight::from_ref_time(175_329_000) .saturating_add(T::DbWeight::get().reads(19)) .saturating_add(T::DbWeight::get().writes(14)) } @@ -207,8 +207,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 101_661 nanoseconds. - Weight::from_ref_time(103_658_000) + // Minimum execution time: 101_116 nanoseconds. + Weight::from_ref_time(102_363_000) .saturating_add(T::DbWeight::get().reads(9)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -216,8 +216,8 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 102_476 nanoseconds. - Weight::from_ref_time(107_960_000) + // Minimum execution time: 101_719 nanoseconds. + Weight::from_ref_time(107_717_000) .saturating_add(T::DbWeight::get().reads(9)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -227,15 +227,15 @@ impl zenlink_protocol::WeightInfo for SubstrateWeight Weight { - // Minimum execution time: 8_067 nanoseconds. - Weight::from_ref_time(8_216_000) + // Minimum execution time: 7_810 nanoseconds. + Weight::from_ref_time(8_142_000) .saturating_add(RocksDbWeight::get().reads(1)) .saturating_add(RocksDbWeight::get().writes(1)) } // Storage: ZenlinkProtocol FeeMeta (r:1 w:1) fn set_fee_point() -> Weight { - // Minimum execution time: 7_393 nanoseconds. - Weight::from_ref_time(7_819_000) + // Minimum execution time: 7_400 nanoseconds. + Weight::from_ref_time(7_604_000) .saturating_add(RocksDbWeight::get().reads(1)) .saturating_add(RocksDbWeight::get().writes(1)) } @@ -244,8 +244,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol PairStatuses (r:1 w:1) // Storage: ZenlinkProtocol LiquidityPairs (r:0 w:1) fn create_pair() -> Weight { - // Minimum execution time: 31_381 nanoseconds. - Weight::from_ref_time(31_892_000) + // Minimum execution time: 28_848 nanoseconds. + Weight::from_ref_time(33_175_000) .saturating_add(RocksDbWeight::get().reads(3)) .saturating_add(RocksDbWeight::get().writes(2)) } @@ -253,8 +253,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol BootstrapLimits (r:0 w:1) // Storage: ZenlinkProtocol BootstrapRewards (r:0 w:1) fn bootstrap_create() -> Weight { - // Minimum execution time: 25_296 nanoseconds. - Weight::from_ref_time(25_877_000) + // Minimum execution time: 24_782 nanoseconds. + Weight::from_ref_time(25_446_000) .saturating_add(RocksDbWeight::get().reads(1)) .saturating_add(RocksDbWeight::get().writes(3)) } @@ -264,8 +264,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol PairStatuses (r:1 w:1) // Storage: ZenlinkProtocol BootstrapPersonalSupply (r:1 w:1) fn bootstrap_contribute() -> Weight { - // Minimum execution time: 63_772 nanoseconds. - Weight::from_ref_time(65_004_000) + // Minimum execution time: 63_689 nanoseconds. + Weight::from_ref_time(67_938_000) .saturating_add(RocksDbWeight::get().reads(8)) .saturating_add(RocksDbWeight::get().writes(6)) } @@ -284,8 +284,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol ForeignLedger (r:2 w:2) // Storage: AssetManager AssetIdMetadata (r:0 w:4) fn bootstrap_claim() -> Weight { - // Minimum execution time: 253_641 nanoseconds. - Weight::from_ref_time(267_990_000) + // Minimum execution time: 248_654 nanoseconds. + Weight::from_ref_time(250_716_000) .saturating_add(RocksDbWeight::get().reads(24)) .saturating_add(RocksDbWeight::get().writes(20)) } @@ -303,8 +303,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol LiquidityPairs (r:0 w:1) // Storage: ZenlinkProtocol BootstrapEndStatus (r:0 w:1) fn bootstrap_end() -> Weight { - // Minimum execution time: 231_245 nanoseconds. - Weight::from_ref_time(234_383_000) + // Minimum execution time: 226_155 nanoseconds. + Weight::from_ref_time(240_070_000) .saturating_add(RocksDbWeight::get().reads(23)) .saturating_add(RocksDbWeight::get().writes(32)) } @@ -312,8 +312,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol BootstrapRewards (r:1 w:1) // Storage: ZenlinkProtocol BootstrapLimits (r:0 w:1) fn bootstrap_update() -> Weight { - // Minimum execution time: 32_028 nanoseconds. - Weight::from_ref_time(32_396_000) + // Minimum execution time: 30_750 nanoseconds. + Weight::from_ref_time(31_564_000) .saturating_add(RocksDbWeight::get().reads(2)) .saturating_add(RocksDbWeight::get().writes(3)) } @@ -322,8 +322,8 @@ impl WeightInfo for () { // Storage: ParachainInfo ParachainId (r:1 w:0) // Storage: ZenlinkProtocol ForeignLedger (r:4 w:4) fn bootstrap_refund() -> Weight { - // Minimum execution time: 64_260 nanoseconds. - Weight::from_ref_time(68_350_000) + // Minimum execution time: 63_599 nanoseconds. + Weight::from_ref_time(64_611_000) .saturating_add(RocksDbWeight::get().reads(7)) .saturating_add(RocksDbWeight::get().writes(6)) } @@ -341,8 +341,8 @@ impl WeightInfo for () { // Storage: AssetManager AssetIdMetadata (r:0 w:5) // Storage: AssetManager AssetIdLocation (r:0 w:3) fn add_liquidity() -> Weight { - // Minimum execution time: 238_646 nanoseconds. - Weight::from_ref_time(242_711_000) + // Minimum execution time: 234_124 nanoseconds. + Weight::from_ref_time(248_597_000) .saturating_add(RocksDbWeight::get().reads(25)) .saturating_add(RocksDbWeight::get().writes(29)) } @@ -359,8 +359,8 @@ impl WeightInfo for () { // Storage: Assets Account (r:1 w:1) // Storage: AssetManager AssetIdMetadata (r:0 w:2) fn remove_liquidity() -> Weight { - // Minimum execution time: 175_693 nanoseconds. - Weight::from_ref_time(177_926_000) + // Minimum execution time: 173_355 nanoseconds. + Weight::from_ref_time(175_329_000) .saturating_add(RocksDbWeight::get().reads(19)) .saturating_add(RocksDbWeight::get().writes(14)) } @@ -368,8 +368,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol ForeignLedger (r:6 w:6) // Storage: ZenlinkProtocol PairStatuses (r:2 w:0) fn swap_exact_assets_for_assets() -> Weight { - // Minimum execution time: 101_661 nanoseconds. - Weight::from_ref_time(103_658_000) + // Minimum execution time: 101_116 nanoseconds. + Weight::from_ref_time(102_363_000) .saturating_add(RocksDbWeight::get().reads(9)) .saturating_add(RocksDbWeight::get().writes(6)) } @@ -377,8 +377,8 @@ impl WeightInfo for () { // Storage: ZenlinkProtocol ForeignLedger (r:6 w:6) // Storage: ZenlinkProtocol PairStatuses (r:2 w:0) fn swap_assets_for_exact_assets() -> Weight { - // Minimum execution time: 102_476 nanoseconds. - Weight::from_ref_time(107_960_000) + // Minimum execution time: 101_719 nanoseconds. + Weight::from_ref_time(107_717_000) .saturating_add(RocksDbWeight::get().reads(9)) .saturating_add(RocksDbWeight::get().writes(6)) } diff --git a/runtime/manta/src/xcm_config.rs b/runtime/manta/src/xcm_config.rs index a9efd3f40..d03b2cc08 100644 --- a/runtime/manta/src/xcm_config.rs +++ b/runtime/manta/src/xcm_config.rs @@ -53,6 +53,8 @@ use xcm_builder::{ }; use xcm_executor::{traits::JustTry, Config, XcmExecutor}; +use manta_primitives::xcm::AllowTopLevelPaidExecutionDescendOriginFirst; + parameter_types! { pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); @@ -87,9 +89,11 @@ pub type LocationToAccountId = ( SiblingParachainConvertsVia, // Straight up local `AccountId32` origins just alias directly to `AccountId`. AccountId32Aliases, + // Converts multilocation into a 32 byte hash for local `AccountId`s + xcm_builder::Account32Hash, ); -/// This is the type to convert an (incoming) XCM origin into a local `RuntimeOrigin` instance, +/// This is the type to convert an (incoming) XCM origin into a local `Origin` instance, /// ready for dispatching a transaction with Xcm's `Transact`. /// It uses some Rust magic macro to do the pattern matching sequentially. /// There is an `OriginKind` which can biases the kind of local `RuntimeOrigin` it will become. @@ -153,6 +157,9 @@ match_types! { pub type Barrier = ( // Allows local origin messages which call weight_credit >= weight_limit. TakeWeightCredit, + // Allows execution of Transact XCM instruction from configurable set of origins + // as long as the message is in the format DescendOrigin + WithdrawAsset + BuyExecution + AllowTopLevelPaidExecutionDescendOriginFirst, // Allows non-local origin messages, for example from from the xcmp queue, // which have the ability to deposit assets and pay for their own execution. AllowTopLevelPaidExecutionFrom,