Skip to content

Commit 78897f9

Browse files
girazokibkonturacatangiu
authored andcommitted
Allow configuration of worst case buy execution weight (paritytech#7944)
Adds `worst_case_buy_execution` to the Config trait of `pallet-xcm-benchmarks` with a default implementation that mimics the code that existed previous to this PR. Rationale: not allowing to set the `WeightLimit` and the `FeeAsset` might mean that we dont benchmark the worst case, as with `WeightLimit::Unlimited` the `Trader` does not even execute: https://github.com/paritytech/polkadot-sdk/blob/c01dbebeaa6394691974de46dd2d41a582f6a4c2/polkadot/xcm/xcm-executor/src/lib.rs#L833 The new configurable function allows projects to customize the parameters with which the benchmark is run to make sure they account for the worst-case scenario **This is very likely the case of the assethub system chain**, with several traders being analyzed and possibly several reads being made: https://github.com/paritytech/polkadot-sdk/blob/38d2fa859861005157ccb249dca1378f015e0b06/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs#L403 --------- Co-authored-by: Branislav Kontur <bkontur@gmail.com> Co-authored-by: Adrian Catangiu <adrian@parity.io>
1 parent cd9ab13 commit 78897f9

16 files changed

Lines changed: 101 additions & 47 deletions

File tree

bridges/chains/chain-bridge-hub-westend/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ frame_support::parameter_types! {
9494
/// The XCM fee that is paid for executing XCM program (with `ExportMessage` instruction) at the Westend
9595
/// BridgeHub.
9696
/// (initially was calculated by test `BridgeHubWestend::can_calculate_weight_for_paid_export_message_with_reserve_transfer` + `33%`)
97-
pub const BridgeHubWestendBaseXcmFeeInWnds: u128 = 18_191_740_000;
97+
pub const BridgeHubWestendBaseXcmFeeInWnds: u128 = 22_962_450_000;
9898

9999
/// Transaction fee that is paid at the Westend BridgeHub for delivering single inbound message.
100100
/// (initially was calculated by test `BridgeHubWestend::can_calculate_fee_for_standalone_message_delivery_transaction` + `33%`)

cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
101101
#[cfg(feature = "runtime-benchmarks")]
102102
use xcm::latest::prelude::{
103103
Asset, Assets as XcmAssets, Fungible, Here, InteriorLocation, Junction, Junction::*, Location,
104-
NetworkId, NonFungible, Parent, ParentThen, Response, XCM_VERSION,
104+
NetworkId, NonFungible, Parent, ParentThen, Response, WeightLimit, XCM_VERSION,
105105
};
106106
use xcm::{
107107
latest::prelude::{AssetId, BodyId},
@@ -1994,11 +1994,11 @@ impl_runtime_apis! {
19941994
Ok((origin, ticket, assets))
19951995
}
19961996

1997-
fn fee_asset() -> Result<Asset, BenchmarkError> {
1998-
Ok(Asset {
1997+
fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> {
1998+
Ok((Asset {
19991999
id: AssetId(TokenLocation::get()),
20002000
fun: Fungible(1_000_000 * UNITS),
2001-
})
2001+
}, WeightLimit::Limited(Weight::from_parts(5000, 5000))))
20022002
}
20032003

20042004
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {

cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ use frame_support::traits::PalletInfoAccess;
112112
#[cfg(feature = "runtime-benchmarks")]
113113
use xcm::latest::prelude::{
114114
Asset, Assets as XcmAssets, Fungible, Here, InteriorLocation, Junction, Junction::*, Location,
115-
NetworkId, NonFungible, Parent, ParentThen, Response, XCM_VERSION,
115+
NetworkId, NonFungible, Parent, ParentThen, Response, WeightLimit, XCM_VERSION,
116116
};
117117

118118
use xcm_runtime_apis::{
@@ -2265,11 +2265,11 @@ impl_runtime_apis! {
22652265
Ok((origin, ticket, assets))
22662266
}
22672267

2268-
fn fee_asset() -> Result<Asset, BenchmarkError> {
2269-
Ok(Asset {
2268+
fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> {
2269+
Ok((Asset {
22702270
id: AssetId(WestendLocation::get()),
22712271
fun: Fungible(1_000 * UNITS),
2272-
})
2272+
}, WeightLimit::Limited(Weight::from_parts(5000, 5000))))
22732273
}
22742274

22752275
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {

cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,11 +1253,11 @@ impl_runtime_apis! {
12531253
Ok((origin, ticket, assets))
12541254
}
12551255

1256-
fn fee_asset() -> Result<Asset, BenchmarkError> {
1257-
Ok(Asset {
1256+
fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> {
1257+
Ok((Asset {
12581258
id: AssetId(TokenLocation::get()),
12591259
fun: Fungible(1_000_000 * UNITS),
1260-
})
1260+
}, WeightLimit::Limited(Weight::from_parts(5000, 5000))))
12611261
}
12621262

12631263
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {

cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,11 +1193,11 @@ impl_runtime_apis! {
11931193
Ok((origin, ticket, assets))
11941194
}
11951195

1196-
fn fee_asset() -> Result<Asset, BenchmarkError> {
1197-
Ok(Asset {
1196+
fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> {
1197+
Ok((Asset {
11981198
id: AssetId(WestendLocation::get()),
11991199
fun: Fungible(1_000_000 * UNITS),
1200-
})
1200+
}, WeightLimit::Limited(Weight::from_parts(5000, 5000))))
12011201
}
12021202

12031203
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {
@@ -1270,7 +1270,11 @@ impl_runtime_apis! {
12701270
}
12711271

12721272
fn alias_origin() -> Result<(Location, Location), BenchmarkError> {
1273-
Err(BenchmarkError::Skip)
1273+
// Any location can alias to an internal location.
1274+
// Here parachain 1000 aliases to an internal account.
1275+
let origin = Location::new(1, [Parachain(1000)]);
1276+
let target = Location::new(1, [Parachain(1000), AccountId32 { id: [128u8; 32], network: None }]);
1277+
Ok((origin, target))
12741278
}
12751279
}
12761280

cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,11 +1275,11 @@ impl_runtime_apis! {
12751275
Ok((origin, ticket, assets))
12761276
}
12771277

1278-
fn fee_asset() -> Result<Asset, BenchmarkError> {
1279-
Ok(Asset {
1278+
fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> {
1279+
Ok((Asset {
12801280
id: AssetId(WndLocation::get()),
12811281
fun: Fungible(1_000_000 * UNITS),
1282-
})
1282+
}, WeightLimit::Limited(Weight::from_parts(5000, 5000))))
12831283
}
12841284

12851285
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {

cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,11 +1133,11 @@ impl_runtime_apis! {
11331133
Ok((origin, ticket, assets))
11341134
}
11351135

1136-
fn fee_asset() -> Result<Asset, BenchmarkError> {
1137-
Ok(Asset {
1136+
fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> {
1137+
Ok((Asset {
11381138
id: AssetId(RocRelayLocation::get()),
11391139
fun: Fungible(1_000_000 * UNITS),
1140-
})
1140+
}, WeightLimit::Limited(Weight::from_parts(5000, 5000))))
11411141
}
11421142

11431143
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {

cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,11 +1159,11 @@ impl_runtime_apis! {
11591159
Ok((origin, ticket, assets))
11601160
}
11611161

1162-
fn fee_asset() -> Result<Asset, BenchmarkError> {
1163-
Ok(Asset {
1162+
fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> {
1163+
Ok((Asset {
11641164
id: AssetId(TokenRelayLocation::get()),
11651165
fun: Fungible(1_000_000 * UNITS),
1166-
})
1166+
}, WeightLimit::Limited(Weight::from_parts(5000, 5000))))
11671167
}
11681168

11691169
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {

cumulus/parachains/runtimes/people/people-rococo/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,11 +1053,11 @@ impl_runtime_apis! {
10531053
Ok((origin, ticket, assets))
10541054
}
10551055

1056-
fn fee_asset() -> Result<Asset, BenchmarkError> {
1057-
Ok(Asset {
1056+
fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> {
1057+
Ok((Asset {
10581058
id: AssetId(RelayLocation::get()),
10591059
fun: Fungible(1_000_000 * UNITS),
1060-
})
1060+
}, WeightLimit::Limited(Weight::from_parts(5000, 5000))))
10611061
}
10621062

10631063
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {

cumulus/parachains/runtimes/people/people-westend/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,11 +1070,11 @@ impl_runtime_apis! {
10701070
Ok((origin, ticket, assets))
10711071
}
10721072

1073-
fn fee_asset() -> Result<Asset, BenchmarkError> {
1074-
Ok(Asset {
1073+
fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> {
1074+
Ok((Asset {
10751075
id: AssetId(RelayLocation::get()),
10761076
fun: Fungible(1_000_000 * UNITS),
1077-
})
1077+
}, WeightLimit::Limited(Weight::from_parts(5000, 5000))))
10781078
}
10791079

10801080
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {

0 commit comments

Comments
 (0)