Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add statemine #24

Merged
merged 169 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
169 commits
Select commit Hold shift + click to select a range
aa67a43
rustc grumbles
joepetrowski Nov 17, 2022
9ab1739
add second instance
joepetrowski Nov 17, 2022
df40d77
leave some todos
joepetrowski Nov 17, 2022
94717a4
fix AssetsToBlockAuthor
joepetrowski Nov 17, 2022
47d96e0
make it almost compile
joepetrowski Nov 18, 2022
1e0515e
make it actually compile
joepetrowski Nov 18, 2022
6de6313
fix logical error
joepetrowski Nov 18, 2022
35d1e57
cargo fmt to resolve duplicate imports on merge
joepetrowski Nov 18, 2022
362a907
fix deps to make compile
joepetrowski Nov 18, 2022
b8ed7e7
fmt
joepetrowski Nov 18, 2022
633366b
(pallet-assets/pallet-asset-tx-payment) pathched with `sv-locked-for-…
bkontur Nov 21, 2022
5f7f8c2
statemine progress
joepetrowski Nov 22, 2022
e8afde4
ForeignCreators :tada:
joepetrowski Nov 22, 2022
e569b68
fix AssetFeeAsExistentialDepositMultiplier
joepetrowski Nov 30, 2022
c487586
no default instance
joepetrowski Nov 30, 2022
4191a4d
instantiate statemint
joepetrowski Dec 1, 2022
d9d5a9d
compile tests
bkontur Dec 22, 2022
4a9dec9
Init of pallet with `transfer_asset_via_bridge` call
bkontur Nov 11, 2022
39ba564
Init of pallet with `transfer_asset_via_bridge` call
bkontur Dec 14, 2022
c675531
Box wrap inputs
bkontur Dec 19, 2022
e127426
Added withdraw/deposit to bridge's reserve account
bkontur Dec 19, 2022
a7dd1fc
TODO: temporary hack pipelines because of https://github.com/parityte…
bkontur Dec 21, 2022
2ff5c4f
Allow receive bridged Xcm::Trap on Westmint
bkontur Jan 4, 2023
18ad58b
Allow (temporary) Statemine send xcm messages
bkontur Jan 4, 2023
fe7817e
refactor TrustedBridgedNetworks
bkontur Jan 4, 2023
a80781e
Allow (hacky) xcm::transact for remark/remark_with_event
bkontur Jan 4, 2023
0985898
Unit-test for Statemine - send_xcm_transact_with_remark_with_event_works
bkontur Jan 5, 2023
c3195d2
Fix for BridgedSignedAccountId32AsNative
bkontur Jan 5, 2023
3353263
don't rename pallet in runtime
joepetrowski Jan 11, 2023
9e211b8
don't rename and fix tests
joepetrowski Jan 11, 2023
31bc1c6
Added `allowed_target_location` + reanchored assets/destination + tests
bkontur Jan 12, 2023
25c2fc5
fix benchmark helper
joepetrowski Jan 12, 2023
a4a581b
fix benchmark build
joepetrowski Jan 12, 2023
7fbfeb3
Merge remote-tracking branch 'origin/joe-bridge-hub-westmint-assets' …
bkontur Jan 12, 2023
9cd2708
more benchmark fixes
joepetrowski Jan 12, 2023
23f9e4d
Merge remote-tracking branch 'origin/joe-bridge-hub-westmint-assets' …
bkontur Jan 12, 2023
81e9703
fix penpal and rococo
joepetrowski Jan 12, 2023
4365baa
Merge branch 'bridge-hub-base' into joe-bridge-hub-westmint-assets
bkontur Jan 15, 2023
f2c3569
Merge remote-tracking branch 'origin/joe-bridge-hub-westmint-assets' …
bkontur Jan 15, 2023
0c3f3b7
update BenchmarkHelper interface
joepetrowski Jan 17, 2023
c3d2108
fmt
joepetrowski Jan 17, 2023
0d75123
Merge remote-tracking branch 'origin/master' into joe-bridge-hub-west…
bkontur Jan 21, 2023
1d6fff4
Merge branch 'joe-bridge-hub-westmint-assets' into bko-transfer-asset…
bkontur Jan 21, 2023
8d809e4
Added weight `export_message` to statemint because of `pallet_xcm.send`
bkontur Jan 22, 2023
81abe45
add foreign assets to westmint
joepetrowski Jan 24, 2023
0da76e0
add foreign assets to statemine
joepetrowski Jan 24, 2023
57a2f00
Merge remote-tracking branch 'origin/master' into bko-transfer-asset-…
bkontur Jan 25, 2023
1ae22a7
Merge remote-tracking branch 'origin/master' into bko-transfer-asset-…
bkontur Jan 30, 2023
af4fe56
Governance can call `xcm:Transact` with bridges configuration management
bkontur Jan 30, 2023
063fef0
Merge remote-tracking branch 'origin/master' into joe-foreign-assets
Jan 30, 2023
bf2e4d3
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-tra…
bkontur Jan 30, 2023
78175ba
Revert temporary disabled `scripts/ci/gitlab/pipeline/test.yml`
bkontur Jan 30, 2023
761a500
Unit-test for handling `ReserveAssetDeposited` on Westmint for Foreig…
bkontur Feb 1, 2023
bc4664b
Merge remote-tracking branch 'origin/master' into joe-foreign-assets
Feb 9, 2023
b534445
Merge remote-tracking branch 'origin/master' into joe-foreign-assets
Feb 10, 2023
0590241
use updated api for ensure origin trait
muharem Feb 13, 2023
a1ce9b8
Merge remote-tracking branch 'origin/master' into joe-foreign-assets
Feb 23, 2023
0f80e76
Merge remote-tracking branch 'origin/master' into joe-foreign-assets
Feb 28, 2023
ae8cac6
Merge remote-tracking branch 'origin/master' into joe-foreign-assets
bkontur Mar 3, 2023
1b21403
Merge remote-tracking branch 'origin/master' into joe-foreign-assets
Mar 3, 2023
5cb396f
Merge remote-tracking branch 'origin/master' into joe-foreign-assets
Mar 8, 2023
56abaf5
Merge remote-tracking branch 'origin/master' into joe-foreign-assets
Mar 10, 2023
d5b71a7
Benchmarks for pallet-bridge-assets-transfer (#2316)
svyatonik Mar 15, 2023
4f70058
Merge remote-tracking branch 'origin/master' into joe-foreign-assets
Mar 15, 2023
60a6089
Assets/ForeignAssets tests and fixes (#2167)
bkontur Mar 16, 2023
018b800
Added `StartsWithExplicitGlobalConsensus` to ignores (#2338)
bkontur Mar 16, 2023
08bfe99
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-tra…
bkontur Mar 16, 2023
48b6877
Change to correct weight file for pallet_bridge_assets_transfer
bkontur Mar 17, 2023
c16f96d
Renamed `pallet-bridge-assets-transfer` to `pallet-bridge-transfer`
bkontur Mar 17, 2023
32a09c7
from_ref_time to from_parts
bkontur Mar 17, 2023
137ee81
".git/.scripts/commands/bench/bench.sh" pallet statemine assets palle…
Mar 17, 2023
36751ae
Added `ping_via_bridge`
bkontur Mar 19, 2023
b550a8e
".git/.scripts/commands/bench/bench.sh" pallet statemine assets palle…
Mar 19, 2023
47e0283
Merge remote-tracking branch 'origin/master' into joe-foreign-assets
Mar 20, 2023
a4e2b93
Fix test
bkontur Mar 20, 2023
ad13281
Merge remote-tracking branch 'origin/joe-foreign-assets' into bko-tra…
Mar 20, 2023
eff26cd
Revert not needed stuff
bkontur Mar 20, 2023
65fe38b
Added test-case `can_governance_change_bridge_transfer_configuration`
bkontur Mar 20, 2023
bc5a3ed
Added test `initiate_transfer_asset_via_bridge_for_native_asset_works`
bkontur Mar 21, 2023
ec44e0d
Merge remote-tracking branch 'origin/master' into bko-transfer-asset-…
bkontur Mar 23, 2023
abe9ad2
Fix compilation
bkontur Mar 24, 2023
98c09fa
Small fixes
bkontur Mar 24, 2023
d712d42
Added support for paid or unpaid execution by configuration
bkontur Mar 24, 2023
8dfe3b6
Merge remote-tracking branch 'origin/master' into bko-transfer-asset-…
bkontur Mar 24, 2023
a757c38
Merge remote-tracking branch 'origin/master' into bko-transfer-asset-…
Mar 27, 2023
a3eb549
Removed stuff
bkontur Mar 27, 2023
7d4319d
Bump futures from 0.3.26 to 0.3.27 (#2359)
dependabot[bot] Mar 27, 2023
ea6598c
Bump clap from 4.1.11 to 4.1.13 (#2388)
dependabot[bot] Mar 27, 2023
35d79f3
Remove HeaderBackend from RelayChainRPCClient (#2385)
skunert Mar 28, 2023
e0a27e6
Added `receive_reserve_asset_deposited_from_different_consensus_works`
bkontur Mar 27, 2023
0ef1444
Bump scale-info from 2.3.1 to 2.4.0 (#2386)
dependabot[bot] Mar 28, 2023
72d4010
Renamed Bridges -> AllowedExporters
bkontur Mar 28, 2023
066db6b
Bump serde_json from 1.0.94 to 1.0.95 (#2387)
dependabot[bot] Mar 28, 2023
1d8208b
Companion: wasm-builder support stable Rust (#2393)
bkchr Mar 29, 2023
99fca26
Added `IsReserve` handling for `ReserveAssetDeposited` + benchmarks
bkontur Mar 29, 2023
559f3ca
Bump thiserror from 1.0.38 to 1.0.40 (#2396)
dependabot[bot] Mar 29, 2023
bfaa974
Fix compile
bkontur Mar 29, 2023
1c459ed
Merge branch 'master' of https://github.com/paritytech/cumulus into HEAD
Mar 29, 2023
3bf39cf
".git/.scripts/commands/bench/bench.sh" pallet statemine assets palle…
Mar 29, 2023
69dd6ae
Bump syn from 1.0.109 to 2.0.9 (#2397)
dependabot[bot] Mar 29, 2023
247e843
Bump serde from 1.0.156 to 1.0.159 (#2395)
dependabot[bot] Mar 29, 2023
2ce882f
Companion for https://github.com/paritytech/substrate/pull/13725 (#2401)
altonen Mar 30, 2023
3ce4e83
Bump syn from 2.0.9 to 2.0.11 (#2405)
dependabot[bot] Mar 30, 2023
693e973
Bump scale-info from 2.4.0 to 2.5.0 (#2404)
dependabot[bot] Mar 30, 2023
f5340e7
Bump tempfile from 3.4.0 to 3.5.0 (#2406)
dependabot[bot] Mar 30, 2023
337bd17
bump zombienet version (#2411)
pepoviola Mar 30, 2023
f76ba2b
Fix conditional benchmarking
bkontur Mar 30, 2023
8bcceb6
Merge branch 'master' of https://github.com/paritytech/cumulus into HEAD
Mar 30, 2023
45ca89b
".git/.scripts/commands/bench/bench.sh" pallet statemine assets palle…
Mar 30, 2023
727b348
".git/.scripts/commands/bench/bench.sh" pallet westmint assets pallet…
Mar 30, 2023
826e1aa
Bump tokio from 1.26.0 to 1.27.0 (#2413)
dependabot[bot] Mar 31, 2023
a92aeb3
Change test weights
bkontur Mar 31, 2023
93d9b6a
Bump syn from 2.0.11 to 2.0.12 (#2414)
dependabot[bot] Mar 31, 2023
b1cd3d5
Bump proc-macro2 from 1.0.52 to 1.0.54 (#2415)
dependabot[bot] Mar 31, 2023
9106fa8
Companion PR for contract deletion updates (#2409)
pgherveou Mar 31, 2023
b82d6b1
Fix SafeCallFilter for westmint
bkontur Mar 31, 2023
e5035c8
Allow arbitrary key-values in RelayStateSproofBuilder (#2407)
tmpolaczyk Mar 31, 2023
e5d994b
help text examples + clean up (#2418)
skunert Apr 1, 2023
e67094e
Bump futures from 0.3.27 to 0.3.28 (#2420)
dependabot[bot] Apr 1, 2023
6bdcf1f
Bump clap from 4.1.13 to 4.1.14 (#2421)
dependabot[bot] Apr 1, 2023
66bfb2c
Update Substrate & Polkadot (#2422)
bkchr Apr 3, 2023
d12c6d0
Bump syn from 2.0.12 to 2.0.13 (#2428)
dependabot[bot] Apr 3, 2023
697f0cd
Bump hex-literal from 0.3.4 to 0.4.0 (#2426)
dependabot[bot] Apr 3, 2023
53c6b8d
Companion for #6986 (#2416)
bkontur Apr 4, 2023
7fd80c7
Merge remote-tracking branch 'origin/master' into bko-transfer-asset-…
bkontur Apr 4, 2023
5ed3677
[backport] weights 9400 (#2425)
EgorPopelyaev Apr 4, 2023
e25e1ef
Use send_xcm and add cost to event
bkontur Apr 4, 2023
88ead41
Cleanup: Remove polkadot-service dependency from minimal node (#2430)
skunert Apr 4, 2023
2cbaa39
Co #13699: Remove old calls (#2431)
ggwpez Apr 4, 2023
b49628f
[Backport] version bumps 9400 (#2424)
EgorPopelyaev Apr 5, 2023
77ad776
Refactor to support multiple MultiAsset + cleaning
bkontur Apr 5, 2023
b3edf24
Merge remote-tracking branch 'origin/master' into bko-transfer-asset-…
Apr 5, 2023
e6bd54a
".git/.scripts/commands/bench/bench.sh" xcm westmint assets pallet_xc…
Apr 5, 2023
98f6ca7
Bump hex-literal from 0.4.0 to 0.4.1 (#2434)
dependabot[bot] Apr 5, 2023
a5a79db
Updated bridge-hub-polkadot.json (#2435)
bkontur Apr 6, 2023
b0715f9
The Polkadot Fellowship import (#2236)
muharem Apr 9, 2023
03763dd
Companion for #13302 (#2357)
lexnv Apr 11, 2023
b4a50e2
use stable rust toolchain in ci
Apr 11, 2023
4733416
Bump syn from 2.0.13 to 2.0.14 (#2446)
dependabot[bot] Apr 12, 2023
5a0ebad
Bump serde from 1.0.159 to 1.0.160 (#2445)
dependabot[bot] Apr 12, 2023
030db02
Invoke cargo build commands with `--locked` (#2444)
Apr 12, 2023
df9ed24
Bump actions/checkout from 3.1.0 to 3.5.1 (#2448)
dependabot[bot] Apr 12, 2023
71d427f
Updated doc
bkontur Apr 13, 2023
73bdbdc
Merge remote-tracking branch 'origin/master' into bko-transfer-asset-…
Apr 13, 2023
574f425
Bump serde_json from 1.0.95 to 1.0.96 (#2453)
dependabot[bot] Apr 13, 2023
b42855d
Bump actions/checkout from 3.5.1 to 3.5.2 (#2452)
dependabot[bot] Apr 14, 2023
a26ebb2
Bump syn from 2.0.14 to 2.0.15 (#2454)
dependabot[bot] Apr 14, 2023
863e94d
Bump assert_cmd from 2.0.10 to 2.0.11 (#2457)
dependabot[bot] Apr 15, 2023
72349fc
Changed `query_account_balances` return type (#2455)
bkontur Apr 17, 2023
926799c
Companion for substrate#13883 (#2460)
andresilva Apr 18, 2023
3de5354
Optimize level monitor reconstruction (#2461)
davxy Apr 19, 2023
4449044
Bump clap from 4.1.14 to 4.2.3 (#2465)
dependabot[bot] Apr 19, 2023
ea44f8c
Bump Swatinem/rust-cache from 2.2.0 to 2.2.1 (#2456)
dependabot[bot] Apr 19, 2023
d403b49
Companion for substrate#13771 (#2410)
muharem Apr 19, 2023
eced0cb
Parachain node should not recover blocks while syncing (#2462)
skunert Apr 19, 2023
56644eb
Address review comments
serban300 Apr 20, 2023
8615ac8
[Polkadot Companion] for 7101 (#2470)
mrcnski Apr 21, 2023
5170168
Merge remote-tracking branch 'origin/master' into bko-transfer-asset-…
Apr 24, 2023
2c1dd4f
Align BridgeHub runtimes with other SP runtimes + reused test for tel…
bkontur Apr 24, 2023
5c479b7
Extract runtime_para_id for test
bkontur Apr 19, 2023
ad2fa5c
Typos
bkontur Apr 19, 2023
7bba7f0
Added helper for `execute_as_governance`
bkontur Apr 20, 2023
e58b442
Merge remote-tracking branch 'origin/master' into bko-transfer-asset-…
bkontur Apr 24, 2023
2e33b87
Fix test because `UnpaidRemoteExporter` adds now `UnpaidExecution` in…
bkontur Apr 24, 2023
43ee627
Use `execute_as_governance` function
bkontur Apr 24, 2023
2637a64
merge from bko-transfer-asset-via-bridge
alistair-singh May 11, 2023
d3bccec
typos
alistair-singh May 10, 2023
5632fa3
modified lock
alistair-singh May 11, 2023
94c880c
revert to parity/master
alistair-singh May 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ members = [
"primitives/utility",
"polkadot-parachain",
"parachains/common",
"parachains/pallets/bridge-transfer",
"parachains/pallets/parachain-info",
"parachains/pallets/ping",
"parachains/runtimes/testing/rococo-parachain",
Expand Down
58 changes: 58 additions & 0 deletions parachains/pallets/bridge-transfer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[package]
name = "pallet-bridge-transfer"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
license = "Apache-2.0"
homepage = "https://docs.substrate.io/"
repository = "https://github.com/paritytech/cumulus/"
description = "Pallet for message transfer through bridges"
readme = "README.md"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.3.0", default-features = false, features = ["derive"] }
log = { version = "0.4.14", default-features = false }

# Substrate
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", optional = true, default-features = false, branch = "master" }
frame-system-benchmarking = { git = "https://github.com/paritytech/substrate", optional = true, default-features = false, branch = "master" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }

# Polkadot
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }

[dev-dependencies]
sp-version = { git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "master" }
cumulus-pallet-xcmp-queue = { path = "../../../pallets/xcmp-queue" }

[features]
default = ["std"]
std = [
"codec/std",
"log/std",
"scale-info/std",
"sp-std/std",
"sp-runtime/std",
"frame-support/std",
"frame-system/std",
"xcm/std",
"xcm-builder/std",
"xcm-executor/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
199 changes: 199 additions & 0 deletions parachains/pallets/bridge-transfer/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// This file is part of Substrate.

// Copyright (C) 2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! `BridgeTransfer` pallet benchmarks.

use crate::{
AllowedExporters, AllowedReserveLocations, AllowedUniversalAliases, BenchmarkHelper, Call,
Config, Event, Pallet, PingMessageBuilder,
};

use frame_benchmarking::{benchmarks, BenchmarkError};
use frame_support::{
ensure,
traits::{EnsureOrigin, Get},
};
use sp_std::prelude::*;
use xcm::prelude::*;

#[cfg(feature = "runtime-benchmarks")]
impl<T: Config> Pallet<T> {
#[cfg(feature = "runtime-benchmarks")]
pub fn insert_universal_alias_for_benchmarks((location, junction): (MultiLocation, Junction)) {
assert!(matches!(
AllowedUniversalAliases::<T>::try_mutate(location, |junctions| junctions
.try_insert(junction)),
Ok(true)
));
}
}

benchmarks! {
transfer_asset_via_bridge {
let _ = T::TransferAssetOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
// every asset has its own configuration and ledger, so there's a performance dependency
// (be sure to use "worst" of assets)
let max_assets_limit = T::MaxAssetsLimit::get();
ensure!(max_assets_limit > 0, "MaxAssetsLimit not set up correctly.");
let (bridged_network, bridge_config) = T::BenchmarkHelper::bridge_config()
.ok_or(BenchmarkError::Stop("missing `bridge_config` data"))?;
let (origin, assets, destination) = T::BenchmarkHelper::prepare_asset_transfer()
.ok_or(BenchmarkError::Stop("missing `prepare_asset_transfer` data"))?;
let assets_count = match &assets {
VersionedMultiAssets::V2(assets) => assets.len(),
VersionedMultiAssets::V3(assets) => assets.len(),
};
ensure!(assets_count == max_assets_limit as usize, "`assets` not set up correctly for worst case.");
AllowedExporters::<T>::insert(bridged_network, bridge_config);
}: _<T::RuntimeOrigin>(origin, Box::new(assets), Box::new(destination))
verify {
// we don't care about message hash or sender cost here, just check that the transfer has been initiated
let actual_event = frame_system::Pallet::<T>::events().pop().map(|r| r.event);
let expected_event: <T as Config>::RuntimeEvent = Event::TransferInitiated {
message_hash: Default::default(),
sender_cost: Default::default(),
}.into();
assert!(matches!(actual_event, Some(expected_event)));
}

ping_via_bridge {
let _ = T::TransferPingOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;

let (bridged_network, bridge_config) = T::BenchmarkHelper::bridge_config()
.ok_or(BenchmarkError::Stop("missing `bridge_config` data"))?;
AllowedExporters::<T>::insert(bridged_network, bridge_config);

let (origin, destination) = T::BenchmarkHelper::prepare_ping_transfer()
.ok_or(BenchmarkError::Stop("missing `prepare_ping_transfer` data"))?;

let origin_location = T::TransferPingOrigin::ensure_origin(origin.clone()).map_err(|_| BenchmarkError::Stop("invalid `origin`"),
)?;
let (_, _, destination_location) = Pallet::<T>::ensure_remote_destination(destination.clone()).map_err(|_|
BenchmarkError::Stop("invalid `destination_location`"),
)?;
let _ = T::PingMessageBuilder::try_build(&origin_location, &bridged_network, &destination_location).ok_or(
BenchmarkError::Stop("invalid `PingMessageBuilder`"),
)?;
}: _<T::RuntimeOrigin>(origin, Box::new(destination))
verify {
// we don't care about message hash or sender cost here, just check that the transfer has been initiated
let actual_event = frame_system::Pallet::<T>::events().pop().map(|r| r.event);
let expected_event: <T as Config>::RuntimeEvent = Event::TransferInitiated {
message_hash: Default::default(),
sender_cost: Default::default(),
}.into();
assert!(matches!(actual_event, Some(expected_event)));
}

add_exporter_config {
let origin = T::AdminOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let (bridged_network, bridge_config) = T::BenchmarkHelper::bridge_config()
.ok_or(BenchmarkError::Stop("missing `bridge_config` data"))?;
}: _<T::RuntimeOrigin>(origin, bridged_network, Box::new(bridge_config.clone()))
verify {
assert_eq!(AllowedExporters::<T>::get(bridged_network), Some(bridge_config));
}

remove_exporter_config {
let origin = T::AdminOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let (bridged_network, bridge_config) = T::BenchmarkHelper::bridge_config()
.ok_or(BenchmarkError::Stop("missing `bridge_config` data"))?;
AllowedExporters::<T>::insert(bridged_network, bridge_config);
}: _<T::RuntimeOrigin>(origin, bridged_network)
verify {
assert_eq!(AllowedExporters::<T>::get(bridged_network), None);
}

update_exporter_config {
let origin = T::AdminOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let (bridged_network, bridge_config) = T::BenchmarkHelper::bridge_config()
.ok_or(BenchmarkError::Stop("missing `bridge_config` data"))?;
AllowedExporters::<T>::insert(bridged_network, bridge_config);

let bridge_location_fee = None;
let target_location_fee = Some(xcm::VersionedMultiAsset::V3(MultiAsset {
id: Concrete(MultiLocation::parent()),
fun: Fungible(1_000_0000),
}));
}: _<T::RuntimeOrigin>(origin, bridged_network, bridge_location_fee.clone().map(Box::new), target_location_fee.clone().map(Box::new))
verify {
let exporter = AllowedExporters::<T>::get(bridged_network).unwrap();
assert_eq!(exporter.bridge_location_fee, bridge_location_fee.map(|fee| MultiAsset::try_from(fee).unwrap()));
assert_eq!(exporter.max_target_location_fee, target_location_fee.map(|fee| MultiAsset::try_from(fee).unwrap()));
}

add_universal_alias {
let origin = T::AdminOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let (location, junction) = match T::BenchmarkHelper::universal_alias() {
Some(alias) => alias,
None => match T::UniversalAliasesLimit::get() > 0_u32 {
true => return Err(BenchmarkError::Stop("missing `universal_alias` data")),
false => return Err(BenchmarkError::Weightless),
}
};
}: _<T::RuntimeOrigin>(origin, Box::new(location.clone()), junction)
verify {
assert!(AllowedUniversalAliases::<T>::get(&location.try_as().unwrap()).contains(&junction));
}

remove_universal_alias {
let origin = T::AdminOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let (location, junction) = match T::BenchmarkHelper::universal_alias() {
Some(alias) => alias,
None => match T::UniversalAliasesLimit::get() > 0_u32 {
true => return Err(BenchmarkError::Stop("missing `universal_alias` data")),
false => return Err(BenchmarkError::Weightless),
}
};
Pallet::<T>::insert_universal_alias_for_benchmarks((location.clone().try_into().unwrap(), junction));
}: _<T::RuntimeOrigin>(origin, Box::new(location.clone()), vec![junction.clone()])
verify {
assert!(!AllowedUniversalAliases::<T>::get(&location.try_as().unwrap()).contains(&junction));
}

add_reserve_location {
let origin = T::AdminOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let location = match T::BenchmarkHelper::reserve_location() {
Some(location) => location,
None => match T::ReserveLocationsLimit::get() > 0_u32 {
true => return Err(BenchmarkError::Stop("missing `reserve_location` data")),
false => return Err(BenchmarkError::Weightless),
}
};
}: _<T::RuntimeOrigin>(origin, Box::new(location.clone()))
verify {
assert!(AllowedReserveLocations::<T>::get().contains(&location.try_as().unwrap()));
}

remove_reserve_location {
let origin = T::AdminOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let location = match T::BenchmarkHelper::reserve_location() {
Some(location) => location,
None => match T::ReserveLocationsLimit::get() > 0_u32 {
true => return Err(BenchmarkError::Stop("missing `reserve_location` data")),
false => return Err(BenchmarkError::Weightless),
}
};
let multilocation: MultiLocation = location.clone().try_into().unwrap();
assert!(AllowedReserveLocations::<T>::try_mutate(|locations| locations.try_insert(multilocation)).unwrap());
}: _<T::RuntimeOrigin>(origin, vec![location.clone()])
verify {
assert!(!AllowedReserveLocations::<T>::get().contains(&location.try_as().unwrap()));
}

impl_benchmark_test_suite!(Pallet, crate::tests::new_test_ext(), crate::tests::TestRuntime);
}
56 changes: 56 additions & 0 deletions parachains/pallets/bridge-transfer/src/impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (C) 2023 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::{Config, Pallet};
use frame_support::traits::{Contains, ContainsPair};
use xcm::prelude::*;
use xcm_builder::ExporterFor;

/// `ExporterFor` implementation to check if we can transfer anything to `NetworkId`
impl<T: Config> ExporterFor for Pallet<T> {
fn exporter_for(
network: &NetworkId,
_remote_location: &InteriorMultiLocation,
_message: &Xcm<()>,
) -> Option<(MultiLocation, Option<MultiAsset>)> {
Self::allowed_exporters(network)
.map(|bridge_config| (bridge_config.bridge_location, bridge_config.bridge_location_fee))
}
}

/// Verifies if we have `(MultiLocation, Junction)` in allowed universal aliases.
pub struct AllowedUniversalAliasesOf<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> Contains<(MultiLocation, Junction)> for AllowedUniversalAliasesOf<T> {
fn contains((location, junction): &(MultiLocation, Junction)) -> bool {
log::trace!(target: "xcm::contains", "AllowedUniversalAliasesOf location: {:?}, junction: {:?}", location, junction);
Pallet::<T>::allowed_universal_aliases(location).contains(junction)
}
}

/// Verifies if we can allow `(MultiAsset, MultiLocation)` as trusted reserve.
pub struct IsAllowedReserveOf<T, F>(sp_std::marker::PhantomData<(T, F)>);
impl<T: Config, F: ContainsPair<MultiAsset, MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
for IsAllowedReserveOf<T, F>
{
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
log::trace!(target: "xcm::contains", "IsAllowedReserveOf asset: {:?}, origin: {:?}", asset, origin);
// first check - if we have configured origin as trusted reserve location
if !Pallet::<T>::allowed_reserve_locations().contains(origin) {
return false
}
// second check - we need to pass additional `(asset, origin)` filter
F::contains(asset, origin)
}
}
Loading