mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 04:01:10 +00:00
Integrate benchmark-overhead command (#5137)
* Integrate benchmark-overhead command Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Beauty fix test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Spellcheck on Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Remove constants:: module Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update block+extrinsic weights Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Revert "Update block+extrinsic weights" This reverts commit d77bf977f6bca0b1ded35daa2fd54b97e18a67db. * Revert "Remove constants:: module" This reverts commit 2d3bcd0212c438f6b96755900a01762592d90265. * Review fixes Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Review fixes Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Review fixes Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Review fixes Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * CI Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: parity-processbot <>
This commit is contained in:
committed by
GitHub
parent
30dcadacdc
commit
c8cdf9fc03
@@ -6,7 +6,10 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
@@ -14,6 +17,10 @@ sp-storage = { git = "https://github.com/paritytech/substrate", branch = "master
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
@@ -37,7 +44,10 @@ kusama-runtime = { path = "../../runtime/kusama", optional = true }
|
||||
westend-runtime = { path = "../../runtime/westend", optional = true }
|
||||
rococo-runtime = { path = "../../runtime/rococo", optional = true }
|
||||
|
||||
polkadot-core-primitives = { path = "../../core-primitives" }
|
||||
polkadot-primitives = { path = "../../primitives" }
|
||||
polkadot-node-core-parachains-inherent = { path = "../core/parachains-inherent" }
|
||||
polkadot-runtime-common = { path = "../../runtime/common" }
|
||||
|
||||
[features]
|
||||
default = ["polkadot"]
|
||||
|
||||
@@ -24,13 +24,15 @@ use polkadot_primitives::v2::{
|
||||
};
|
||||
use sc_client_api::{AuxStore, Backend as BackendT, BlockchainEvents, KeyIterator, UsageProvider};
|
||||
use sc_executor::NativeElseWasmExecutor;
|
||||
use sp_api::{CallApiAt, NumberFor, ProvideRuntimeApi};
|
||||
use sp_api::{CallApiAt, Encode, NumberFor, ProvideRuntimeApi};
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sp_consensus::BlockStatus;
|
||||
use sp_core::Pair;
|
||||
use sp_keyring::Sr25519Keyring;
|
||||
use sp_runtime::{
|
||||
generic::{BlockId, SignedBlock},
|
||||
traits::{BlakeTwo256, Block as BlockT},
|
||||
Justifications,
|
||||
Justifications, OpaqueExtrinsic,
|
||||
};
|
||||
use sp_storage::{ChildInfo, StorageData, StorageKey};
|
||||
use std::sync::Arc;
|
||||
@@ -567,3 +569,222 @@ impl sp_blockchain::HeaderBackend<Block> for Client {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Provides a `SignedPayload` for any runtime.
|
||||
///
|
||||
/// Should only be used for benchmarking as it is not tested for regular usage.
|
||||
///
|
||||
/// The first code block should set up all variables that are needed to create the
|
||||
/// `SignedPayload`. The second block can make use of the `SignedPayload`.
|
||||
///
|
||||
/// This is not done as a trait function since the return type depends on the runtime.
|
||||
/// This macro therefore uses the same approach as [`with_client!`].
|
||||
macro_rules! with_signed_payload {
|
||||
{
|
||||
$self:ident,
|
||||
{
|
||||
$extra:ident,
|
||||
$client:ident,
|
||||
$raw_payload:ident
|
||||
},
|
||||
{
|
||||
$( $setup:tt )*
|
||||
},
|
||||
(
|
||||
$period:expr,
|
||||
$current_block:expr,
|
||||
$nonce:expr,
|
||||
$tip:expr,
|
||||
$call:expr,
|
||||
$genesis:expr
|
||||
),
|
||||
{
|
||||
$( $usage:tt )*
|
||||
}
|
||||
} => {
|
||||
match $self {
|
||||
#[cfg(feature = "polkadot")]
|
||||
Self::Polkadot($client) => {
|
||||
use polkadot_runtime as runtime;
|
||||
|
||||
$( $setup )*
|
||||
|
||||
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::CheckMortality::<runtime::Runtime>::from(sp_runtime::generic::Era::mortal(
|
||||
$period,
|
||||
$current_block,
|
||||
)),
|
||||
frame_system::CheckNonce::<runtime::Runtime>::from($nonce),
|
||||
frame_system::CheckWeight::<runtime::Runtime>::new(),
|
||||
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from($tip),
|
||||
polkadot_runtime_common::claims::PrevalidateAttests::<runtime::Runtime>::new(),
|
||||
);
|
||||
|
||||
let $raw_payload = runtime::SignedPayload::from_raw(
|
||||
$call.clone(),
|
||||
$extra.clone(),
|
||||
(
|
||||
(),
|
||||
runtime::VERSION.spec_version,
|
||||
runtime::VERSION.transaction_version,
|
||||
$genesis.clone(),
|
||||
$genesis,
|
||||
(),
|
||||
(),
|
||||
(),
|
||||
(),
|
||||
),
|
||||
);
|
||||
|
||||
$( $usage )*
|
||||
},
|
||||
#[cfg(feature = "westend")]
|
||||
Self::Westend($client) => {
|
||||
use westend_runtime as runtime;
|
||||
|
||||
$( $setup )*
|
||||
|
||||
signed_payload!($extra, $raw_payload,
|
||||
($period, $current_block, $nonce, $tip, $call, $genesis));
|
||||
|
||||
$( $usage )*
|
||||
},
|
||||
#[cfg(feature = "kusama")]
|
||||
Self::Kusama($client) => {
|
||||
use kusama_runtime as runtime;
|
||||
|
||||
$( $setup )*
|
||||
|
||||
signed_payload!($extra, $raw_payload,
|
||||
($period, $current_block, $nonce, $tip, $call, $genesis));
|
||||
|
||||
$( $usage )*
|
||||
},
|
||||
#[cfg(feature = "rococo")]
|
||||
Self::Rococo($client) => {
|
||||
use rococo_runtime as runtime;
|
||||
|
||||
$( $setup )*
|
||||
|
||||
signed_payload!($extra, $raw_payload,
|
||||
($period, $current_block, $nonce, $tip, $call, $genesis));
|
||||
|
||||
$( $usage )*
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Generates a `SignedPayload` for the Kusama, Westend and Rococo runtime.
|
||||
///
|
||||
/// Should only be used for benchmarking as it is not tested for regular usage.
|
||||
#[allow(unused_macros)]
|
||||
macro_rules! signed_payload {
|
||||
(
|
||||
$extra:ident, $raw_payload:ident,
|
||||
(
|
||||
$period:expr,
|
||||
$current_block:expr,
|
||||
$nonce:expr,
|
||||
$tip:expr,
|
||||
$call:expr,
|
||||
$genesis:expr
|
||||
)
|
||||
) => {
|
||||
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::CheckMortality::<runtime::Runtime>::from(
|
||||
sp_runtime::generic::Era::mortal($period, $current_block),
|
||||
),
|
||||
frame_system::CheckNonce::<runtime::Runtime>::from($nonce),
|
||||
frame_system::CheckWeight::<runtime::Runtime>::new(),
|
||||
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from($tip),
|
||||
);
|
||||
|
||||
let $raw_payload = runtime::SignedPayload::from_raw(
|
||||
$call.clone(),
|
||||
$extra.clone(),
|
||||
(
|
||||
(),
|
||||
runtime::VERSION.spec_version,
|
||||
runtime::VERSION.transaction_version,
|
||||
$genesis.clone(),
|
||||
$genesis,
|
||||
(),
|
||||
(),
|
||||
(),
|
||||
),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
impl frame_benchmarking_cli::ExtrinsicBuilder for Client {
|
||||
fn remark(&self, nonce: u32) -> std::result::Result<OpaqueExtrinsic, &'static str> {
|
||||
with_signed_payload! {
|
||||
self,
|
||||
{extra, client, raw_payload},
|
||||
{
|
||||
// First the setup code to init all the variables that are needed
|
||||
// to build the signed extras.
|
||||
use runtime::{Call, SystemCall};
|
||||
|
||||
let call = Call::System(SystemCall::remark { remark: vec![] });
|
||||
let bob = Sr25519Keyring::Bob.pair();
|
||||
|
||||
let period = polkadot_runtime_common::BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64;
|
||||
|
||||
let current_block = 0;
|
||||
let tip = 0;
|
||||
let genesis = client.usage_info().chain.best_hash;
|
||||
},
|
||||
(period, current_block, nonce, tip, call, genesis),
|
||||
/* The SignedPayload is generated here */
|
||||
{
|
||||
// Use the payload to generate a signature.
|
||||
let signature = raw_payload.using_encoded(|payload| bob.sign(payload));
|
||||
|
||||
let ext = runtime::UncheckedExtrinsic::new_signed(
|
||||
call,
|
||||
sp_runtime::AccountId32::from(bob.public()).into(),
|
||||
polkadot_core_primitives::Signature::Sr25519(signature.clone()),
|
||||
extra,
|
||||
);
|
||||
Ok(ext.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Generates inherent data for benchmarking Polkadot, Kusama, Westend and Rococo.
|
||||
///
|
||||
/// Not to be used outside of benchmarking since it returns mocked values.
|
||||
pub fn benchmark_inherent_data(
|
||||
header: polkadot_core_primitives::Header,
|
||||
) -> std::result::Result<sp_inherents::InherentData, sp_inherents::Error> {
|
||||
use sp_inherents::InherentDataProvider;
|
||||
let mut inherent_data = sp_inherents::InherentData::new();
|
||||
|
||||
// Assume that all runtimes have the `timestamp` pallet.
|
||||
let d = std::time::Duration::from_millis(0);
|
||||
let timestamp = sp_timestamp::InherentDataProvider::new(d.into());
|
||||
timestamp.provide_inherent_data(&mut inherent_data)?;
|
||||
|
||||
let para_data = polkadot_primitives::v2::InherentData {
|
||||
bitfields: Vec::new(),
|
||||
backed_candidates: Vec::new(),
|
||||
disputes: Vec::new(),
|
||||
parent_header: header,
|
||||
};
|
||||
|
||||
polkadot_node_core_parachains_inherent::ParachainsInherentDataProvider::from_data(para_data)
|
||||
.provide_inherent_data(&mut inherent_data)?;
|
||||
|
||||
Ok(inherent_data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user