Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmark for new_session hook #1016

Merged
merged 5 commits into from
Aug 22, 2024
Merged

Conversation

JesseAbram
Copy link
Member

Closes #1009

@JesseAbram JesseAbram marked this pull request as ready for review August 20, 2024 15:24
Copy link
Collaborator

@HCastano HCastano left a comment

Choose a reason for hiding this comment

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

Requesting changes because we really need to think about the impact of this.

I haven't been able to find any examples of implementations of SessionManager which deal with any weights. I only found one for NoteHistoricalRoot which doesn't deal with weights.

Do you have any other counter examples here? Otherwise I would just leave this out tbh

Comment on lines 616 to 619
frame_system::Pallet::<T>::register_extra_weight_unchecked(
result_weight.expect("Error unwraping non error value"),
DispatchClass::Mandatory,
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems really risky to use. From the docs:

Even more dangerous is to note that this function does NOT take any action if the new sum of block weight is more than the block weight limit. This is what the unchecked.

This means we could stall the chain at a session boundary

@JesseAbram
Copy link
Member Author

JesseAbram commented Aug 20, 2024

Requesting changes because we really need to think about the impact of this.

I haven't been able to find any examples of implementations of SessionManager which deal with any weights. I only found one for NoteHistoricalRoot which doesn't deal with weights.

Do you have any other counter examples here? Otherwise I would just leave this out tbh

ya, used it before in statemine, in the collator selection pallet, if we don't do weights here on session change we would have larger blocks we can add an if statment for the max weight of a block and be like hey don't add the weight if it is greater then a max block weight and have a larger block instead of a chain stall

https://github.com/paritytech/polkadot-sdk/blob/717bbb24c40717e70d2e3b648bcd372559c71bd2/cumulus/pallets/collator-selection/src/lib.rs#L974

@HCastano HCastano changed the title Benchmark for new session Add benchmark for new_session hook Aug 20, 2024
Copy link
Contributor

@ameba23 ameba23 left a comment

Choose a reason for hiding this comment

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

Im leaving this as a comment so that @HCastano gets the say on this. I would need you to sit on a call and talk me through this to really get it.

But the fact that the same thing has been done in another pallet which has presumably been audited makes me think its probably fine.

* Format benchmarking code

* Update `*_less_then_signers` bench to scale signers in storage

Since we end up reading from this storage vec we want to make sure it is populated with up to
`MAX_SIGNERS` for the purposes of benchmarking.

* Change benchmarking for session handler to only use two benches

We add an extra storage read each time, but we can simplify the benchmarking a bit

* Always update session weight

If the signer length was more than the total signers we wouldn't
update the session weight, even though we would still do a few
storage operations.

* Remove `expect` by using `match` statement

* Remove unused `new_session_not_adding_new_signer` bench

* Update the name for one of the benches

* Update benchmark results

* Add missing parameter to base bench
@JesseAbram JesseAbram merged commit 43123e7 into master Aug 22, 2024
8 checks passed
@JesseAbram JesseAbram deleted the benchmark-for-new-session branch August 22, 2024 14:53
ameba23 added a commit that referenced this pull request Aug 23, 2024
* master:
  Clean up registration related tests in `pallet-registry` (#1021)
  Remove `prune_registration` extrinsic (#1022)
  Add benchmark for `new_session` hook (#1016)
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.

Benchmarks for new_session and on_init in propagation repo
3 participants