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

Add benchmark for balances #342

Merged
merged 5 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
61 changes: 60 additions & 1 deletion Cargo.lock

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

11 changes: 4 additions & 7 deletions bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ node-runtime = { path = "../runtime" }
node-inspect = { optional = true, path = "../inspect" }
node-transaction-factory = { optional = true, path = "../transaction-factory" }

# TODO benchmarking
#frame-benchmarking-cli = { optional = true, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }
# benchmarking
frame-benchmarking-cli = { optional = true, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }

sc-cli = { package = "darwinia-cli", optional = true, path = "../../../client/cli" }

Expand All @@ -125,9 +125,7 @@ structopt = { version = "0.3.8", optional = true }
vergen = { version = "3.0.4", optional =true }

build-script-utils = { package = "substrate-build-script-utils", git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }

# TODO benchmarking
#frame-benchmarking-cli = { optional = true, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }
frame-benchmarking-cli = { optional = true, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }

sc-cli = { package = "darwinia-cli", optional = true, path = "../../../client/cli" }

Expand All @@ -143,8 +141,7 @@ browser = [
"wasm-bindgen-futures",
]
cli = [
# TODO benchmarking
# "frame-benchmarking-cli",
"frame-benchmarking-cli",

"node-executor/wasmi-errno",
"node-inspect",
Expand Down
6 changes: 3 additions & 3 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use std::{
use grandpa_primitives::AuthorityId as GrandpaId;
use hex_literal::hex;
use node_runtime::{
constants::currency::*, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig as RingConfig, Block, ClaimsConfig,
ContractsConfig, CouncilConfig, EthBackingConfig, EthRelayConfig, GrandpaConfig, ImOnlineConfig, IndicesConfig,
KtonConfig, SessionConfig, SessionKeys, SocietyConfig, StakerStatus, StakingConfig, SudoConfig, SystemConfig,
constants::currency::*, AuthorityDiscoveryConfig, BabeConfig, Block, ClaimsConfig, ContractsConfig, CouncilConfig,
EthBackingConfig, EthRelayConfig, GrandpaConfig, ImOnlineConfig, IndicesConfig, KtonConfig, RingConfig,
SessionConfig, SessionKeys, SocietyConfig, StakerStatus, StakingConfig, SudoConfig, SystemConfig,
TechnicalCommitteeConfig, WASM_BINARY,
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
Expand Down
7 changes: 3 additions & 4 deletions bin/node/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ pub enum Subcommand {
about = "Decode given block or extrinsic using current native runtime."
)]
Inspect(node_inspect::cli::InspectCmd),
// TODO benchmarking
// /// The custom benchmark subcommmand benchmarking runtime pallets.
// #[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]
// Benchmark(frame_benchmarking_cli::BenchmarkCmd),
/// 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.
Expand Down
14 changes: 7 additions & 7 deletions bin/node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ where

cmd.run(inspect)
}
// TODO benchmarking
// Some(Subcommand::Benchmark(_cmd)) => {
// cmd.init(&version)?;
// cmd.update_config(&mut config, load_spec, &version)?;
//
// cmd.run::<_, _, node_runtime::Block, node_executor::Executor>(config)
// }
Some(Subcommand::Benchmark(cmd)) => {
cmd.init(&version)?;
cmd.update_config(&mut config, load_spec, &version)?;

cmd.run::<_, _, node_runtime::Block, node_executor::Executor>(config)?;
Ok(())
}
Some(Subcommand::Factory(cli_args)) => {
cli_args.shared_params.init(&version)?;
cli_args.shared_params.update_config(&mut config, load_spec, &version)?;
Expand Down
2 changes: 1 addition & 1 deletion bin/node/cli/src/factory_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl RuntimeAdapter for FactoryState<Number> {
sign::<Self>(
CheckedExtrinsic {
signed: Some((sender.clone(), extra)),
function: Call::Balances(RingCall::transfer(
function: Call::Ring(RingCall::transfer(
pallet_indices::address::Address::Id(destination.clone().into()),
(*amount).into(),
)),
Expand Down
6 changes: 2 additions & 4 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ sp-version = { default-features = false, git = "https://github.com/darwinia-netw
node-primitives = { default-features = false, path = "../primitives" }

# frame dependencies
# TODO benchmarking
#frame-benchmarking = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }
frame-benchmarking = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }
frame-executive = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }
frame-support = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }
frame-system = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }
Expand Down Expand Up @@ -88,8 +87,7 @@ std = [
"rustc-hex",
"serde",

# TODO benchmarking
# "frame-benchmarking/std",
"frame-benchmarking/std",
"frame-executive/std",
"frame-support/std",
"frame-system-rpc-runtime-api/std",
Expand Down
38 changes: 18 additions & 20 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ pub fn native_version() -> NativeVersion {
}
}

type Ring = Balances;

type NegativeImbalance = <Ring as Currency<AccountId>>::NegativeImbalance;

pub type DealWithFees = SplitTwoWays<
Expand Down Expand Up @@ -643,7 +641,7 @@ construct_runtime!(
EthBacking: pallet_eth_backing::{Module, Call, Storage, Config<T>, Event<T>},
EthRelay: pallet_eth_relay::{Module, Call, Storage, Config<T>, Event<T>},
Kton: pallet_kton::{Module, Call, Storage, Config<T>, Event<T>},
Balances: pallet_ring::{Module, Call, Storage, Config<T>, Event<T>},
Ring: pallet_ring::{Module, Call, Storage, Config<T>, Event<T>},
clearloop marked this conversation as resolved.
Show resolved Hide resolved
Staking: pallet_staking::{Module, Call, Storage, Config<T>, Event<T>},
Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},
Vesting: pallet_vesting::{Module, Call, Storage, Config<T>, Event<T>},
Expand Down Expand Up @@ -837,23 +835,23 @@ impl_runtime_apis! {
}

// TODO benchmarking
// impl frame_benchmarking::Benchmark<Block> for Runtime {
// fn dispatch_benchmark(
// module: Vec<u8>,
// extrinsic: Vec<u8>,
// steps: Vec<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(),
// _ => None,
// }
// }
// }
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn dispatch_benchmark(
module: Vec<u8>,
extrinsic: Vec<u8>,
steps: Vec<u32>,
repeat: u32,
) -> Option<Vec<frame_benchmarking::BenchmarkResults>> {
use frame_benchmarking::Benchmarking;

match module.as_slice() {
b"darwinia-ring" | b"ring" => Ring::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(),
_ => None,
}
}
}
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ rpassword = "4.0.1"
# github.com
sc-informant = { git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }
sp-panic-handler = { git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }
sc-cli = { git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }
sc-client-api = { git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }
sp-blockchain = { git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }
sc-network = { git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.3" }
Expand Down
17 changes: 17 additions & 0 deletions client/cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

//! Initialization errors.

use sc_cli::Error as ScError;

/// Result type alias for the CLI.
pub type Result<T> = std::result::Result<T, Error>;

Expand Down Expand Up @@ -68,3 +70,18 @@ impl std::error::Error for Error {
}
}
}

// Convert the Error of sc-cli
impl std::convert::From<ScError> for Error {
fn from(e: ScError) -> Error {
match e {
ScError::Io(e) => Error::Io(e),
ScError::Cli(e) => Error::Cli(e),
ScError::Service(e) => Error::Service(e),
ScError::Client(e) => Error::Client(e),
ScError::Input(e) => Error::Input(e),
ScError::InvalidListenMultiaddress => Error::InvalidListenMultiaddress,
ScError::Other(e) => Error::Other(e),
}
}
}
Loading