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

HRMP benchmarks #3876

Merged
merged 55 commits into from
Jan 21, 2022
Merged

HRMP benchmarks #3876

merged 55 commits into from
Jan 21, 2022

Conversation

kianenigma
Copy link
Contributor

@kianenigma kianenigma commented Sep 17, 2021

as you see, nothing is done, just opening a PR to signal that I will work on this and prevent overlap.

  • Weigh the background-like tasks, and make all of the inter-pallet calls self-weiging. Could be done in a follow-up. All dispatchables area already being weighed.

part of #3850

@kianenigma kianenigma changed the title WIP: HRMP benchmarks HRMP benchmarks Sep 20, 2021
@kianenigma kianenigma marked this pull request as ready for review September 20, 2021 17:25
runtime/kusama/src/lib.rs Outdated Show resolved Hide resolved
/// `hrmp_max_parathread_outbound_channels` can be set to.
///
/// This is used for benchmarking sanely bounding relevant storage items.
type HrmpMaxOutboundChannelsBound: Get<u32>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Long term, I don't think this patter is good. We probably will need to add a lot of bound types here, one for each field of HostConfigurations. I don't see it within the scope of this PR, but if we go down that road, it is probably worthwhile to abstract all of these types into one new type, maybe called struct HostConfigurationBounds and only use that to minimize the footprint in the interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, note that for simplicity, for now I have combined the parachain and parathread variant. This might help us use BoundedVec in some places as well, but that didn't work out.

@@ -1134,6 +1134,8 @@ impl parachains_origin::Config for Runtime {}

