Skip to content

Commit

Permalink
Add benchmark overhead
Browse files Browse the repository at this point in the history
Remove seedling runtime
Update Virto runtime to match Kreivo
Add pallet_asset_tx_payment
  • Loading branch information
darkforest0202 authored and olanod committed Jul 11, 2023
1 parent d4ce364 commit 1df5667
Show file tree
Hide file tree
Showing 34 changed files with 2,116 additions and 3,559 deletions.
1,523 changes: 284 additions & 1,239 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ panic = 'unwind'
members = [
'node',
'runtime/virto',
'runtime/seedling',
'runtime/kreivo',
'virto-xcm-emulator',
]

exclude = [
'virto-xcm-emulator'
]
9 changes: 6 additions & 3 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ serde_json = "1.0.96"
# Local
virto-runtime = { path = "../runtime/virto"}
kreivo-runtime = { path = "../runtime/kreivo"}
seedling-runtime = { path = "../runtime/seedling"}
jsonrpsee = { version = "0.16.2", features = ["server"] }

# Substrate
Expand All @@ -49,19 +48,23 @@ sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polk
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
try-runtime-cli = { git = "https://github.com/paritytech/substrate", optional = true , branch = "polkadot-v0.9.43" }
sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
substrate-frame-rpc-system = { package = "substrate-frame-rpc-system", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
substrate-state-trie-migration-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
pallet-asset-tx-payment = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }

# Polkadot
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.43" }
Expand Down Expand Up @@ -96,9 +99,9 @@ polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "relea
[features]
default = []
runtime-benchmarks = [
"polkadot-cli/runtime-benchmarks",
"virto-runtime/runtime-benchmarks",
"kreivo-runtime/runtime-benchmarks"
"kreivo-runtime/runtime-benchmarks",
"polkadot-cli/runtime-benchmarks"
]
try-runtime = [
"virto-runtime/try-runtime",
Expand Down
170 changes: 170 additions & 0 deletions node/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
use std::{sync::Arc, time::Duration};

use codec::Encode;
use cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider;
use sc_client_api::BlockBackend;
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<kreivo_runtime::RuntimeApi> {
fn pallet(&self) -> &str {
"system"
}

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

fn build(&self, nonce: u32) -> Result<OpaqueExtrinsic, &'static str> {
use kreivo_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<virto_runtime::RuntimeApi> {
fn pallet(&self) -> &str {
"system"
}

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

fn build(&self, nonce: u32) -> Result<OpaqueExtrinsic, &'static str> {
use virto_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:?}"))?;

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

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

Ok(inherent_data)
}
1 change: 0 additions & 1 deletion node/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use sp_core::{Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};

pub mod kreivo;
pub mod seedling;
pub mod virto;

/// The default XCM version to set in genesis config.
Expand Down
Loading

0 comments on commit 1df5667

Please sign in to comment.