Add setter configurable only for benchmarking or tests - #9668
Conversation
|
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 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. |
|
In many ways, this is a follow up to #9209 |
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.