Skip to content

Commit

Permalink
feat(overhead-benchmarks): overhead benchmarking #1095
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeCap08055 committed Mar 1, 2023
1 parent 508552d commit e6a5475
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 112 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ benchmarks-schemas:
benchmarks-stateful-storage:
./scripts/run_benchmark.sh -p stateful-storage

benchmarks-overhead:
./scripts/run_benchmark.sh -p overhead

.PHONY: docs
docs:
RUSTDOCFLAGS="--enable-index-page -Zunstable-options" cargo doc --no-deps --features frequency
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 26 additions & 8 deletions node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ common-primitives = { default-features = false, path = "../../common/primitives"
common-runtime = { package = "common-runtime", path = "../../runtime/common", default-features = false }
frequency-runtime = { package = "frequency-runtime", path = "../../runtime/frequency", default-features = false }
frequency-service = { package = "frequency-service", path = "../service", default-features = false, optional = true }
pallet-msa = { package = "pallet-msa", path = "../../pallets/msa", default-features = false, optional = true }
pallet-msa = { package = "pallet-msa", path = "../../pallets/msa", default-features = false }
# Substrate
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.36" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.36" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.36" }
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.36" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.36" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }
sc-cli = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.36" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sc-service = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.36" }
Expand All @@ -51,18 +51,36 @@ polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "r
cumulus-client-cli = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" }
cumulus-client-service = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" }
cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.36" }

[build-dependencies]
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }

[features]
std = ["sp-api/std"]
cli = ["frequency-service", "sp-core", "sc-cli", "sc-service", "frame-benchmarking-cli", "try-runtime-cli"]
cli = [
"frequency-service",
"sp-core",
"sc-cli",
"sc-service",
"frame-benchmarking-cli",
"try-runtime-cli"
]
default = ["std", "cli"]
runtime-benchmarks = ["polkadot-cli/runtime-benchmarks", "pallet-msa/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-transaction-payment"]
runtime-benchmarks = [
"polkadot-cli/runtime-benchmarks",
"frequency-runtime/runtime-benchmarks",
"frame-benchmarking-cli/runtime-benchmarks"
]
try-runtime = ["frequency-service/try-runtime", "try-runtime-cli", "try-runtime-cli/try-runtime"]
on-chain-release-build = ["sp-api/disable-logging"]
frequency = ["frequency-service/frequency"]
frequency-rococo-local = ["frequency-service/frequency-rococo-local"]
frequency-rococo-testnet = ["frequency-service/frequency-rococo-testnet"]
all-frequency-features = ["frequency", "frequency-rococo-local", "frequency-rococo-testnet", "frequency-service/all-frequency-features"]
all-frequency-features = [
"frequency",
"frequency-rococo-local",
"frequency-rococo-testnet",
"frequency-service/all-frequency-features"
]

28 changes: 19 additions & 9 deletions node/cli/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
//! Should only be used for benchmarking as it may break in other contexts.

use common_primitives::node::{AccountId, Balance, Signature};
use frame_support::pallet_prelude::InherentData;
use frame_system::{Call as SystemCall, Config};
use frequency_service::service::{frequency_runtime as runtime, ParachainClient as FullClient};
// use runtime::{AccountId, Balance, BalancesCall, SystemCall};
use frame_support::pallet_prelude::InherentData;
use sc_cli::Result;
use sc_client_api::BlockBackend;
use sp_core::{Encode, Pair};
Expand All @@ -16,7 +15,7 @@ use sp_runtime::{OpaqueExtrinsic, SaturatedConversion};
use pallet_balances::Call as BalancesCall;
use pallet_msa;
use pallet_transaction_payment;
use sp_inherents;
use sp_inherents::InherentDataProvider;
use sp_timestamp;
use std::{sync::Arc, time::Duration};

Expand Down Expand Up @@ -164,13 +163,24 @@ pub fn inherent_benchmark_data() -> Result<InherentData> {
let mut inherent_data = InherentData::new();
let d = Duration::from_millis(0);
let timestamp = sp_timestamp::InherentDataProvider::new(d.into());

let mock_para_inherent_provider =
cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider {
current_para_block: 0,
relay_offset: 1,
relay_blocks_per_para_block: 2,
xcm_config: Default::default(),
raw_downward_messages: Default::default(),
raw_horizontal_messages: Default::default(),
para_blocks_per_relay_epoch: 2,
relay_randomness_config: (),
};

futures::executor::block_on(timestamp.provide_inherent_data(&mut inherent_data))
.map_err(|e| format!("creating inherent data: {:?}", e))?;
futures::executor::block_on(
<sp_timestamp::InherentDataProvider as sp_inherents::InherentDataProvider>::provide_inherent_data(
&timestamp,
&mut inherent_data,
),
mock_para_inherent_provider.provide_inherent_data(&mut inherent_data),
)
.map_err(|e| format!("creating inherent data: {:?}", e))?;
.map_err(|e| format!("creating cumulus inherent data: {:?}", e))?;

Ok(inherent_data)
}
10 changes: 0 additions & 10 deletions node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use cumulus_primitives_core::ParaId;
use frame_benchmarking_cli::BenchmarkCmd;
use log::info;

#[cfg(feature = "runtime-benchmarks")]
use crate::benchmarking::{inherent_benchmark_data, RemarkBuilder};
use common_primitives::node::Block;
use frequency_service::{
Expand Down Expand Up @@ -332,7 +331,6 @@ pub fn run() -> Result<()> {

cmd.run(config, partials.client.clone(), db, storage)
}),
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Overhead(cmd) => runner.sync_run(|config| {
let partials = new_partial(&config, false)?;
let ext_builder = RemarkBuilder::new(partials.client.clone());
Expand All @@ -345,14 +343,6 @@ pub fn run() -> Result<()> {
&ext_builder,
)
}),
#[cfg(not(feature = "runtime-benchmarks"))]
BenchmarkCmd::Overhead(_) =>
return Err(sc_cli::Error::Input(
"Compile with --features=runtime-benchmarks \
to enable overhead benchmarks."
.into(),
)
.into()),
BenchmarkCmd::Machine(cmd) => runner.sync_run(|config| {
cmd.run(&config, frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE.clone())
}),
Expand Down
4 changes: 2 additions & 2 deletions node/cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Frequency CLI library.

#![allow(missing_docs)]
#[cfg(feature = "runtime-benchmarks")]
#[cfg(feature = "cli")]
mod benchmarking;

#[cfg(feature = "cli")]
Expand All @@ -16,7 +16,7 @@ mod export_metadata_cmd;
#[cfg(feature = "cli")]
mod runtime_version_cmd;

#[cfg(feature = "runtime-behchmarks")]
#[cfg(feature = "cli")]
pub use benchmarking::*;

#[cfg(feature = "cli")]
Expand Down
1 change: 1 addition & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ frame-support = { git = "https://github.com/paritytech/substrate", default-featu
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }
sp-weights = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }
# Substrate pallets
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }
pallet-collective = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" }
Expand Down
3 changes: 1 addition & 2 deletions runtime/common/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ pub mod pallet_timestamp;
pub mod pallet_treasury;
pub mod pallet_utility;

pub use block_weights::constants::BlockExecutionWeight;
pub use extrinsic_weights::constants::ExtrinsicBaseWeight;
pub use frame_support::weights::constants::{BlockExecutionWeight, ExtrinsicBaseWeight};
Loading

0 comments on commit e6a5475

Please sign in to comment.