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

Add setter configurable only for benchmarking or tests #9668

Merged

Conversation

girazoki
Copy link
Contributor

@girazoki girazoki commented Sep 1, 2021

This PR adds a setter for BlockNumberProvider if compiling with runtime-benchmarks features. This allows to write benchmarking that is independent to the BlockProvider used, as it allows to set the desired mocked block number.

This is a problem we have encountered in moonbeam-foundation/crowdloan-rewards#44 (cc @JoshOrndorff), where we want to write benchmark code that is agnostic of the block provider. But to benchmark correctly one of the extrinsics, we need to specifically set the block number in the block provider.

@cla-bot-2021
Copy link

cla-bot-2021 bot commented Sep 1, 2021

User @girazoki, please sign the CLA here.

@girazoki girazoki marked this pull request as ready for review September 1, 2021 08:47
@JoshOrndorff
Copy link
Contributor

JoshOrndorff commented Sep 1, 2021

Our crowdloan rewards pallet which @girazoki linked is responsible for paying tokens to a fixed set of users (crowdloan participants in our case). The tokens are not paid all at once, rather there is a linear vesting schedule. The pallet is generic over what block number is used for the vesting schedule. Concretely, we imagine users either vesting according to their own chain's native block number, or the relay chain's block number.

The worst-case weight for claiming a reward happens when the block number used for vesting is non-zero. (Because if it is zero, the amount due is zero and no transfer is actually made.) In our mock runtime we use the native block number from frame_system and it is trivial to set the block number with the set_block_number helper method or calling an individual pallet's on_initialize. This same practice is well precedented throughout frame benchmarks. For example here.

In the Moonbeam runtime, we use the relay chain block number for vesting. We would like our benchmarks to be re-useable over both block number configurations, thus we need a way to set the block number through the trait.

@girazoki girazoki changed the title Add setter configurable only fior benchmarking or tests Add setter configurable only for benchmarking or tests Sep 1, 2021
@JoshOrndorff
Copy link
Contributor

In many ways, this is a follow up to #9209

primitives/runtime/src/traits.rs Outdated Show resolved Hide resolved
@bkchr bkchr added A2-insubstantial Pull request requires no code review (e.g., a sub-repository hash update). 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. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Sep 8, 2021
@bkchr bkchr merged commit 267dac2 into paritytech:master Sep 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A2-insubstantial Pull request requires no code review (e.g., a sub-repository hash update). 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. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants