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:
Bastian Köcher
2020-02-19 10:22:36 +01:00
committed by GitHub
parent e50f610907
commit b4ebd41c21
25 changed files with 484 additions and 329 deletions
+3
View File
@@ -89,6 +89,7 @@ node-executor = { version = "2.0.0", path = "../executor" }
# CLI-specific dependencies
sc-cli = { version = "0.8.0", optional = true, path = "../../../client/cli" }
frame-benchmarking-cli = { version = "2.0.0", optional = true, path = "../../../utils/frame/benchmarking-cli" }
node-transaction-factory = { version = "0.8.0", optional = true, path = "../transaction-factory" }
node-inspect = { version = "0.8.0", optional = true, path = "../inspect" }
@@ -112,6 +113,7 @@ build-script-utils = { version = "2.0.0", package = "substrate-build-script-util
structopt = { version = "0.3.8", optional = true }
node-transaction-factory = { version = "0.8.0", optional = true, path = "../transaction-factory" }
node-inspect = { version = "0.8.0", optional = true, path = "../inspect" }
frame-benchmarking-cli = { version = "2.0.0", optional = true, path = "../../../utils/frame/benchmarking-cli" }
[build-dependencies.sc-cli]
version = "0.8.0"
@@ -135,6 +137,7 @@ cli = [
"node-inspect",
"node-transaction-factory",
"sc-cli",
"frame-benchmarking-cli",
"sc-service/rocksdb",
"structopt",
"vergen",
+7
View File
@@ -53,6 +53,13 @@ pub enum Subcommand {
about = "Decode given block or extrinsic using current native runtime."
)]
Inspect(node_inspect::cli::InspectCmd),
/// The custom benchmark subcommmand benchmarking runtime pallets.
#[structopt(
name = "benchmark",
about = "Benchmark runtime pallets."
)]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
}
/// The `factory` command used to generate transactions.
+6 -1
View File
@@ -43,12 +43,17 @@ where
cmd.init(&mut config, load_spec, &version)?;
let client = sc_service::new_full_client::<
node_runtime::Block,node_runtime::RuntimeApi, node_executor::Executor, _, _,
node_runtime::Block, node_runtime::RuntimeApi, node_executor::Executor, _, _,
>(&config)?;
let inspect = node_inspect::Inspector::<node_runtime::Block>::new(client);
cmd.run(inspect)
},
Some(Subcommand::Benchmark(cmd)) => {
cmd.init(&mut config, load_spec, &version)?;
cmd.run::<_, _, node_runtime::Block, node_executor::Executor>(config)
},
Some(Subcommand::Factory(cli_args)) => {
sc_cli::init(&cli_args.shared_params, &version)?;
sc_cli::init_config(&mut config, &cli_args.shared_params, &version, load_spec)?;
+1
View File
@@ -16,6 +16,7 @@ sp-io = { version = "2.0.0", path = "../../../primitives/io" }
sp-state-machine = { version = "0.8", path = "../../../primitives/state-machine" }
sp-trie = { version = "2.0.0", path = "../../../primitives/trie" }
trie-root = "0.16.0"
frame-benchmarking = { version = "2.0.0", path = "../../../frame/benchmarking" }
[dev-dependencies]
criterion = "0.3.0"
+1 -1
View File
@@ -26,5 +26,5 @@ native_executor_instance!(
pub Executor,
node_runtime::api::dispatch,
node_runtime::native_version,
sp_io::benchmarking::HostFunctions,
frame_benchmarking::benchmarking::HostFunctions,
);
+2
View File
@@ -33,6 +33,7 @@ sp-version = { version = "2.0.0", default-features = false, path = "../../../pri
# frame dependencies
frame-executive = { version = "2.0.0", default-features = false, path = "../../../frame/executive" }
frame-benchmarking = { version = "2.0.0", default-features = false, path = "../../../frame/benchmarking" }
frame-support = { version = "2.0.0", default-features = false, path = "../../../frame/support" }
frame-system = { version = "2.0.0", default-features = false, path = "../../../frame/system" }
frame-system-rpc-runtime-api = { version = "2.0.0", default-features = false, path = "../../../frame/system/rpc/runtime-api/" }
@@ -115,6 +116,7 @@ std = [
"sp-session/std",
"pallet-sudo/std",
"frame-support/std",
"frame-benchmarking/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
"pallet-timestamp/std",
+12 -16
View File
@@ -31,14 +31,13 @@ pub use node_primitives::{AccountId, Signature};
use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment};
use sp_api::impl_runtime_apis;
use sp_runtime::{
Permill, Perbill, Percent, ApplyExtrinsicResult, BenchmarkResults,
impl_opaque_keys, generic, create_runtime_str,
Permill, Perbill, Percent, ApplyExtrinsicResult, impl_opaque_keys, generic, create_runtime_str,
};
use sp_runtime::curve::PiecewiseLinear;
use sp_runtime::transaction_validity::TransactionValidity;
use sp_runtime::traits::{
self, BlakeTwo256, Block as BlockT, StaticLookup, SaturatedConversion,
ConvertInto, OpaqueKeys, Benchmarking,
ConvertInto, OpaqueKeys,
};
use sp_version::RuntimeVersion;
#[cfg(any(feature = "std", test))]
@@ -816,28 +815,25 @@ impl_runtime_apis! {
}
}
impl crate::Benchmark<Block> for Runtime {
fn dispatch_benchmark(module: Vec<u8>, extrinsic: Vec<u8>, steps: u32, repeat: u32)
-> Option<Vec<BenchmarkResults>>
{
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn dispatch_benchmark(
module: Vec<u8>,
extrinsic: Vec<u8>,
steps: u32,
repeat: u32,
) -> Option<Vec<frame_benchmarking::BenchmarkResults>> {
use frame_benchmarking::Benchmarking;
match module.as_slice() {
b"pallet-balances" | b"balances" => Balances::run_benchmark(extrinsic, steps, repeat).ok(),
b"pallet-identity" | b"identity" => Identity::run_benchmark(extrinsic, steps, repeat).ok(),
b"pallet-timestamp" | b"timestamp" => Timestamp::run_benchmark(extrinsic, steps, repeat).ok(),
_ => return None,
_ => None,
}
}
}
}
sp_api::decl_runtime_apis! {
pub trait Benchmark
{
fn dispatch_benchmark(module: Vec<u8>, extrinsic: Vec<u8>, steps: u32, repeat: u32)
-> Option<Vec<BenchmarkResults>>;
}
}
#[cfg(test)]
mod tests {
use super::*;