Make pallet_session benchmarks generic over the staking solution #7522
+73
−25
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Current benchmarking code for pallet_session requires the runtime to implement pallet_staking from polkadot-dsk. It prevents registering and running benchmarks in runtimes that don't use that specific staking solution (like our project Tanssi).
This PR thus modifies the benchmarking code to add a
StakingAdapter
trait and associated type in pallet_session_benchmarkingConfig
trait. Implementors of this trait are responsible for calling the appropriate pallet. The benchmarking crate also include aPalletStaking
adapter that implementsStakingAdapter
to use pallet_staking like before.Integration
Downstream projects that using pallet_session_benchmarking needs to specify the adapter when implementing the
Config
trait. If they use pallet_staking, they can change the following code in thedispatch_benchmark
function of their runtime:impl pallet_session_benchmarking::Config for Runtime { + type StakingAdapter = pallet_session_benchmarking::PalletStaking<Runtime>; }
A project that doesn't use pallet_staking wouldn't have been able to use pallet_session_benchmarking in the first place. Now they can implement their own adapter that corresponds to their staking solution and setup pallet_session benchmarking.
Review Notes
pallet_session_benchmarking::Config
now has an associated typeStakingAdapter
that must implement traitpallet_session_benchmarking::StakingAdapter
, which contains various functions the benchmark needs to interact with the staking solution. Those functions are in a new trait + associated type to allow writing once the adapter instead of having to copy the function bodies in each runtime code. Adapter can be written once and used in multiple runtime (likePalletStaking
that will work for any runtime that use polkadot-sdk pallet_staking).Checklist
T
required)You can remove the "Checklist" section once all have been checked. Thank you for your contribution!