Skip to content

Commit

Permalink
Benchmark Polkadot Claims Pallet (paritytech#876)
Browse files Browse the repository at this point in the history
* fix

* Starting to add benchmarks

* make compile

* add benchmarks

* Make work with Substrate master

* Bench validate unsigned

* back to polkadot master

* starting to add cli with feature flag

* more stuff

* Add to kusama

* Update Cargo.lock

* fix dev dep

* bump wasm builder

* Remove encode from keccak benchmark

* bump spec

* Add weight documentation

* Update Cargo.lock

* Update check_runtime.sh

* Update publish_draft_release.sh

* Update Cargo.lock

Co-authored-by: thiolliere <[email protected]>
  • Loading branch information
2 people authored and General-Beck committed Mar 19, 2020
1 parent 3d80ee5 commit c4004cf
Show file tree
Hide file tree
Showing 29 changed files with 4,203 additions and 4,143 deletions.
7,931 changes: 3,880 additions & 4,051 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ maintenance = { status = "actively-developed" }
[profile.release]
# Polkadot runtime requires unwinding.
panic = "unwind"

[features]
runtime-benchmarks=["cli/runtime-benchmarks"]
5 changes: 4 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ crate-type = ["cdylib", "rlib"]
log = "0.4.8"
futures = { version = "0.3.4", features = ["compat"] }
structopt = "0.3.8"
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
Expand All @@ -28,6 +27,8 @@ sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polka
service = { package = "polkadot-service", path = "../service", default-features = false }

tokio = { version = "0.2.10", features = ["rt-threaded"], optional = true }
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true }
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true }

wasm-bindgen = { version = "0.2.57", optional = true }
wasm-bindgen-futures = { version = "0.4.7", optional = true }
Expand All @@ -40,10 +41,12 @@ rocksdb = [ "service/rocksdb" ]
cli = [
"tokio",
"sc-cli",
"frame-benchmarking-cli",
"service/full-node",
]
browser = [
"wasm-bindgen",
"wasm-bindgen-futures",
"browser-utils",
]
runtime-benchmarks = ["service/runtime-benchmarks"]
7 changes: 7 additions & 0 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ pub enum Subcommand {
#[allow(missing_docs)]
#[structopt(name = "validation-worker", setting = structopt::clap::AppSettings::Hidden)]
ValidationWorker(ValidationWorkerCommand),

/// The custom benchmark subcommmand benchmarking runtime pallets.
#[structopt(
name = "benchmark",
about = "Benchmark runtime pallets."
)]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
}

#[allow(missing_docs)]
Expand Down
12 changes: 12 additions & 0 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ pub fn run(version: VersionInfo) -> sc_cli::Result<()> {
Ok(())
}
},
Some(Subcommand::Benchmark(cmd)) => {
cmd.init(&version)?;
cmd.update_config(&mut config, load_spec, &version)?;

let is_kusama = config.chain_spec.as_ref().map_or(false, |s| s.is_kusama());

if is_kusama {
cmd.run::<_, _, service::kusama_runtime::Block, service::KusamaExecutor>(config)
} else {
cmd.run::<_, _, service::polkadot_runtime::Block, service::PolkadotExecutor>(config)
}
},
}
}