impl parachains_configuration::Config for Runtime {
type WeightInfo = weights::runtime_parachains_configuration::WeightInfo<Runtime>;
type HrmpMaxOutboundChannelsBound = ConstU32<128>;
type HrmpMaxInboundChannelsBound = ConstU32<128>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rather arbitrary numbers.

Copy link
Contributor

@pepyakin pepyakin left a comment

Choose a reason for hiding this comment

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

It looks fine, assuming the formatting changes will be reverted.

PS: For the future, I would really appreciate if a PR didn't include so much formatting. It complicates reviewing as it takes effort to see what actually requires attention.

runtime/parachains/src/hrmp.rs Outdated Show resolved Hide resolved
runtime/parachains/src/hrmp.rs Outdated Show resolved Hide resolved
runtime/parachains/src/hrmp.rs Outdated Show resolved Hide resolved
@kianenigma
Copy link
Contributor Author

kianenigma commented Sep 21, 2021

It looks fine, assuming the formatting changes will be reverted.

PS: For the future, I would really appreciate if a PR didn't include so much formatting. It complicates reviewing as it takes effort to see what actually requires attention.

Yeah, I am having some weird issues with cargo fmt: #3876 (comment).

Only ones that I did fix intentionally was that your comments were sometimes were not wrapped at 120 100. Only a handful, and should not make review that hard.

Copy link
Contributor

@pepyakin pepyakin left a comment

Choose a reason for hiding this comment

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

Ah, actually, I also assumed that comments underwent some kind of automatic formatting.

I am really sensitive about the line width and never go over 120. The ones you wrapped looked more like they were 100, which I believe is fine to do occasionally, if that improves reading experience. In some instances it is fine and I do not feel strongly, but in others (I mentioned them below) I do.

runtime/parachains/src/hrmp.rs Outdated Show resolved Hide resolved
runtime/parachains/src/hrmp.rs Outdated Show resolved Hide resolved
runtime/parachains/src/hrmp.rs Outdated Show resolved Hide resolved
@kianenigma
Copy link
Contributor Author

Ah, actually, I also assumed that comments underwent some kind of automatic formatting.

I am really sensitive about the line width and never go over 120. The ones you wrapped looked more like they were 100, which I believe is fine to do occasionally, if that improves reading experience. In some instances it is fine and I do not feel strongly, but in others (I mentioned them below) I do.

Fixed your feedbacks, indeed my fixings (which where done with a plugin, not manually) made a few things a bit unclear.

And indeed I try and enforce 100 where possible, what I said earlier about 120 was wrong.

Copy link
Contributor

@drahnr drahnr left a comment

Choose a reason for hiding this comment

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

Changes look reasonable to me, I did not do a deep dive on the parameterization logic of the actual benchmarking code.

Copy link
Contributor

@pepyakin pepyakin left a comment

Choose a reason for hiding this comment

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

A couple of fixes and good to go

runtime/parachains/src/hrmp.rs Outdated Show resolved Hide resolved
pub fn force_process_hrmp_open(origin: OriginFor<T>) -> DispatchResult {
///
/// Total number of opening channels must be provided as witness data of weighing.
#[pallet::weight(<T as Config>::WeightInfo::force_process_hrmp_open(*_channels))]
Copy link
Contributor

Choose a reason for hiding this comment

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

This appears to be not checked. Do you think this right? It also applies to other places above and below.

In any case, this looks weird for reviewers/auditors and as such required a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not checked because it is coming from root origin and it is assumed to be correct, but I could easily add that, but IMO it is just noise. It will clutter both the dispatch code and the error variant.

About the comment, if you look around Frame, this a pretty common patter, where some additional data needs to be passed to the dispatch, sometime not really used other than checked for correctness, just to measure the weight of some transaction ahead of time and have efficient pool processing. These are typically called "witness data".

@@ -1005,6 +1020,7 @@ pub mod pallet {
new: u32,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(new <= T::HrmpMaxOutboundChannelsBound::get(), Error::<T>::InvalidNewValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

ensuring the conditions in setters are now discouraged in favor of checking it centrally in fn check_consistency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I settled this in e22a79f, LMK what you think.

Copy link
Contributor

Choose a reason for hiding this comment

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

So, I will also change this in Ump? #3889

Copy link
Contributor

Choose a reason for hiding this comment

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

i missed your comment... ༼ ༎ຶ ෴ ༎ຶ༽

But that seems to be the same cases

// ingress channels to a single leaving parachain that need to be closed.
let i in 0 .. (<T as configuration::Config>::HrmpMaxInboundChannelsBound::get() - 1);
// egress channels to a single leaving parachain that need to be closed.
let e in 0 .. (<T as configuration::Config>::HrmpMaxOutboundChannelsBound::get() - 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just out of my inexperience: why do we check it for every variable and just not once for the bound const variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(if I have understood your question correctly:) We want the benchmarking machinery to tell us the dependency on i and e, for which you need to run the benchmark in a range of values for both i and e. The final outcome of this would be fn(i, e) -> weight.

Copy link
Contributor

Choose a reason for hiding this comment

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

But why do we want us to tell the dependency on those? i and e are constants anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

their upper bound is constant and we happen to use that here as well, If you see where T::WeightInfo::force_clean_hrmp is being called, these two parameters need to be provided (similar to the other comment, it is a root call and we expect root to give a proper estimate of the witness data)

let channel_id = HrmpChannelId { sender, recipient };
assert_ok!(Hrmp::<T>::hrmp_close_channel(sender_origin.clone().into(), channel_id));
if matches!(until, ParachainSetupStep::CloseRequested) {
// NOTE: this is just for expressiveness, otherwise the if-statement is 100% useless.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This function has an obvious code pattern which makes this comment superfluous. It does not harm though.

runtime/parachains/src/hrmp/benchmarking.rs Outdated Show resolved Hide resolved
runtime/parachains/src/hrmp/benchmarking.rs Outdated Show resolved Hide resolved
runtime/parachains/src/hrmp/benchmarking.rs Show resolved Hide resolved
from: u32,
to: u32,
until: ParachainSetupStep,
) -> [(ParaId, crate::Origin); 2]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: You probably know what I am going to say about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact I don't, enlighten me please.

Copy link
Contributor

@drahnr drahnr Jan 21, 2022

Choose a reason for hiding this comment

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

Use a tuple instead and/or define a helper struct :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the rationale? an array of two is perfectly fine in my opinion and practically synonym to a tuple of two in my head.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I assumed too much.

While I think an array of two is definitely uncommon in such cases, and by default I would expect a tuple in cases like this. However, I agree it's more or less synonymous (It seems a bit novel and I even like it a bit compared to a tuple, because you use different brackets for the outer and inner items)

I, however, meant to propose to use a struct instead of the array. The inner tuples are OK since they are at least typed. That has an advantage that you fix names in one place — at the declaration side compared to the each place (which promotes consistency). Names are a bit better in this setting compared to indices:

What's more clear to refer the recipient, a field named recipient or an element at index 1?

Copy link
Contributor

@emostov emostov left a comment

Choose a reason for hiding this comment

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

👍

/// Maximum number of HRMP outbound channels exceeded.
MaxHrmpOutboundChannelsExceeded,
/// Maximum number of HRMP inbound channels exceeded.
MaxHrmpInboundChannelsExceeded,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: mention the value for consistency with other similar variants?

@kianenigma
Copy link
Contributor Author

bot merge

@paritytech-processbot
Copy link

Waiting for commit status.

@paritytech-processbot paritytech-processbot bot merged commit 95581b8 into master Jan 21, 2022
@paritytech-processbot paritytech-processbot bot deleted the kiz-bench-hrmp branch January 21, 2022 13:42
@pepyakin pepyakin added B7-runtimenoteworthy and removed B0-silent Changes should not be mentioned in any release notes labels Jan 24, 2022
Wizdave97 pushed a commit to ComposableFi/polkadot that referenced this pull request Feb 3, 2022
* wip template for hrmp benchmarks

* add all of the benchmarks, first draft

* File was not saved :/

* cargo +nightly fmt

* Use configs

* add configs

* Fix rococo

* Final touches

* revert fmt changes, one last time

* Fix wrappings

* Fix a bunch of tests

* cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=kusama-dev --steps=50 --repeat=20 --pallet=runtime_parachains::hrmp --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/runtime_parachains_hrmp.rs

* add to westend

* actually use everything

* cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=runtime_parachains::hrmp --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/westend/src/weights/runtime_parachains_hrmp.rs

* Update runtime/parachains/src/hrmp.rs

Co-authored-by: Keith Yeung <[email protected]>

* use real weight in wnd

* reorg

* minor cleanup

* weigh some of the internal stuff as well

* cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=kusama-dev --steps=50 --repeat=20 --pallet=runtime_parachains::hrmp --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/runtime_parachains_hrmp.rs

* cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=runtime_parachains::hrmp --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/westend/src/weights/runtime_parachains_hrmp.rs

* add files

* Master.into()

* add validation

* fmt

* fmt

* final fixes

* all runtimes build

* undo formatting

* Update runtime/parachains/src/hrmp.rs

Co-authored-by: Zeke Mostov <[email protected]>

* non-controversial changes

* do it the parachain-way: use const instead of type configs for simplicity.

* borrow assert_storage_consistency_exhaustive

* move assert_storage_consistency_exhaustive to Pallet, so it can be reused for benchmarks as well.

* fix typo

Co-authored-by: Parity Bot <[email protected]>
Co-authored-by: Keith Yeung <[email protected]>
Co-authored-by: Sergey Shulepov <[email protected]>
Co-authored-by: Zeke Mostov <[email protected]>
@kianenigma kianenigma added D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited. and removed D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels Feb 14, 2022
@louismerlin louismerlin added D1-audited 👍 PR contains changes to critical logic that has been properly reviewed and externally audited. and removed D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited. labels Jun 27, 2022
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. 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.

8 participants