Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
[#210] Add overhead benchmarks to Trappist node
Browse files Browse the repository at this point in the history
  • Loading branch information
kalaninja committed Jun 7, 2023
1 parent f3d6d9c commit f7c1311
Show file tree
Hide file tree
Showing 11 changed files with 395 additions and 177 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

29 changes: 15 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[workspace]
members = [
"node",
"runtime/stout",
"runtime/trappist",
"primitives/xcm",
"node",
"runtime/stout",
"runtime/trappist",
"primitives/xcm",
]
exclude = [
"contracts",
"xcm-simulator"
"contracts",
"xcm-simulator"
]

[profile.release]
Expand All @@ -32,15 +32,15 @@ license = "Apache License v2"
async-trait = "0.1.57"
clap = { version = "4.0.32" }
parity-scale-codec = { version = "3.0.0", default-features = false, features = ["derive"] }
futures = { version = "0.3.25"}
hex-literal = { version = "0.3.4"}
log = { version = "0.4.17"}
futures = { version = "0.3.25" }
hex-literal = { version = "0.3.4" }
log = { version = "0.4.17" }
serde = { version = "1.0.152" }
scale-info = { version = "2.3.1", default-features = false, features = ["derive"] }
smallvec = "1.9.0"

# Local dependencies
trappist-runtime = { path = "runtime/trappist"}
trappist-runtime = { path = "runtime/trappist" }
stout-runtime = { path = "runtime/stout" }
jsonrpsee = { version = "0.16.2" }

Expand All @@ -57,7 +57,7 @@ pallet-lockdown-mode = { version = "0.1.0", default-features = false, path = "pa

# Substrate std
try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37"}
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
frame-rpc-system = { package = "substrate-frame-rpc-system", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37", default-features = false }
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
Expand All @@ -76,9 +76,10 @@ sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkad
sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-serializer = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37"}
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-serializer = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
substrate-state-trie-migration-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37"}
substrate-state-trie-migration-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }

# Substrate non-std
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37", default-features = false }
Expand Down Expand Up @@ -138,7 +139,7 @@ pallet-utility = { git = "https://github.com/paritytech/substrate", default-feat
pallet-treasury = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.37" }

# Cumulus client dependencies
cumulus-client-cli ={ git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-client-cli = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-client-consensus-aura = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-client-consensus-relay-chain = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-client-consensus-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
Expand Down
36 changes: 20 additions & 16 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ path = "src/main.rs"
[dependencies]
async-trait = { workspace = true }
clap = { workspace = true }
parity-scale-codec = { workspace = true }
parity-scale-codec = { workspace = true }
futures = { workspace = true }
hex-literal = { workspace = true }
log = { workspace = true }
Expand All @@ -34,57 +34,61 @@ jsonrpsee = { workspace = true, features = ["server"] }
pallet-dex-rpc = { workspace = true }

# Substrate
frame-benchmarking = { workspace = true, features = [ "std" ] }
frame-benchmarking = { workspace = true, features = ["std"] }
frame-benchmarking-cli = { workspace = true }
sp-runtime = { workspace = true }
sp-io = { workspace = true, features = [ "std" ] }
sp-core = { workspace = true, features = [ "std" ] }
sp-io = { workspace = true, features = ["std"] }
sp-core = { workspace = true, features = ["std"] }
sp-consensus = { workspace = true }
sp-session = { workspace = true, features = [ "std" ] }
sp-session = { workspace = true, features = ["std"] }
sc-consensus = { workspace = true }
sc-cli = { workspace = true }
sc-client-api = { workspace = true }
sc-executor = { workspace = true }
sc-service = { workspace = true }
sc-telemetry = { workspace = true }
sc-transaction-pool = { workspace = true }
sp-transaction-pool = { workspace = true, features = [ "std" ] }
sp-transaction-pool = { workspace = true, features = ["std"] }
sc-network = { workspace = true }
sc-network-common = { workspace = true }
sc-basic-authorship = { workspace = true }
sp-timestamp = { workspace = true, features = [ "std" ] }
sp-timestamp = { workspace = true, features = ["std"] }
sp-inherents = { workspace = true }
sp-blockchain = { workspace = true }
sp-block-builder = { workspace = true, features = [ "std" ] }
sp-keystore = { workspace = true, features = [ "std" ] }
sp-block-builder = { workspace = true, features = ["std"] }
sp-keyring = { workspace = true }
sp-keystore = { workspace = true, features = ["std"] }
sc-chain-spec = { workspace = true }
sc-rpc = { workspace = true }
sc-tracing = { workspace = true }
sp-offchain = { workspace = true, features = [ "std" ] }
sp-api = { workspace = true, features = [ "std" ] }
sp-consensus-aura = { workspace = true, features = [ "std" ] }
sp-offchain = { workspace = true, features = ["std"] }
sp-api = { workspace = true, features = ["std"] }
sp-consensus-aura = { workspace = true, features = ["std"] }
sc-sysinfo = { workspace = true }
sp-serializer = { workspace = true }
substrate-prometheus-endpoint = { workspace = true }
try-runtime-cli = { workspace = true, optional = true }
sc-transaction-pool-api = { workspace = true }
frame-system = { workspace = true }
frame-rpc-system = { workspace = true }
pallet-asset-tx-payment = { workspace = true }
pallet-transaction-payment-rpc = { workspace = true }
substrate-state-trie-migration-rpc = { workspace = true }

# Polkadot
polkadot-cli = { workspace = true }
polkadot-primitives = { workspace = true }
polkadot-service = { workspace = true }
xcm = { workspace = true, features = [ "std" ] }
xcm = { workspace = true, features = ["std"] }

# Cumulus
cumulus-client-cli ={ workspace = true }
cumulus-client-cli = { workspace = true }
cumulus-client-consensus-aura = { workspace = true }
cumulus-client-consensus-relay-chain = { workspace = true }
cumulus-client-consensus-common = { workspace = true }
cumulus-client-service = { workspace = true }
cumulus-client-network = { workspace = true }
cumulus-primitives-core = { workspace = true, features = [ "std" ] }
cumulus-primitives-core = { workspace = true, features = ["std"] }
cumulus-primitives-parachain-inherent = { workspace = true }
cumulus-relay-chain-interface = { workspace = true }

Expand All @@ -105,7 +109,7 @@ polkadot-cli = { workspace = true }
[features]
default = []
runtime-benchmarks = [
"trappist-runtime/runtime-benchmarks",
"trappist-runtime/runtime-benchmarks",
"stout-runtime/runtime-benchmarks",
"polkadot-cli/runtime-benchmarks"
]
Expand Down
160 changes: 160 additions & 0 deletions node/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
use parity_scale_codec::Encode;
use sc_client_api::BlockBackend;
use std::{sync::Arc, time::Duration};

use sp_core::Pair;
use sp_inherents::{InherentData, InherentDataProvider};
use sp_keyring::Sr25519Keyring;
use sp_runtime::{generic, OpaqueExtrinsic, SaturatedConversion};

use crate::service::ParachainClient;

/// Generates `System::Remark` extrinsics for the benchmarks.
///
/// Note: Should only be used for benchmarking.
pub struct RemarkBuilder<RuntimeApi> {
client: Arc<ParachainClient<RuntimeApi>>,
}

impl<RuntimeApi> RemarkBuilder<RuntimeApi> {
/// Creates a new [`Self`] from the given client.
pub fn new(client: Arc<ParachainClient<RuntimeApi>>) -> Self {
Self { client }
}
}

impl frame_benchmarking_cli::ExtrinsicBuilder for RemarkBuilder<trappist_runtime::RuntimeApi> {
fn pallet(&self) -> &str {
"system"
}

fn extrinsic(&self) -> &str {
"remark"
}

fn build(&self, nonce: u32) -> Result<OpaqueExtrinsic, &'static str> {
use trappist_runtime as runtime;

let call: runtime::RuntimeCall = runtime::SystemCall::remark { remark: vec![] }.into();
let period = runtime::BlockHashCount::get()
.checked_next_power_of_two()
.map(|c| c / 2)
.unwrap_or(2) as u64;
let best_block = self.client.chain_info().best_number;
let tip = 0;
let extra: runtime::SignedExtra = (
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
frame_system::CheckTxVersion::<runtime::Runtime>::new(),
frame_system::CheckGenesis::<runtime::Runtime>::new(),
frame_system::CheckEra::<runtime::Runtime>::from(generic::Era::mortal(
period,
best_block.saturated_into(),
)),
frame_system::CheckNonce::<runtime::Runtime>::from(nonce),
frame_system::CheckWeight::<runtime::Runtime>::new(),
pallet_asset_tx_payment::ChargeAssetTxPayment::<runtime::Runtime>::from(tip, None),
);

let genesis_hash = self.client.block_hash(0).ok().flatten().expect("Genesis block exists");
let best_hash = self.client.chain_info().best_hash;
let payload = runtime::SignedPayload::from_raw(
call.clone(),
extra.clone(),
(
(),
runtime::VERSION.spec_version,
runtime::VERSION.transaction_version,
genesis_hash,
best_hash,
(),
(),
(),
),
);

let sender = Sr25519Keyring::Bob.pair();
let signature = payload.using_encoded(|x| sender.sign(x));
let extrinsic = runtime::UncheckedExtrinsic::new_signed(
call,
sp_runtime::AccountId32::from(sender.public()).into(),
runtime::Signature::Sr25519(signature),
extra,
);

Ok(extrinsic.into())
}
}

impl frame_benchmarking_cli::ExtrinsicBuilder for RemarkBuilder<stout_runtime::RuntimeApi> {
fn pallet(&self) -> &str {
"system"
}

fn extrinsic(&self) -> &str {
"remark"
}

fn build(&self, nonce: u32) -> Result<OpaqueExtrinsic, &'static str> {
use stout_runtime as runtime;

let call: runtime::RuntimeCall = runtime::SystemCall::remark { remark: vec![] }.into();
let period = runtime::BlockHashCount::get()
.checked_next_power_of_two()
.map(|c| c / 2)
.unwrap_or(2) as u64;
let best_block = self.client.chain_info().best_number;
let tip = 0;
let extra: runtime::SignedExtra = (
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
frame_system::CheckTxVersion::<runtime::Runtime>::new(),
frame_system::CheckGenesis::<runtime::Runtime>::new(),
frame_system::CheckEra::<runtime::Runtime>::from(generic::Era::mortal(
period,
best_block.saturated_into(),
)),
frame_system::CheckNonce::<runtime::Runtime>::from(nonce),
frame_system::CheckWeight::<runtime::Runtime>::new(),
pallet_asset_tx_payment::ChargeAssetTxPayment::<runtime::Runtime>::from(tip, None),
);

let genesis_hash = self.client.block_hash(0).ok().flatten().expect("Genesis block exists");
let best_hash = self.client.chain_info().best_hash;
let payload = runtime::SignedPayload::from_raw(
call.clone(),
extra.clone(),
(
(),
runtime::VERSION.spec_version,
runtime::VERSION.transaction_version,
genesis_hash,
best_hash,
(),
(),
(),
),
);

let sender = Sr25519Keyring::Bob.pair();
let signature = payload.using_encoded(|x| sender.sign(x));
let extrinsic = runtime::UncheckedExtrinsic::new_signed(
call,
sp_runtime::AccountId32::from(sender.public()).into(),
runtime::Signature::Sr25519(signature),
extra,
);

Ok(extrinsic.into())
}
}

/// Generates inherent data for the `benchmark overhead` command.
pub fn inherent_benchmark_data() -> sc_cli::Result<InherentData> {
let mut inherent_data = InherentData::new();
let timestamp = sp_timestamp::InherentDataProvider::new(Duration::ZERO.into());

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

0 comments on commit f7c1311

Please sign in to comment.