Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update benches, weights #208

Open
wants to merge 4 commits into
base: devnet
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ evm = { version = "0.41.1", default-features = false }
futures = "0.3.30"
hash-db = { version = "0.16.0", default-features = false }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
hex-literal = "0.4.1"
hex-literal = { version = "0.4.1", default-features = false }
impl-serde = { version = "0.4.0", default-features = false }
impl-trait-for-tuples = "0.2.1"
jsonrpsee = "0.22.5"
Expand Down
23 changes: 11 additions & 12 deletions node/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use std::{sync::Arc, time::Duration};

use parity_scale_codec::Encode;
// Substrate
use sc_cli::Result;
use sc_client_api::BlockBackend;
use sp_core::{ecdsa, Pair};
use sp_inherents::{InherentData, InherentDataProvider};
Expand All @@ -32,18 +31,17 @@ use sp_runtime::{generic::Era, OpaqueExtrinsic, SaturatedConversion};
use atleta_runtime::{self as runtime, AccountId, Balance, BalancesCall, SystemCall};
use fp_account::AccountId20;

use crate::client::Client;
use crate::service::FullClient;

/// Generates extrinsics for the `benchmark overhead` command.
/// Generates `System::Remark` extrinsics for the benchmarks.
///
/// Note: Should only be used for benchmarking.
pub struct RemarkBuilder {
client: Arc<Client>,
client: Arc<FullClient>,
}

