diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 9b0ee84c34d8a..37a7592854623 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -1594,7 +1594,8 @@ pub mod pallet_prelude { /// want to write an alternative to the `frame_system` pallet. /// /// Also see -/// [`pallet::disable_frame_system_supertrait_check`](`frame_support::pallet_macros::disable_frame_system_supertrait_check`) +/// [`pallet::disable_frame_system_supertrait_check`](`frame_support::pallet_macros:: +/// disable_frame_system_supertrait_check`) /// /// ## Macro expansion: /// @@ -1638,7 +1639,8 @@ pub mod pallet_prelude { /// storages can opt-out from this constraint by using `#[pallet::unbounded]` (see /// `#[pallet::storage]` for more info). /// -/// Also see [`pallet::generate_storage_info`](`frame_support::pallet_macros::generate_storage_info`) +/// Also see [`pallet::generate_storage_info`](`frame_support::pallet_macros:: +/// generate_storage_info`) /// /// # `pallet::storage_version` /// diff --git a/utils/frame/benchmarking-cli/src/extrinsic/bench.rs b/utils/frame/benchmarking-cli/src/extrinsic/bench.rs index f67cadffd7e2b..66248b192aae3 100644 --- a/utils/frame/benchmarking-cli/src/extrinsic/bench.rs +++ b/utils/frame/benchmarking-cli/src/extrinsic/bench.rs @@ -41,6 +41,7 @@ use sp_runtime::{ transaction_validity::{InvalidTransaction, TransactionValidityError}, Digest, DigestItem, OpaqueExtrinsic, }; +use std::{cell::RefCell, rc::Rc}; use ver_api::VerApi; use clap::Args; @@ -82,7 +83,7 @@ pub(crate) struct Benchmark { } pub(crate) struct BenchmarkVer { - client: Arc, + client: Rc>, params: BenchmarkParams, inherent_data: (sp_inherents::InherentData, sp_inherents::InherentData), _p: PhantomData<(Block, BA)>, @@ -239,7 +240,7 @@ where { /// Create a new [`Self`] from the arguments. pub fn new( - client: Arc, + client: Rc>, params: BenchmarkParams, inherent_data: (sp_inherents::InherentData, sp_inherents::InherentData), ) -> Self { @@ -299,13 +300,11 @@ where StateAction::ApplyChanges(sc_consensus::StorageChanges::Changes(block.storage_changes)); params.fork_choice = Some(ForkChoiceStrategy::LongestChain); - let mut c = self.client.clone(); - unsafe { - let mut_c = Arc::::get_mut_unchecked(&mut c); - futures::executor::block_on(mut_c.import_block(params, Default::default())) - .expect("importing a block doesn't fail"); - } - info!("best number: {} ", c.info().best_number); + futures::executor::block_on( + self.client.borrow_mut().import_block(params, Default::default()), + ) + .expect("importing a block doesn't fail"); + info!("best number: {} ", self.client.borrow().info().best_number); } /// Builds a block that enqueues maximum possible amount of extrinsics @@ -314,8 +313,13 @@ where ext_builder: &dyn ExtrinsicBuilder, ) -> Result> { let digest = self.create_digest(1_u64); - let mut builder = self.client.new_block(digest)?; - // Create and insert the inherents. + info!("creating remarks"); + let remarks = (0..self.max_ext_per_block()) + .map(|nonce| ext_builder.build(nonce).expect("remark txs creation should not fail")) + .collect::>(); + + let client = self.client.borrow(); + let mut builder = client.new_block(digest)?; info!("creating inherents"); let (seed, inherents) = builder.create_inherents(self.inherent_data.0.clone()).unwrap(); @@ -335,8 +339,7 @@ where let block = builder.build_with_seed(seed, |at, api| { let mut valid_txs: Vec<(Option, Block::Extrinsic)> = Default::default(); - for nonce in 0..self.max_ext_per_block() { - let remark = ext_builder.build(nonce).expect("remark txs creation should not fail"); + for remark in remarks { match validate_transaction::(at, &api, remark.clone()) { Ok(()) => { valid_txs.push((None, remark)); @@ -356,6 +359,10 @@ where valid_txs })?; info!("Extrinsics per block: {}", txs_count); + + if txs_count >= self.max_ext_per_block() as u64 { + panic!("fully filled block should not consume more than half of pregenrated extrinsics .. consider increasing --max-ext-per-block paramter value"); + } Ok(block) } @@ -366,9 +373,15 @@ where apply_previous_block_extrinsics: bool, ) -> Result> { // Return early if we just want a block with inherents and no additional extrinsics. + let remarks = (txs_count..(txs_count * 2)) + .map(|nonce| { + ext_builder.build(nonce as u32).expect("remark txs creation should not fail") + }) + .collect::>(); let digest = self.create_digest(3_u64); - let mut builder = self.client.new_block(digest)?; + let client = self.client.borrow(); + let mut builder = client.new_block(digest)?; let (seed, inherents) = builder.create_inherents(self.inherent_data.1.clone()).unwrap(); info!("pushing inherents"); for inherent in inherents { @@ -380,16 +393,14 @@ where }); let block = builder.build_with_seed(seed, |_, _| { - (txs_count..(txs_count * 2)) - .map(|nonce| { - let remark = ext_builder - .build(nonce as u32) - .expect("remark txs creation should not fail"); - (None, remark) - }) - .collect::>() + remarks.into_iter().map(|remark| (None, remark)).collect::>() })?; + info!( + "created block #{} with {} extrinsics", + block.block.header().number(), + block.block.extrinsics().len() + ); debug!("created block {:?}", block.block.clone()); Ok(block) } @@ -401,6 +412,7 @@ where info!("Running {} warmups...", self.params.warmup); for _ in 0..self.params.warmup { self.client + .borrow() .runtime_api() .execute_block(&block_id, block.clone()) .map_err(|e| Error::Client(RuntimeApiError(e)))?; @@ -411,7 +423,8 @@ where // Execute a block multiple times and record each execution time. for _ in 0..self.params.repeat { let block = block.clone(); - let runtime_api = self.client.runtime_api(); + let client = self.client.borrow(); + let runtime_api = client.runtime_api(); let start = Instant::now(); runtime_api diff --git a/utils/frame/benchmarking-cli/src/lib.rs b/utils/frame/benchmarking-cli/src/lib.rs index 11f4b480768cf..a44a208b16ae9 100644 --- a/utils/frame/benchmarking-cli/src/lib.rs +++ b/utils/frame/benchmarking-cli/src/lib.rs @@ -16,7 +16,6 @@ // limitations under the License. //! Contains the root [`BenchmarkCmd`] command and exports its sub-commands. -#![feature(get_mut_unchecked)] mod block; mod extrinsic; diff --git a/utils/frame/benchmarking-cli/src/overhead/cmd.rs b/utils/frame/benchmarking-cli/src/overhead/cmd.rs index 40ed00c1a8f45..872fc75a0349a 100644 --- a/utils/frame/benchmarking-cli/src/overhead/cmd.rs +++ b/utils/frame/benchmarking-cli/src/overhead/cmd.rs @@ -33,6 +33,7 @@ use sp_runtime::{ traits::{Block as BlockT, Header as HeaderT}, DigestItem, OpaqueExtrinsic, }; +use std::{cell::RefCell, rc::Rc}; use ver_api::VerApi; use clap::{Args, Parser}; @@ -146,7 +147,7 @@ impl OverheadCmd { pub fn run_ver( &self, cfg: Configuration, - client: Arc, + client: Rc>, inherent_data: (sp_inherents::InherentData, sp_inherents::InherentData), ext_builder: &dyn ExtrinsicBuilder, ) -> Result<()>