Add benchmarking pipeline to node-template (#7122)

This commit is contained in:
Shawn Tabrizi
2020-09-17 10:09:59 +02:00
committed by GitHub
parent 9aa8698cfc
commit ab97e94972
8 changed files with 91 additions and 13 deletions
+5
View File
@@ -3912,6 +3912,8 @@ dependencies = [
name = "node-template"
version = "2.0.0-rc6"
dependencies = [
"frame-benchmarking",
"frame-benchmarking-cli",
"jsonrpc-core",
"node-template-runtime",
"pallet-transaction-payment-rpc",
@@ -3945,10 +3947,13 @@ dependencies = [
name = "node-template-runtime"
version = "2.0.0-rc6"
dependencies = [
"frame-benchmarking",
"frame-executive",
"frame-support",
"frame-system",
"frame-system-benchmarking",
"frame-system-rpc-runtime-api",
"hex-literal",
"pallet-aura",
"pallet-balances",
"pallet-grandpa",
@@ -45,7 +45,17 @@ sc-basic-authorship = { version = "0.8.0-rc6", path = "../../../client/basic-aut
substrate-frame-rpc-system = { version = "2.0.0-rc6", path = "../../../utils/frame/rpc/system" }
pallet-transaction-payment-rpc = { version = "2.0.0-rc6", path = "../../../frame/transaction-payment/rpc/" }
# These dependencies are used for runtime benchmarking
frame-benchmarking = { version = "2.0.0-rc6", path = "../../../frame/benchmarking" }
frame-benchmarking-cli = { version = "2.0.0-rc6", path = "../../../utils/frame/benchmarking-cli" }
node-template-runtime = { version = "2.0.0-rc6", path = "../runtime" }
[build-dependencies]
substrate-build-script-utils = { version = "2.0.0-rc6", path = "../../../utils/build-script-utils" }
[features]
default = []
runtime-benchmarks = [
"node-template-runtime/runtime-benchmarks",
]
@@ -32,4 +32,8 @@ pub enum Subcommand {
/// Revert the chain to a previous state.
Revert(sc_cli::RevertCmd),
/// The custom benchmark subcommmand benchmarking runtime pallets.
#[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
}
@@ -15,12 +15,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::chain_spec;
use crate::{chain_spec, service};
use crate::cli::{Cli, Subcommand};
use crate::service;
use sc_cli::{SubstrateCli, RuntimeVersion, Role, ChainSpec};
use sc_service::PartialComponents;
use crate::service::new_partial;
use node_template_runtime::Block;
impl SubstrateCli for Cli {
fn impl_name() -> String {
@@ -75,7 +74,7 @@ pub fn run() -> sc_cli::Result<()> {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents { client, task_manager, import_queue, ..}
= new_partial(&config)?;
= service::new_partial(&config)?;
Ok((cmd.run(client, import_queue), task_manager))
})
},
@@ -83,7 +82,7 @@ pub fn run() -> sc_cli::Result<()> {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents { client, task_manager, ..}
= new_partial(&config)?;
= service::new_partial(&config)?;
Ok((cmd.run(client, config.database), task_manager))
})
},
@@ -91,7 +90,7 @@ pub fn run() -> sc_cli::Result<()> {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents { client, task_manager, ..}
= new_partial(&config)?;
= service::new_partial(&config)?;
Ok((cmd.run(client, config.chain_spec), task_manager))
})
},
@@ -99,7 +98,7 @@ pub fn run() -> sc_cli::Result<()> {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents { client, task_manager, import_queue, ..}
= new_partial(&config)?;
= service::new_partial(&config)?;
Ok((cmd.run(client, import_queue), task_manager))
})
},
@@ -111,10 +110,20 @@ pub fn run() -> sc_cli::Result<()> {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents { client, task_manager, backend, ..}
= new_partial(&config)?;
= service::new_partial(&config)?;
Ok((cmd.run(client, backend), task_manager))
})
},
Some(Subcommand::Benchmark(cmd)) => {
if cfg!(feature = "runtime-benchmarks") {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run::<Block, service::Executor>(config))
} else {
Err("Benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`.".into())
}
},
None => {
let runner = cli.create_runner(&cli.run)?;
runner.run_node_until_exit(|config| match config.role {
@@ -16,6 +16,7 @@ native_executor_instance!(
pub Executor,
node_template_runtime::api::dispatch,
node_template_runtime::native_version,
frame_benchmarking::benchmarking::HostFunctions,
);
type FullClient = sc_service::TFullClient<Block, RuntimeApi, Executor>;
+17 -2
View File
@@ -40,6 +40,11 @@ sp-version = { version = "2.0.0-rc6", default-features = false, path = "../../..
frame-system-rpc-runtime-api = { version = "2.0.0-rc6", default-features = false, path = "../../../frame/system/rpc/runtime-api/" }
pallet-transaction-payment-rpc-runtime-api = { version = "2.0.0-rc6", default-features = false, path = "../../../frame/transaction-payment/rpc/runtime-api/" }
# Used for runtime benchmarking
frame-benchmarking = { version = "2.0.0-rc6", default-features = false, path = "../../../frame/benchmarking", optional = true }
frame-system-benchmarking = { version = "2.0.0-rc6", default-features = false, path = "../../../frame/system/benchmarking", optional = true }
hex-literal = { version = "0.3.1", optional = true }
template = { version = "2.0.0-rc6", default-features = false, path = "../pallets/template", package = "pallet-template" }
[build-dependencies]
@@ -58,7 +63,7 @@ std = [
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-transaction-payment/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"serde",
"sp-api/std",
"sp-block-builder/std",
@@ -72,6 +77,16 @@ std = [
"sp-transaction-pool/std",
"sp-version/std",
"frame-system/std",
"frame-system-rpc-runtime-api/std",
"frame-system-rpc-runtime-api/std",
"template/std",
]
runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system-benchmarking",
"hex-literal",
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
]
@@ -440,4 +440,39 @@ impl_runtime_apis! {
TransactionPayment::query_info(uxt, len)
}
}
#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
use frame_system_benchmarking::Module as SystemBench;
impl frame_system_benchmarking::Trait for Runtime {}
let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
// Total Issuance
hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),
// Execution Phase
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),
// Event Count
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),
// System Events
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
];
let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
add_benchmark!(params, batches, pallet_balances, Balances);
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
}
}
}
+2 -3
View File
@@ -88,9 +88,8 @@ pub fn run() -> Result<()> {
runner.sync_run(|config| cmd.run::<Block, Executor>(config))
} else {
println!("Benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`.");
Ok(())
Err("Benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`.".into())
}
}
Some(Subcommand::Key(cmd)) => cmd.run(),