impl RemarkBuilder {
/// Creates a new [`Self`] from the given client.
pub fn new(client: Arc<Client>) -> Self {
pub fn new(client: Arc<FullClient>) -> Self {
Self { client }
}
}
Expand Down Expand Up @@ -75,14 +73,14 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for RemarkBuilder {
///
/// Note: Should only be used for benchmarking.
pub struct TransferKeepAliveBuilder {
client: Arc<Client>,
client: Arc<FullClient>,
dest: AccountId,
value: Balance,
}

impl TransferKeepAliveBuilder {
/// Creates a new [`Self`] from the given client.
pub fn new(client: Arc<Client>, dest: AccountId, value: Balance) -> Self {
pub fn new(client: Arc<FullClient>, dest: AccountId, value: Balance) -> Self {
Self { client, dest, value }
}
}
Expand Down Expand Up @@ -114,7 +112,7 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for TransferKeepAliveBuilder {
///
/// Note: Should only be used for benchmarking.
pub fn create_benchmark_extrinsic(
client: &Client,
client: &FullClient,
sender: ecdsa::Pair,
call: runtime::RuntimeCall,
nonce: u32,
Expand Down Expand Up @@ -168,13 +166,14 @@ pub fn create_benchmark_extrinsic(
/// Generates inherent data for the `benchmark overhead` command.
///
/// Note: Should only be used for benchmarking.
pub fn inherent_benchmark_data() -> Result<InherentData> {
pub fn benchmark_inherent_data(
header: polkadot_core_primitives::Header,
) -> Result<InherentData, sp_inherents::Error> {
let mut inherent_data = InherentData::new();
let d = Duration::from_millis(0);
let timestamp = sp_timestamp::InherentDataProvider::new(d.into());

futures::executor::block_on(timestamp.provide_inherent_data(&mut inherent_data))
.map_err(|e| format!("creating inherent data: {:?}", e))?;
futures::executor::block_on(timestamp.provide_inherent_data(&mut inherent_data))?;

let para_data = polkadot_primitives::InherentData {
bitfields: Vec::new(),
Expand Down
81 changes: 52 additions & 29 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use sc_cli::SubstrateCli;
use sc_service::DatabaseSource;
// Frontier
pub use crate::error::Error;
// use sc_cli::Error;
use fc_db::kv::frontier_database_dir;
use polkadot_service::OverseerGen;
use std::net::ToSocketAddrs;
Expand Down Expand Up @@ -267,50 +266,74 @@ pub fn run() -> Result<()> {
},
#[cfg(feature = "runtime-benchmarks")]
Some(Subcommand::Benchmark(cmd)) => {
use crate::benchmarking::{
inherent_benchmark_data, RemarkBuilder, TransferKeepAliveBuilder,
};
// use crate::benchmarking::{
// inherent_benchmark_data, RemarkBuilder, TransferKeepAliveBuilder,
// };
use atleta_runtime::{Block, ExistentialDeposit};
use frame_benchmarking_cli::{
BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE,
};

let runner = cli.create_runner(cmd)?;
match cmd {
BenchmarkCmd::Pallet(cmd) => runner
.sync_run(|config| cmd.run_with_spec::<Block, ()>(Some(config.chain_spec))),
BenchmarkCmd::Pallet(cmd) => runner.sync_run(|config| {
cmd.run_with_spec::<sp_runtime::traits::HashingFor<Block>, ()>(Some(
config.chain_spec,
))
.map_err(|e| Error::SubstrateCli(e))
}),
BenchmarkCmd::Block(cmd) => runner.sync_run(|mut config| {
let (client, _, _, _, _) = service::new_chain_ops(&mut config, &cli.eth)?;
cmd.run(client)
cmd.run(client.clone()).map_err(Error::SubstrateCli)
}),
BenchmarkCmd::Extrinsic(_) | BenchmarkCmd::Overhead(_) => {
runner.sync_run(|mut config| {
let (client, _, _, _, _) = service::new_chain_ops(&mut config, &cli.eth)?;
let header = client.header(client.info().genesis_hash).unwrap().unwrap();
let inherent_data = benchmark_inherent_data(header)
.map_err(|e| format!("generating inherent data: {:?}", e))?;
let remark_builder = RemarkBuilder::new(client.clone());

match cmd {
BenchmarkCmd::Extrinsic(cmd) => {
let tka_builder = TransferKeepAliveBuilder::new(
client.clone(),
get_account_id_from_seed::<sp_core::ecdsa::Public>("Alice"),
ExistentialDeposit::get(),
);

let ext_factory = ExtrinsicFactory(vec![
Box::new(remark_builder),
Box::new(tka_builder),
]);

cmd.run(client.clone(), inherent_data, Vec::new(), &ext_factory)
.map_err(Error::SubstrateCli)
},
BenchmarkCmd::Overhead(cmd) => cmd
.run(
config,
client.clone(),
inherent_data,
Vec::new(),
&remark_builder,
)
.map_err(Error::SubstrateCli),
_ => unreachable!("Ensured by the outside match; qed"),
}
})
},
BenchmarkCmd::Storage(cmd) => runner.sync_run(|mut config| {
let (client, backend, _, _, _) = service::new_chain_ops(&mut config, &cli.eth)?;
let db = backend.expose_db();
let storage = backend.expose_storage();
cmd.run(config, client, db, storage)

cmd.run(config, client.clone(), db, storage).map_err(Error::SubstrateCli)
}),
BenchmarkCmd::Overhead(cmd) => runner.sync_run(|mut config| {
let (client, _, _, _, _) = service::new_chain_ops(&mut config, &cli.eth)?;
let ext_builder = RemarkBuilder::new(client.clone());
cmd.run(config, client, inherent_benchmark_data()?, Vec::new(), &ext_builder)
BenchmarkCmd::Machine(cmd) => runner.sync_run(|config| {
cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone())
.map_err(Error::SubstrateCli)
}),
BenchmarkCmd::Extrinsic(cmd) => runner.sync_run(|mut config| {
let (client, _, _, _, _) = service::new_chain_ops(&mut config, &cli.eth)?;
// Register the *Remark* and *TKA* builders.
let ext_factory = ExtrinsicFactory(vec![
Box::new(RemarkBuilder::new(client.clone())),
Box::new(TransferKeepAliveBuilder::new(
client.clone(),
get_account_id_from_seed::<sp_core::ecdsa::Public>("Alice"),
ExistentialDeposit::get(),
)),
]);

cmd.run(client, inherent_benchmark_data()?, Vec::new(), &ext_factory)
}),
BenchmarkCmd::Machine(cmd) => {
runner.sync_run(|config| cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()))
},
}
},
#[cfg(not(feature = "runtime-benchmarks"))]
Expand Down
2 changes: 1 addition & 1 deletion node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#![warn(missing_docs)]
#![allow(clippy::type_complexity, clippy::too_many_arguments, clippy::large_enum_variant)]
#![cfg_attr(feature = "runtime-benchmarks", deny(unused_crate_dependencies))]
// #![cfg_attr(feature = "runtime-benchmarks", deny(unused_crate_dependencies))]

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
Expand Down
15 changes: 14 additions & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"]
log = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
hex-literal = { workspace = true }
hex-literal = { workspace = true, optional = true }
static_assertions = "1.1"

# Substrate
Expand Down Expand Up @@ -285,20 +285,33 @@ std = [
"pallet-evm-precompile-preimage/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex-literal",
"pallet-babe/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-ethereum/runtime-benchmarks",
"pallet-evm/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"pallet-nomination-pools/runtime-benchmarks",
"pallet-hotfix-sufficients/runtime-benchmarks",
"pallet-offences-benchmarking",
"pallet-preimage/runtime-benchmarks",
"pallet-contracts/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"runtime-common/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
]
39 changes: 33 additions & 6 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#![recursion_limit = "512"]
#![allow(clippy::new_without_default, clippy::or_fun_call)]
#![allow(clippy::identity_op)]
#![cfg_attr(feature = "runtime-benchmarks", deny(unused_crate_dependencies))]
// #![cfg_attr(feature = "runtime-benchmarks", deny(unused_crate_dependencies))]

// Make the WASM binary available.
#[cfg(feature = "std")]
Expand Down Expand Up @@ -392,7 +392,7 @@ parameter_types! {

impl pallet_balances::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;
type WeightInfo = ();
type Balance = Balance;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
Expand Down Expand Up @@ -482,7 +482,7 @@ impl pallet_treasury::Config for Runtime {
type BalanceConverter = UnityAssetBalanceConversion;
type PayoutPeriod = PayoutSpendPeriod;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type BenchmarkHelper = benchmarks::TreasuryArguments;
}

// sudo
Expand Down Expand Up @@ -1795,12 +1795,15 @@ extern crate frame_benchmarking;
#[cfg(feature = "runtime-benchmarks")]
mod benches {
define_benchmarks!(
[frame_benchmarking, BaselineBench::<Runtime>]
[frame_system, SystemBench::<Runtime>]
[pallet_babe, Babe]
[pallet_balances, Balances]
[pallet_timestamp, Timestamp]
[pallet_multisig, Multisig]
[pallet_preimage, Preimage]
[pallet_scheduler, Scheduler]
[pallet_sudo, Sudo]
[pallet_timestamp, Timestamp]
[pallet_treasury, Treasury]
[pallet_utility, Utility]
[pallet_evm, EVM]
);
}
Expand Down Expand Up @@ -2602,6 +2605,7 @@ impl_runtime_apis! {
let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);

add_benchmarks!(params, batches);
add_benchmark!(params, batches, pallet_evm, PalletEvmBench::<Runtime>);
add_benchmark!(params, batches, pallet_hotfix_sufficients, PalletHotfixSufficientsBench::<Runtime>);

Expand Down Expand Up @@ -2631,6 +2635,29 @@ impl_runtime_apis! {
}
}

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarks {
use crate::AccountId;
use core::marker::PhantomData;
use frame_support::traits::Get;
use pallet_treasury::ArgumentsFactory as TreasuryArgumentsFactory;
use sp_core::{ConstU32, ConstU8};

pub struct TreasuryArguments<Parents = ConstU8<0>, ParaId = ConstU32<0>>(
PhantomData<(Parents, ParaId)>,
);

impl<Parents: Get<u8>, ParaId: Get<u32>> TreasuryArgumentsFactory<(), AccountId>
for TreasuryArguments<Parents, ParaId>
{
fn create_asset_kind(_seed: u32) -> () {}

fn create_beneficiary(seed: [u8; 32]) -> AccountId {
AccountId::from(seed)
}
}
}

#[cfg(test)]
mod tests {
use super::{Runtime, WeightPerGas};
Expand Down