Expand Down
4 changes: 2 additions & 2 deletions parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2018"
codec = { package = "parity-scale-codec", version = "1.1.0", default-features = false, features = [ "derive" ] }
derive_more = { version = "0.99.2", optional = true }
serde = { version = "1.0.102", default-features = false, features = [ "derive" ], optional = true }
rstd = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-std = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-wasm-interface = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
Expand All @@ -35,7 +35,7 @@ std = [
"codec/std",
"derive_more",
"serde/std",
"rstd/std",
"sp-std/std",
"shared_memory",
"sp-core/std",
"lazy_static",
Expand Down
6 changes: 3 additions & 3 deletions parachain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub mod wasm_executor;

mod wasm_api;

use rstd::vec::Vec;
use sp_std::vec::Vec;

use codec::{Encode, Decode, CompactAs};
use sp_core::{RuntimeDebug, TypeId};
Expand Down Expand Up @@ -117,7 +117,7 @@ impl Id {
pub fn is_system(&self) -> bool { self.0 < USER_INDEX_START }
}

impl rstd::ops::Add<u32> for Id {
impl sp_std::ops::Add<u32> for Id {
type Output = Self;

fn add(self, other: u32) -> Self {
Expand Down Expand Up @@ -192,7 +192,7 @@ pub enum ParachainDispatchOrigin {
Root,
}

impl rstd::convert::TryFrom<u8> for ParachainDispatchOrigin {
impl sp_std::convert::TryFrom<u8> for ParachainDispatchOrigin {
type Error = ();
fn try_from(x: u8) -> core::result::Result<ParachainDispatchOrigin, ()> {
const SIGNED: u8 = ParachainDispatchOrigin::Signed as u8;
Expand Down
2 changes: 1 addition & 1 deletion parachain/src/wasm_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub trait Parachain {
/// function's entry point.
#[cfg(not(feature = "std"))]
pub unsafe fn load_params(params: *const u8, len: usize) -> crate::ValidationParams {
let mut slice = rstd::slice::from_raw_parts(params, len);
let mut slice = sp_std::slice::from_raw_parts(params, len);

codec::Decode::decode(&mut slice).expect("Invalid input data")
}
Expand Down
4 changes: 2 additions & 2 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ inherents = { package = "sp-inherents", git = "https://github.com/paritytech/sub
application-crypto = { package = "sp-application-crypto", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
rstd = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-std = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
runtime_primitives = { package = "sp-runtime", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
polkadot-parachain = { path = "../parachain", default-features = false }
trie = { package = "sp-trie", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
Expand All @@ -31,7 +31,7 @@ std = [
"inherents/std",
"trie/std",
"sp-api/std",
"rstd/std",
"sp-std/std",
"sp-version/std",
"runtime_primitives/std",
"serde",
Expand Down
6 changes: 3 additions & 3 deletions primitives/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

//! Polkadot parachain types.
use rstd::prelude::*;
use rstd::cmp::Ordering;
use sp_std::prelude::*;
use sp_std::cmp::Ordering;
use parity_scale_codec::{Encode, Decode};
use bitvec::vec::BitVec;
use super::{Hash, Balance};
Expand Down Expand Up @@ -646,7 +646,7 @@ pub struct FeeSchedule {
impl FeeSchedule {
/// Compute the fee for a message of given size.
pub fn compute_fee(&self, n_bytes: usize) -> Balance {
use rstd::mem;
use sp_std::mem;
debug_assert!(mem::size_of::<Balance>() >= mem::size_of::<usize>());

let n_bytes = n_bytes as Balance;
Expand Down
10 changes: 6 additions & 4 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ serde_derive = { version = "1.0.102", optional = true }

sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
inherents = { package = "sp-inherents", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
rstd = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-std = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-staking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
Expand All @@ -28,14 +28,14 @@ staking = { package = "pallet-staking", git = "https://github.com/paritytech/sub
system = { package = "frame-system", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
timestamp = { package = "pallet-timestamp", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
vesting = { package = "pallet-vesting", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false, optional = true }

primitives = { package = "polkadot-primitives", path = "../../primitives", default-features = false }
polkadot-parachain = { path = "../../parachain", default-features = false }
libsecp256k1 = { version = "0.3.2", default-features = false, optional = true }

[dev-dependencies]
hex-literal = "0.2.1"
libsecp256k1 = "0.3.2"
tiny-keccak = "1.5.0"
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
babe = { package = "pallet-babe", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
Expand All @@ -44,6 +44,7 @@ pallet-staking-reward-curve = { git = "https://github.com/paritytech/substrate",
treasury = { package = "pallet-treasury", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
trie-db = "0.20.0"
serde_json = "1.0.41"
libsecp256k1 = "0.3.2"

[features]
default = []
Expand All @@ -57,7 +58,7 @@ std = [
"sp-core/std",
"polkadot-parachain/std",
"sp-api/std",
"rstd/std",
"sp-std/std",
"sp-io/std",
"frame-support/std",
"authorship/std",
Expand All @@ -73,3 +74,4 @@ std = [
"serde/std",
"log",
]
runtime-benchmarks = ["frame-benchmarking", "libsecp256k1"]
2 changes: 1 addition & 1 deletion runtime/common/src/attestations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! In the future, it is planned that this module will handle dispute resolution
//! as well.
use rstd::prelude::*;
use sp_std::prelude::*;
use codec::{Encode, Decode};
use frame_support::{
decl_storage, decl_module, decl_error, ensure, dispatch::DispatchResult, traits::Get
Expand Down
Loading

0 comments on commit c4004cf

Please sign in to comment.