2023-01-04 23:09:58 -05:00
|
|
|
use std::sync::Arc;
|
2022-07-15 00:05:00 -04:00
|
|
|
|
|
|
|
|
use sp_core::{Encode, Pair};
|
|
|
|
|
use sp_keyring::Sr25519Keyring;
|
2023-01-04 23:09:58 -05:00
|
|
|
use sp_inherents::InherentData;
|
2022-07-15 00:05:00 -04:00
|
|
|
|
|
|
|
|
use sp_runtime::OpaqueExtrinsic;
|
|
|
|
|
|
|
|
|
|
use sc_cli::Result;
|
|
|
|
|
use sc_client_api::BlockBackend;
|
|
|
|
|
|
2023-01-20 11:00:18 -05:00
|
|
|
use serai_runtime::{
|
|
|
|
|
VERSION, BlockHashCount,
|
|
|
|
|
system::{self, Call as SystemCall},
|
|
|
|
|
transaction_payment, RuntimeCall, UncheckedExtrinsic, SignedPayload, Runtime,
|
|
|
|
|
};
|
2022-07-15 00:05:00 -04:00
|
|
|
|
|
|
|
|
use crate::service::FullClient;
|
|
|
|
|
|
2022-08-16 17:43:46 -04:00
|
|
|
pub struct RemarkBuilder {
|
2022-07-15 01:26:07 -04:00
|
|
|
client: Arc<FullClient>,
|
2022-07-15 00:05:00 -04:00
|
|
|
}
|
|
|
|
|
|
2022-08-16 17:43:46 -04:00
|
|
|
impl RemarkBuilder {
|
2022-07-15 00:05:00 -04:00
|
|
|
pub fn new(client: Arc<FullClient>) -> Self {
|
|
|
|
|
Self { client }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-16 17:43:46 -04:00
|
|
|
impl frame_benchmarking_cli::ExtrinsicBuilder for RemarkBuilder {
|
|
|
|
|
fn pallet(&self) -> &str {
|
|
|
|
|
"system"
|
|
|
|
|
}
|
|
|
|
|
fn extrinsic(&self) -> &str {
|
|
|
|
|
"remark"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn build(&self, nonce: u32) -> std::result::Result<OpaqueExtrinsic, &'static str> {
|
2022-07-15 01:26:07 -04:00
|
|
|
Ok(OpaqueExtrinsic::from(create_benchmark_extrinsic(
|
|
|
|
|
self.client.as_ref(),
|
|
|
|
|
Sr25519Keyring::Bob.pair(),
|
|
|
|
|
SystemCall::remark { remark: vec![] }.into(),
|
|
|
|
|
nonce,
|
|
|
|
|
)))
|
2022-07-15 00:05:00 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn create_benchmark_extrinsic(
|
|
|
|
|
client: &FullClient,
|
|
|
|
|
sender: sp_core::sr25519::Pair,
|
2023-01-20 11:00:18 -05:00
|
|
|
call: RuntimeCall,
|
2022-07-15 00:05:00 -04:00
|
|
|
nonce: u32,
|
2023-01-20 11:00:18 -05:00
|
|
|
) -> UncheckedExtrinsic {
|
2022-07-15 00:05:00 -04:00
|
|
|
let extra = (
|
2023-01-20 11:00:18 -05:00
|
|
|
system::CheckNonZeroSender::<Runtime>::new(),
|
|
|
|
|
system::CheckSpecVersion::<Runtime>::new(),
|
|
|
|
|
system::CheckTxVersion::<Runtime>::new(),
|
|
|
|
|
system::CheckGenesis::<Runtime>::new(),
|
|
|
|
|
system::CheckEra::<Runtime>::from(sp_runtime::generic::Era::mortal(
|
|
|
|
|
u64::from(BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2)),
|
2022-07-15 01:26:07 -04:00
|
|
|
client.chain_info().best_number.into(),
|
|
|
|
|
)),
|
2023-01-20 11:00:18 -05:00
|
|
|
system::CheckNonce::<Runtime>::from(nonce),
|
|
|
|
|
system::CheckWeight::<Runtime>::new(),
|
|
|
|
|
transaction_payment::ChargeTransactionPayment::<Runtime>::from(0),
|
2022-07-15 00:05:00 -04:00
|
|
|
);
|
|
|
|
|
|
2023-01-20 11:00:18 -05:00
|
|
|
UncheckedExtrinsic::new_signed(
|
2022-07-15 00:05:00 -04:00
|
|
|
call.clone(),
|
2022-07-30 18:21:20 -04:00
|
|
|
sender.public(),
|
2023-01-20 11:00:18 -05:00
|
|
|
SignedPayload::from_raw(
|
2022-07-30 18:21:20 -04:00
|
|
|
call,
|
|
|
|
|
extra.clone(),
|
|
|
|
|
(
|
|
|
|
|
(),
|
2023-01-20 11:00:18 -05:00
|
|
|
VERSION.spec_version,
|
|
|
|
|
VERSION.transaction_version,
|
2022-07-30 18:21:20 -04:00
|
|
|
client.block_hash(0).ok().flatten().unwrap(),
|
|
|
|
|
client.chain_info().best_hash,
|
|
|
|
|
(),
|
|
|
|
|
(),
|
|
|
|
|
(),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.using_encoded(|e| sender.sign(e)),
|
2022-07-15 00:05:00 -04:00
|
|
|
extra,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn inherent_benchmark_data() -> Result<InherentData> {
|
2023-01-04 23:09:58 -05:00
|
|
|
Ok(InherentData::new())
|
2022-07-15 00:05:00 -04:00
|
|
|
}
|