mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-29 21:41:03 +00:00
Consolidate frame benchmarking into a frame crate (#4977)
This prs cleans up some of the frame benchmarking stuff: - Move CLI into `frame-benchmarking-cli`. No frame related CLI should exists in the default Substrate CLI. - Move all traits and types related to frame benchmarking into the `frame-benchmarking` trait. Frame types should be isolated in Frame.
This commit is contained in:
@@ -26,7 +26,6 @@ use std::str::FromStr;
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Serialize, Deserialize, de::DeserializeOwned};
|
||||
use sp_core::{self, Hasher, Blake2Hasher, TypeId, RuntimeDebug};
|
||||
use crate::BenchmarkParameter;
|
||||
use crate::codec::{Codec, Encode, Decode};
|
||||
use crate::transaction_validity::{
|
||||
ValidTransaction, TransactionValidity, TransactionValidityError, UnknownTransaction,
|
||||
@@ -1318,75 +1317,6 @@ pub trait BlockIdTo<Block: self::Block> {
|
||||
) -> Result<Option<NumberFor<Block>>, Self::Error>;
|
||||
}
|
||||
|
||||
/// The pallet benchmarking trait.
|
||||
pub trait Benchmarking<T> {
|
||||
/// Run the benchmarks for this pallet.
|
||||
///
|
||||
/// Parameters
|
||||
/// - `extrinsic`: The name of extrinsic function you want to benchmark encoded as bytes.
|
||||
/// - `steps`: The number of sample points you want to take across the range of parameters.
|
||||
/// - `repeat`: The number of times you want to repeat a benchmark.
|
||||
fn run_benchmark(extrinsic: Vec<u8>, steps: u32, repeat: u32) -> Result<Vec<T>, &'static str>;
|
||||
}
|
||||
|
||||
/// The required setup for creating a benchmark.
|
||||
pub trait BenchmarkingSetup<T, Call, RawOrigin> {
|
||||
/// Return the components and their ranges which should be tested in this benchmark.
|
||||
fn components(&self) -> Vec<(BenchmarkParameter, u32, u32)>;
|
||||
|
||||
/// Set up the storage, and prepare a call and caller to test in a single run of the benchmark.
|
||||
fn instance(&self, components: &[(BenchmarkParameter, u32)]) -> Result<(Call, RawOrigin), &'static str>;
|
||||
}
|
||||
|
||||
/// Creates a `SelectedBenchmark` enum implementing `BenchmarkingSetup`.
|
||||
///
|
||||
/// Every variant must implement [`BenchmarkingSetup`](crate::traits::BenchmarkingSetup).
|
||||
///
|
||||
/// ```nocompile
|
||||
///
|
||||
/// struct Transfer;
|
||||
/// impl BenchmarkingSetup for Transfer { ... }
|
||||
///
|
||||
/// struct SetBalance;
|
||||
/// impl BenchmarkingSetup for SetBalance { ... }
|
||||
///
|
||||
/// selected_benchmark!(Transfer, SetBalance);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! selected_benchmark {
|
||||
($($bench:ident),*) => {
|
||||
// The list of available benchmarks for this pallet.
|
||||
enum SelectedBenchmark {
|
||||
$( $bench, )*
|
||||
}
|
||||
|
||||
// Allow us to select a benchmark from the list of available benchmarks.
|
||||
impl<T: Trait> $crate::traits::BenchmarkingSetup<T, Call<T>, RawOrigin<T::AccountId>> for SelectedBenchmark {
|
||||
fn components(&self) -> Vec<(BenchmarkParameter, u32, u32)> {
|
||||
match self {
|
||||
$( Self::$bench => <$bench as $crate::traits::BenchmarkingSetup<
|
||||
T,
|
||||
Call<T>,
|
||||
RawOrigin<T::AccountId>,
|
||||
>>::components(&$bench), )*
|
||||
}
|
||||
}
|
||||
|
||||
fn instance(&self, components: &[(BenchmarkParameter, u32)])
|
||||
-> Result<(Call<T>, RawOrigin<T::AccountId>), &'static str>
|
||||
{
|
||||
match self {
|
||||
$( Self::$bench => <$bench as $crate::traits::BenchmarkingSetup<
|
||||
T,
|
||||
Call<T>,
|
||||
RawOrigin<T::AccountId>,
|
||||
>>::instance(&$bench, components), )*
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user