Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

XCM Benchmarks for Asset Transactor w/ Fungible Asset #3818

Merged
merged 31 commits into from
Sep 27, 2021

Conversation

shawntabrizi
Copy link
Member

This PR includes benchmarks for XCMs which use the AssetTransactor trait, implemented for an asset which implements the Fungible trait.

@paritytech paritytech deleted a comment from parity-benchapp bot Sep 9, 2021
@shawntabrizi
Copy link
Member Author

/benchmark runtime custom --chain=westend-dev --pallet=pallet_xcm_benchmarks::fungible --extrinsic="*" --steps=10 --repeat=10 --template=./xcm/pallet-xcm-benchmarks/template.hbs --output=./ --execution=wasm --wasm-execution=compiled

@parity-benchapp
Copy link

parity-benchapp bot commented Sep 9, 2021

Benchmark Runtime Custom for branch "shawntabrizi-fungible-benchmarks" with command cargo run --quiet --release --features runtime-benchmarks -- benchmark --chain=westend-dev --pallet=pallet_xcm_benchmarks::fungible --extrinsic="*" --steps=10 --repeat=10 --template=./xcm/pallet-xcm-benchmarks/template.hbs --output=./ --execution=wasm --wasm-execution=compiled

Results
Pallet: "pallet_xcm_benchmarks::fungible", Extrinsic: "withdraw_asset", Lowest values: [], Highest values: [], Steps: 10, Repeat: 10
Raw Storage Info
========
Storage: System Account (r:1 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=     39.3
              µs

Reads = 1
Writes = 1

Min Squares Analysis
========
-- Extrinsic Time --

Model:
Time ~=     39.3
              µs

Reads = 1
Writes = 1

Pallet: "pallet_xcm_benchmarks::fungible", Extrinsic: "transfer_asset", Lowest values: [], Highest values: [], Steps: 10, Repeat: 10
Raw Storage Info
========
Storage: System Account (r:2 w:2)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    60.53
              µs

Reads = 2
Writes = 2

Min Squares Analysis
========
-- Extrinsic Time --

Model:
Time ~=    60.53
              µs

Reads = 2
Writes = 2

Pallet: "pallet_xcm_benchmarks::fungible", Extrinsic: "transfer_reserve_asset", Lowest values: [], Highest values: [], Steps: 10, Repeat: 10
Raw Storage Info
========
Storage: System Account (r:2 w:2)
Storage: Dmp DownwardMessageQueueHeads (r:1 w:1)
Storage: Dmp DownwardMessageQueues (r:1 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    83.37
              µs

Reads = 4
Writes = 4

Min Squares Analysis
========
-- Extrinsic Time --

Model:
Time ~=    83.37
              µs

Reads = 4
Writes = 4

Pallet: "pallet_xcm_benchmarks::fungible", Extrinsic: "receive_teleported_asset", Lowest values: [], Highest values: [], Steps: 10, Repeat: 10
Raw Storage Info
========
Storage: Benchmark Override (r:0 w:0)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~= 18446744073700
              µs

Reads = 0
Writes = 0

Min Squares Analysis
========
-- Extrinsic Time --

Model:
Time ~= 18446744073700
              µs

Reads = 0
Writes = 0

Pallet: "pallet_xcm_benchmarks::fungible", Extrinsic: "deposit_asset", Lowest values: [], Highest values: [], Steps: 10, Repeat: 10
Raw Storage Info
========
Storage: System Account (r:1 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    49.37
              µs

Reads = 1
Writes = 1

Min Squares Analysis
========
-- Extrinsic Time --

Model:
Time ~=    49.37
              µs

Reads = 1
Writes = 1

Pallet: "pallet_xcm_benchmarks::fungible", Extrinsic: "deposit_reserve_asset", Lowest values: [], Highest values: [], Steps: 10, Repeat: 10
Raw Storage Info
========
Storage: System Account (r:1 w:1)
Storage: Dmp DownwardMessageQueueHeads (r:1 w:1)
Storage: Dmp DownwardMessageQueues (r:1 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    75.99
              µs

Reads = 3
Writes = 3

Min Squares Analysis
========
-- Extrinsic Time --

Model:
Time ~=    75.99
              µs

Reads = 3
Writes = 3

Pallet: "pallet_xcm_benchmarks::fungible", Extrinsic: "initiate_teleport", Lowest values: [], Highest values: [], Steps: 10, Repeat: 10
Raw Storage Info
========
Storage: System Account (r:1 w:1)
Storage: Dmp DownwardMessageQueueHeads (r:1 w:1)
Storage: Dmp DownwardMessageQueues (r:1 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    76.46
              µs

Reads = 3
Writes = 3

Min Squares Analysis
========
-- Extrinsic Time --

Model:
Time ~=    76.46
              µs

Reads = 3
Writes = 3


…k --chain=westend-dev --pallet=pallet_xcm_benchmarks::fungible --extrinsic=* --steps=10 --repeat=10 --template=./xcm/pallet-xcm-benchmarks/template.hbs --output=./ --execution=wasm --wasm-execution=compiled
@shawntabrizi shawntabrizi added B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. and removed D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. labels Sep 9, 2021
@shawntabrizi
Copy link
Member Author

/benchmark runtime custom --chain=westend-dev --pallet=pallet_xcm_benchmarks::fungible --extrinsic="*" --steps=50 --repeat=20 --template=./xcm/pallet-xcm-benchmarks/template.hbs --output=./ --execution=wasm --wasm-execution=compiled

@parity-benchapp
Copy link

parity-benchapp bot commented Sep 10, 2021

Benchmark Runtime Custom for branch "shawntabrizi-fungible-benchmarks" with command cargo run --quiet --release --features runtime-benchmarks -- benchmark --chain=westend-dev --pallet=pallet_xcm_benchmarks::fungible --extrinsic="*" --steps=50 --repeat=20 --template=./xcm/pallet-xcm-benchmarks/template.hbs --output=./ --execution=wasm --wasm-execution=compiled

Results
2021-09-10 12:38:05 Took active validators from set with wrong size    
2021-09-10 12:38:05 Took active validators from set with wrong size    
2021-09-10 12:38:06 WARNING: benchmark error skipped - receive_teleported_asset    
2021-09-10 12:38:06 WARNING: benchmark error skipped - receive_teleported_asset    
Error: 
   0: �[91mInvalid input: Benchmark not found for this pallet.�[0m

Backtrace omitted.
Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

ERROR: Unable to commit file ./

@shawntabrizi
Copy link
Member Author

/benchmark xcm westend pallet_xcm_benchmarks::fungible

@shawntabrizi
Copy link
Member Author

/benchmark xcm westend pallet_xcm_benchmarks::fungible

@parity-benchapp
Copy link

parity-benchapp bot commented Sep 17, 2021

Benchmark Westend XCM for branch "shawntabrizi-fungible-benchmarks" with command cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=pallet_xcm_benchmarks::fungible --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --template=./xcm/pallet-xcm-benchmarks/template.hbs --output=./runtime/westend/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs

Results
2021-09-17 04:46:50 [0] 💸 generated 1 npos voters, 1 from validators and 0 nominators    
2021-09-17 04:46:50 Took active validators from set with wrong size    
2021-09-17 04:46:50 Took active validators from set with wrong size.    
2021-09-17 04:46:50 Took active validators from set with wrong size    
2021-09-17 04:46:52 WARNING: benchmark error skipped - receive_teleported_asset    
2021-09-17 04:46:52 WARNING: benchmark error skipped - receive_teleported_asset    
Error: 
   0: �[91mInvalid input: Benchmark not found for this pallet.�[0m

Backtrace omitted.
Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

ERROR: Unable to commit file ./runtime/westend/src/weights/xcm/pallet_xcm_benchmarks_fungible.rs

# temp
pallet-xcm = { path = "../pallet-xcm" }
polkadot-runtime-common = { path = "../../runtime/common" }
# westend-runtime = { path = "../../runtime/westend", features = ["runtime-benchmarks"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO remove me later

Comment on lines +60 to +61
const HOLDING_FUNGIBLES: u32 = 99;
const HOLDING_NON_FUNGIBLES: u32 = 99;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should go into the config of the corresponding xcm_benchmark pallet, right?

const HOLDING_NON_FUNGIBLES: u32 = 99;

pub fn worst_case_holding() -> Assets {
let fungibles_amount: u128 = 100; // TODO probably update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your opinion was always sticking to ED and multiplies thereof, which should be possible here if you pass in a T.

let instruction = Instruction::TransferReserveAsset {
assets,
dest: dest_location,
xcm: Xcm::new()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the cost of this nested send is already incorporated here, this is much simpler than the old scheme of order and effect.

let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap();
assert!(T::TransactAsset::balance(&dest_account).is_zero());

let mut executor = new_executor::<T>(Default::default());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might want to make it fn new_executor<T: Config>(_: MultiLocation, initial_holding: Assets)

@@ -0,0 +1,180 @@
// Copyright 2021 Parity Technologies (UK) Ltd.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not super relevant yet since this PR is only about the fungible, but once a fungibles has been added as well, it would be sad to see this mock almost entirely duplicated. I think one mock runtime that implements both xcm_benchamrk::fungible::Config and xcm_benchamrk::fungibles::Config should work fine.

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, most TODOs seem to be related to the next steps, I think we can leave them, try and merge this, to keep the PRs within bite-size pieces.

shawntabrizi and others added 2 commits September 23, 2021 01:01
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
runtime/westend/src/lib.rs Show resolved Hide resolved
Comment on lines 115 to 121
fn report_error(
_query_id: &QueryId,
_dest: &MultiLocation,
max_response_weight: &u64,
) -> Weight {
*max_response_weight
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mark this as preliminary?
the max_response_weight is about the response, no the error itself, right?
there should probably be a XcmGeneric::<Runtime>::report_error(query_id, dest) or similar?

Copy link
Contributor

@apopiak apopiak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for XCM weights/benchmarks! 🎉
Seems to me this has a few rough edges. Unclear to me whether you want to smooth those out now or in a follow up PR.

impl pallet_xcm_benchmarks::Config for Runtime {
type XcmConfig = XcmConfig;
type AccountIdConverter = LocationConverter;
fn valid_destination() -> Result<MultiLocation, sp_runtime::DispatchError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DQ: Why does this return a result?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may need to be some setup required to make a destination valid, for example calling some dispatchables which sets up UMP/DMP settings, or gives a chain funds or anything. Also there may be no valid destination for a chain which doesnt communicate to anyone.

}
fn deposit_reserve_asset(
assets: &MultiAssetFilter,
_max_assets: &u32, // TODO use max assets?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100%, would be a nice reduction in weight

Comment on lines +151 to +154
fn initiate_teleport(
assets: &MultiAssetFilter,
_dest: &MultiLocation,
_xcm: &Xcm<()>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we're going to weigh intiate_teleport based on the worst-case holding?
a max_assets would be nice here as well, right?

Comment on lines +124 to +126
BenchmarkError::Override(
BenchmarkResult::from_weight(T::BlockWeights::get().max_block)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this covering for? shouldn't this always succeed or fail loudly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about chains who just do not support this particular XCM. it covers that scenario where you can still run benchmarks for everything else.

The resulting number screams pretty loudly.

Comment on lines +65 to +73
(0..HOLDING_FUNGIBLES)
.map(|i| {
MultiAsset {
id: Concrete(GeneralIndex(i as u128).into()),
fun: Fungible(fungibles_amount * i as u128),
}
.into()
})
.chain(core::iter::once(MultiAsset { id: Concrete(Here.into()), fun: Fungible(u128::MAX) }))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means the worst case holding amount of fungibles is 100, potentially increasing to 101 if the benchmark adds a new asset.
Is that the desired setup?

Comment on lines +89 to +91
pub fn new_executor<T: Config>(origin: MultiLocation) -> ExecutorOf<T> {
ExecutorOf::<T>::new(origin)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this, (or a differently named util function) might also just populate the executor with a worst-case holding on construction

Comment on lines +59 to +64
pub struct AllAssetLocationsPass;
impl FilterAssetLocation for AllAssetLocationsPass {
fn filter_asset_location(_: &MultiAsset, _: &MultiLocation) -> bool {
true
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unused?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? it is a mock function to enable tests to pass

type CheckedAccount: Get<Option<Self::AccountId>>;

/// A trusted location which we allow teleports from, and the asset we allow to teleport.
type TrustedTeleporter: Get<Option<(xcm::latest::MultiLocation, xcm::latest::MultiAsset)>>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why introduce an extra asset here?, you already have get_multi_asset below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be a different asset for teleports versus other xcm messages.

why are you worried about including more information?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just trying to keep the interface/config tidy.


impl crate::Config for Test {
type XcmConfig = XcmConfig;
type AccountIdConverter = AccountIdConverter;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why introduce an extra AccountIdConverter when there is the OriginConverter in the XcmConfig?

fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight;
}

// TODO wild case
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo.
I'm guessing you'll address this in a follow-up PR?

Copy link
Contributor

@apopiak apopiak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine if we iron out any kinks in follow ups.

@shawntabrizi
Copy link
Member Author

bot merge

@ghost
Copy link

ghost commented Sep 27, 2021

Waiting for commit status.

@ghost
Copy link

ghost commented Sep 27, 2021

Merge aborted: Checks failed for 7b47f5c

@shawntabrizi
Copy link
Member Author

https://research.web3.foundation/ is down and causing the CI failure.

@shawntabrizi shawntabrizi merged commit f0b2bf3 into master Sep 27, 2021
@shawntabrizi shawntabrizi deleted the shawntabrizi-fungible-benchmarks branch September 27, 2021 04:38
@mmostafas mmostafas added D1-audited 👍 PR contains changes to critical logic that has been properly reviewed and externally audited. and removed D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels Sep 28, 2021
ordian added a commit that referenced this pull request Sep 28, 2021
* master: (24 commits)
  Added multisig in Rococo (#3873)
  Fix bin-substrate toml (#3939)
  Bump tracing from 0.1.27 to 0.1.28 (#3937)
  XCM Benchmarks for Asset Transactor w/ Fungible Asset (#3818)
  Bump libc from 0.2.101 to 0.2.102 (#3933)
  Do not compile `wasm_api` module when not needed. (#3934)
  Bump syn from 1.0.76 to 1.0.77 (#3932)
  Fix spelling (#3845)
  Bump tokio from 1.11.0 to 1.12.0 (#3910)
  Ignore `generate-bags` by dependabot (#3930)
  Update logging in paras_inherent (#3927)
  Bump libsecp256k1 from 0.6.0 to 0.7.0 (#3909)
  Remove BEEFY repo dependency (#3923)
  Substrate Companion for rust 1.54 (#3807)
  Fix broken links (#3919)
  update BaseXcmWegiht to match Kusama (#3911)
  add parachains pallets to Polkadot runtime (#3815)
  Add a `force_unfreeze` extrinsic to the disputes module (#3906)
  Add new rococo chainspec (#3905)
  Ensure all parachain configuration extrinsics are operational (#3912)
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D1-audited 👍 PR contains changes to critical logic that has been properly reviewed and externally audited.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants