Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
baf1be9
Here's a template for you.
kianenigma Jul 30, 2021
3f357a0
All tests compile
kianenigma Jul 30, 2021
ac40480
finish the skeleton
kianenigma Jul 30, 2021
a43758a
More baby steps
kianenigma Jul 31, 2021
1dc11da
Build is broken
kianenigma Jul 31, 2021
e4792b7
Merge branch 'master' of github.com:paritytech/polkadot into kiz-xcm-…
kianenigma Jul 31, 2021
cb91ac6
make westend work again
kianenigma Jul 31, 2021
5b33749
mock weight generation
shawntabrizi Jul 31, 2021
ed9149f
Merge branch 'kiz-xcm-bench-pallet' of https://github.com/paritytech/…
shawntabrizi Jul 31, 2021
d99d4f9
just some boilerpalate
kianenigma Jul 31, 2021
5483da8
Merge branch 'kiz-xcm-bench-pallet' of github.com:paritytech/polkadot…
kianenigma Jul 31, 2021
e9081ea
Everythign works again in a new format
kianenigma Aug 1, 2021
d976204
add the new files
kianenigma Aug 1, 2021
44c212d
more weight info
shawntabrizi Aug 2, 2021
1f70c4c
new format again
kianenigma Aug 2, 2021
324be3d
Merge branch 'kiz-xcm-bench-pallet' of github.com:paritytech/polkadot…
kianenigma Aug 2, 2021
d61c255
remove files
kianenigma Aug 2, 2021
139e1aa
Update traits.rs
shawntabrizi Aug 2, 2021
145f522
stuff
shawntabrizi Aug 2, 2021
feb6bac
push for shawn
kianenigma Aug 3, 2021
3915752
Everything now builds
kianenigma Aug 3, 2021
649b422
pallet-xcm-benchmarks fully compiles again with benchmarks added
kianenigma Aug 3, 2021
b7750a0
push midway
kianenigma Aug 3, 2021
78c4c3e
make build
shawntabrizi Aug 3, 2021
2049112
fix benchmark compile
shawntabrizi Aug 3, 2021
45dedc9
benchmark fix
shawntabrizi Aug 3, 2021
893d572
fix benchmark
shawntabrizi Aug 3, 2021
2038bbd
new bm
shawntabrizi Aug 4, 2021
3b056c7
more benches
shawntabrizi Aug 4, 2021
46a3af0
fix bench
shawntabrizi Aug 4, 2021
e400bc1
finish fungible?
shawntabrizi Aug 4, 2021
6621af3
fix westend build
shawntabrizi Aug 4, 2021
f20ae75
benchmark barrier
shawntabrizi Aug 4, 2021
e4b8a4c
use `ValidDestination`
shawntabrizi Aug 4, 2021
8479329
working on westend
shawntabrizi Aug 4, 2021
d5fd2f8
Merge branch 'master' into kiz-xcm-bench-pallet-extended
shawntabrizi Aug 7, 2021
c8819da
fix xcm v1
shawntabrizi Aug 7, 2021
b56df81
fix xcm-executor
shawntabrizi Aug 7, 2021
9c33a40
fix xcm-builder
shawntabrizi Aug 7, 2021
4fddeae
make benchmarks compile
shawntabrizi Aug 7, 2021
6f29de0
make tests work
shawntabrizi Aug 7, 2021
768a92a
fix westend benchmarks build
shawntabrizi Aug 7, 2021
3c578e4
use generated weight in westend
shawntabrizi Aug 7, 2021
be9cbb6
start fixing xcm_generic
shawntabrizi Aug 7, 2021
b782a31
most of xcm generic
shawntabrizi Aug 7, 2021
3a26395
clean up
shawntabrizi Aug 8, 2021
a950330
Merge branch 'master' into kiz-xcm-bench-pallet-extended
shawntabrizi Aug 8, 2021
3915381
Update Cargo.lock
shawntabrizi Aug 8, 2021
fc00dc1
fix merge
shawntabrizi Aug 8, 2021
c7c0f2b
more cleanup
shawntabrizi Aug 8, 2021
62bb8ee
fix warnings
shawntabrizi Aug 8, 2021
de3247b
more cleanup
shawntabrizi Aug 8, 2021
65a9df8
point to separate modules
shawntabrizi Aug 8, 2021
d62420e
temp fix, use zero weight
shawntabrizi Aug 8, 2021
be98ce1
Merge remote-tracking branch 'origin/master' into kiz-xcm-bench-palle…
shawntabrizi Aug 10, 2021
3c08461
fix pallet-xcm-benchmarks
shawntabrizi Aug 10, 2021
0be427c
fix westend benchmarks
shawntabrizi Aug 10, 2021
ac6445c
Merge branch 'master' into kiz-xcm-bench-pallet-extended
shawntabrizi Aug 12, 2021
c352a6e
Delete mock2.rs
shawntabrizi Aug 12, 2021
71cedbf
Merge branch 'master' into kiz-xcm-bench-pallet-extended
shawntabrizi Aug 19, 2021
8c0191a
fix merge
shawntabrizi Aug 19, 2021
edacc76
Merge branch 'master' into kiz-xcm-bench-pallet-extended
shawntabrizi Sep 2, 2021
91b2c13
update trait for v2
shawntabrizi Sep 5, 2021
d1fbaef
basic final weight (maybe wrong)
shawntabrizi Sep 5, 2021
45b5dd4
fix barrier
shawntabrizi Sep 5, 2021
e720007
start to clean up benchmarks
shawntabrizi Sep 5, 2021
12bfc2b
more fixes
shawntabrizi Sep 5, 2021
9ed8a4c
fix more
shawntabrizi Sep 5, 2021
8078c35
Merge branch 'master' into kiz-xcm-bench-pallet-extended
shawntabrizi Sep 5, 2021
ec16d44
update xcm_weight
shawntabrizi Sep 6, 2021
fe27083
executor error and pub
shawntabrizi Sep 6, 2021
f99e086
Merge branch 'master' into kiz-xcm-bench-pallet-extended
shawntabrizi Sep 6, 2021
1d0f6f6
more benchmarks
shawntabrizi Sep 6, 2021
894cd69
Merge branch 'master' into kiz-xcm-bench-pallet-extended
shawntabrizi Sep 6, 2021
b18a7e9
Update Cargo.lock
shawntabrizi Sep 7, 2021
402282c
more
shawntabrizi Sep 7, 2021
e091c29
more
shawntabrizi Sep 7, 2021
40c613d
Merge branch 'master' into kiz-xcm-bench-pallet-extended
shawntabrizi Sep 7, 2021
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ members = [
"xcm/xcm-simulator",
"xcm/xcm-simulator/example",
"xcm/pallet-xcm",
"xcm/pallet-xcm-benchmarks",
"xcm/procedural",
"node/client",
"node/collation-generation",
Expand Down
2 changes: 2 additions & 0 deletions runtime/westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "m
pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-vesting = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-xcm = { path = "../../xcm/pallet-xcm", default-features = false }
pallet-xcm-benchmarks = { path = "../../xcm/pallet-xcm-benchmarks", default-features = false, optional = true }

frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
Expand Down Expand Up @@ -198,6 +199,7 @@ runtime-benchmarks = [
"frame-system-benchmarking",
"hex-literal",
"xcm-builder/runtime-benchmarks",
"pallet-xcm-benchmarks",
"frame-election-provider-support/runtime-benchmarks",
]
try-runtime = [
Expand Down
61 changes: 59 additions & 2 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use runtime_parachains::{

use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom,
AccountId32Aliases, AllowBenchmarks, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom,
ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete,
LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
Expand Down Expand Up @@ -99,6 +99,7 @@ use constants::{currency::*, fee::*, time::*};

// Weights used in the runtime
mod weights;
mod xcm_weights;

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -916,8 +917,9 @@ pub type XcmRouter = (
);

parameter_types! {
pub const Westmint: MultiLocation = Parachain(1000).into();
pub const WestendForWestmint: (MultiAssetFilter, MultiLocation) =
(Wild(AllOf { fun: WildFungible, id: Concrete(WndLocation::get()) }), Parachain(1000).into());
(Wild(AllOf { fun: WildFungible, id: Concrete(WndLocation::get()) }), Westmint::get());
pub const MaxInstructions: u32 = 100;
}
pub type TrustedTeleporters = (xcm_builder::Case<WestendForWestmint>,);
Expand All @@ -930,6 +932,9 @@ pub type Barrier = (
AllowTopLevelPaidExecutionFrom<Everything>,
// Messages coming from system parachains need not pay for execution.
AllowUnpaidExecutionFrom<IsChildSystemParachain<ParaId>>,
// The last barrier should allow benchmarks through.
// We want it to be last so that other barriers are touched for a "worst case scenario".
AllowBenchmarks,
);

pub struct XcmConfig;
Expand Down Expand Up @@ -1396,6 +1401,9 @@ sp_api::impl_runtime_apis! {
use pallet_offences_benchmarking::Pallet as OffencesBench;
use frame_system_benchmarking::Pallet as SystemBench;

type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::<Runtime>;
type XcmGeneric = pallet_xcm_benchmarks::xcm_generic::Pallet::<Runtime>;

let mut list = Vec::<BenchmarkList>::new();

// Polkadot
Expand All @@ -1405,6 +1413,7 @@ sp_api::impl_runtime_apis! {
list_benchmark!(list, extra, runtime_common::crowdloan, Crowdloan);
list_benchmark!(list, extra, runtime_common::paras_registrar, Registrar);
list_benchmark!(list, extra, runtime_common::slots, Slots);

// Substrate
list_benchmark!(list, extra, pallet_balances, Balances);
list_benchmark!(list, extra, pallet_election_provider_multi_phase, ElectionProviderMultiPhase);
Expand All @@ -1422,6 +1431,11 @@ sp_api::impl_runtime_apis! {
list_benchmark!(list, extra, pallet_utility, Utility);
list_benchmark!(list, extra, pallet_vesting, Vesting);

// XCM Benchmarks
// NOTE: Make sure you point to the individual modules below.
list_benchmark!(list, extra, pallet_xcm_benchmarks::fungible, XcmBalances);
list_benchmark!(list, extra, pallet_xcm_benchmarks::xcm_generic, XcmGeneric);

let storage_info = AllPalletsWithSystem::storage_info();

return (list, storage_info)
Expand All @@ -1444,6 +1458,43 @@ sp_api::impl_runtime_apis! {
impl pallet_offences_benchmarking::Config for Runtime {}
impl frame_system_benchmarking::Config for Runtime {}

use xcm::latest::MultiAsset;

impl pallet_xcm_benchmarks::Config for Runtime {
type XcmConfig = XcmConfig;
type AccountIdConverter = LocationConverter;
fn valid_destination() -> Result<MultiLocation, sp_runtime::DispatchError> {
let valid_destination = Westmint::get();
XcmPallet::set_xcm_version(&valid_destination, xcm::latest::VERSION);
Ok(valid_destination)
}
}

impl pallet_xcm_benchmarks::xcm_generic::Config for Runtime {
type Call = Call;

fn worst_case_response() -> (u64, Response) {
let assets: MultiAssets = (Concrete(WndLocation::get()), 1 * UNITS).into();
(0, Response::Assets(assets))
}
}

impl pallet_xcm_benchmarks::fungible::Config for Runtime {
type TransactAsset = Balances;

type CheckedAccount = CheckAccount;

fn get_multi_asset() -> MultiAsset {
MultiAsset {
id: Concrete(WndLocation::get()),
fun: Fungible(1 * UNITS),
}
}
}

type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::<Runtime>;
type XcmGeneric = pallet_xcm_benchmarks::xcm_generic::Pallet::<Runtime>;

let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
Expand All @@ -1469,6 +1520,7 @@ sp_api::impl_runtime_apis! {
add_benchmark!(params, batches, runtime_common::crowdloan, Crowdloan);
add_benchmark!(params, batches, runtime_common::paras_registrar, Registrar);
add_benchmark!(params, batches, runtime_common::slots, Slots);

// Substrate
add_benchmark!(params, batches, pallet_balances, Balances);
add_benchmark!(params, batches, pallet_election_provider_multi_phase, ElectionProviderMultiPhase);
Expand All @@ -1486,6 +1538,11 @@ sp_api::impl_runtime_apis! {
add_benchmark!(params, batches, pallet_utility, Utility);
add_benchmark!(params, batches, pallet_vesting, Vesting);

// XCM Benchmarks
// NOTE: Make sure you point to the individual modules below.
add_benchmark!(params, batches, pallet_xcm_benchmarks::fungible, XcmBalances);
add_benchmark!(params, batches, pallet_xcm_benchmarks::xcm_generic, XcmGeneric);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
}
Expand Down
192 changes: 192 additions & 0 deletions runtime/westend/src/xcm_weights/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
mod xcm_balances;
mod xcm_generic;

use frame_support::weights::Weight;
use xcm_balances::WeightInfo as XcmBalancesWeight;

use crate::Runtime;
use sp_std::prelude::*;
use xcm::{latest::prelude::*, DoubleEncoded};
use xcm_generic::WeightInfo as XcmGeneric;

pub enum AssetTypes {
Balances,
Unknown,
}

impl From<&MultiAsset> for AssetTypes {
fn from(asset: &MultiAsset) -> Self {
match asset {
MultiAsset { id: Concrete(MultiLocation { parents: 0, interior: Here }), .. } =>
AssetTypes::Balances,
_ => AssetTypes::Unknown,
}
}
}

// TODO from Shawn: I dont like this
trait WeighMultiAssets {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight;
}

// TODO wild case
impl WeighMultiAssets for MultiAssetFilter {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight {
match self {
Self::Definite(assets) => assets
.inner()
.into_iter()
.map(|m| <AssetTypes as From<&MultiAsset>>::from(m))
.map(|t| match t {
AssetTypes::Balances => balances_weight,
AssetTypes::Unknown => Weight::MAX,
})
.fold(0, |acc, x| acc.saturating_add(x)),
_ => Weight::MAX,
}
}
}

impl WeighMultiAssets for MultiAssets {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight {
self.inner()
.into_iter()
.map(|m| <AssetTypes as From<&MultiAsset>>::from(m))
.map(|t| match t {
AssetTypes::Balances => balances_weight,
AssetTypes::Unknown => Weight::MAX,
})
.fold(0, |acc, x| acc.saturating_add(x))
}
}

pub struct WestendXcmWeight;
impl XcmWeightInfo<()> for WestendXcmWeight {
fn withdraw_asset(assets: &MultiAssets) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::withdraw_asset())
}
fn reserve_asset_deposited(assets: &MultiAssets) -> Weight {
assets.weigh_multi_assets(XcmGeneric::<Runtime>::reserve_asset_deposited())
}
// TODO none of these need effects
fn receive_teleported_asset(assets: &MultiAssets) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::receive_teleported_asset())
}
fn query_response(_query_id: &u64, _response: &Response, max_weight: &u64) -> Weight {
*max_weight
}
fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::transfer_asset())
}
fn transfer_reserve_asset(
assets: &MultiAssets,
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(
_origin_type: &OriginKind,
_require_weight_at_most: &u64,
_call: &DoubleEncoded<()>,
) -> Weight {
XcmGeneric::<Runtime>::transact()
}
fn hrmp_new_channel_open_request(
_sender: &u32,
_max_message_size: &u32,
_max_capacity: &u32,
) -> Weight {
XcmGeneric::<Runtime>::hrmp_new_channel_open_request()
}
fn hrmp_channel_accepted(_recipient: &u32) -> Weight {
XcmGeneric::<Runtime>::hrmp_channel_accepted()
}
fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> Weight {
XcmGeneric::<Runtime>::hrmp_channel_closing()
}
fn clear_origin() -> Weight {
XcmGeneric::<Runtime>::clear_origin()
}
fn descend_origin(who: &InteriorMultiLocation) -> Weight {
XcmGeneric::<Runtime>::descend_origin(who)
}
fn report_error(
_query_id: &QueryId,
_dest: &MultiLocation,
max_response_weight: &u64,
) -> Weight {
*max_response_weight
}
fn relayed_from(_who: &Junctions, _message: &Box<Xcm<()>>) -> Weight {
XcmGeneric::<Runtime>::relayed_from()
}

fn deposit_asset(
assets: &MultiAssetFilter,
_max_assets: &u32, // TODO use max assets?
_dest: &MultiLocation,
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::deposit_asset())
}
fn deposit_reserve_asset(
assets: &MultiAssetFilter,
_max_assets: &u32, // TODO use max assets?
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::deposit_reserve_asset())
}
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> Weight {
Weight::MAX // todo fix
}
fn initiate_reserve_withdraw(
assets: &MultiAssetFilter,
_reserve: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::initiate_reserve_withdraw())
}
fn initiate_teleport(
assets: &MultiAssetFilter,
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::initiate_teleport())
}
fn query_holding(
_query_id: &u64,
_dest: &MultiLocation,
_assets: &MultiAssetFilter,
_max_response_weight: &u64,
) -> Weight {
XcmGeneric::<Runtime>::query_holding()
}
fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> Weight {
XcmGeneric::<Runtime>::buy_execution()
}
fn refund_surplus() -> Weight {
XcmGeneric::<Runtime>::refund_surplus()
}
fn set_error_handler(_xcm: &Xcm<()>) -> Weight {
XcmGeneric::<Runtime>::set_error_handler()
}
fn set_appendix(_xcm: &Xcm<()>) -> Weight {
XcmGeneric::<Runtime>::set_appendix()
}
fn clear_error() -> Weight {
XcmGeneric::<Runtime>::clear_error()
}
fn claim_asset(assets: &MultiAssets, _ticket: &MultiLocation) -> Weight {
XcmGeneric::<Runtime>::claim_asset(assets)
}
fn trap(code: &u64) -> Weight {
XcmGeneric::<Runtime>::trap(code)
}
fn subscribe_version(_query_id: &QueryId, _max_response_weight: &u64) -> Weight {
XcmGeneric::<Runtime>::subscribe_version()
}
fn unsubscribe_version() -> Weight {
XcmGeneric::<Runtime>::unsubscribe_version()
}
}
Loading