Skip to content

Allow to set a worst case buy execution fee asset and weight#2962

Closed
girazoki wants to merge 4 commits intoparitytech:masterfrom
girazoki:girazoki-worst-case-buy-execution-weight
Closed

Allow to set a worst case buy execution fee asset and weight#2962
girazoki wants to merge 4 commits intoparitytech:masterfrom
girazoki:girazoki-worst-case-buy-execution-weight

Conversation

@girazoki
Copy link
Copy Markdown
Contributor

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:

if let Some(weight) = Option::<Weight>::from(weight_limit) {

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

@girazoki girazoki requested a review from a team as a code owner January 17, 2024 11:40
let fee_asset = AssetId(Here.into());
// The worst case we want for buy execution in terms of
// fee asset and weight
let (fee_asset, weight_limit) = T::worst_case_buy_execution()?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I definitely like the idea of benchmarking with WeightLimit::Limited so we can hit more logic. There's now a fee_asset configuration item that is used to buying execution in the benchmark for refund_surplus, this could be merged with that to include the weight_limit.

We also have to make sure this is in holding, don't know if there's a good way to do it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok I can try to do this!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For holding, yes we rely on worst_case_holding having the fees, and I guess that if it is not the benchmark will fail. So I think this is good enough.

The other way we could do it is by injecting the fee_asset into holding directly, without using worst_case_holding at all

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@franciscoaguirre I dont see the fee_asset setup in refund_surplus. all I see is that the total_surplus is artificially set

executor.set_total_surplus(Weight::from_parts(1337, 1337));

/// asset to trigger the Trader::buy_execution in the XCM executor
/// By default returns ((AssetId(Here.into()), 100_000_000u128), Unlimited)
fn worst_case_buy_execution() -> Result<(Asset, WeightLimit), BenchmarkError> {
Ok(((AssetId(Junctions::Here.into()), 100_000_000u128).into(), WeightLimit::Unlimited))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we need a default for this. More often than not the worst case is Limited and we have many examples that don't buy fees with Here

Copy link
Copy Markdown
Contributor Author

@girazoki girazoki Jan 17, 2024

Choose a reason for hiding this comment

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

What should I configure in this PR for all the runtimes? Use the same values they had before? Because I dont think I know all the polkadot/cumulus runtimes as well to know what is the worst usecase for each of them..

@girazoki
Copy link
Copy Markdown
Contributor Author

girazoki commented Feb 8, 2024

@franciscoaguirre do you have any more input on this? If I dont provide the default implementation I dont think I know enough of the runtimes myself to implement the worst case scenario in each of the cumulus/relay runtimes

@paritytech-cicd-pr
Copy link
Copy Markdown

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: cargo-clippy
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5265397

@RomarQ
Copy link
Copy Markdown
Contributor

RomarQ commented Mar 17, 2025

@girazoki is this still applicable?

@acatangiu
Copy link
Copy Markdown
Contributor

Closing as stale, please reopen if needed.

@acatangiu acatangiu closed this Mar 17, 2025
@girazoki
Copy link
Copy Markdown
Contributor Author

I think it is still aplicable, I willl open a new PR.

@girazoki
Copy link
Copy Markdown
Contributor Author

Sorry that I forgot about this and it became stale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants