From cdf3a2dc1385debf50096d54d4abf838c6cad4f7 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 30 Dec 2024 06:52:03 +0800 Subject: [PATCH] Migrate inclusion benchmark to v2 (#6368) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Migrate inclusion benchmark to v2. --- Polkadot address: 156HGo9setPcU2qhFMVWLkcmtCEGySLwNqa3DaEiYSWtte4Y --------- Co-authored-by: GitHub Action Co-authored-by: Bastian Köcher --- .../parachains/src/inclusion/benchmarking.rs | 63 ++++++++++--------- prdoc/pr_6368.prdoc | 7 +++ 2 files changed, 41 insertions(+), 29 deletions(-) create mode 100644 prdoc/pr_6368.prdoc diff --git a/polkadot/runtime/parachains/src/inclusion/benchmarking.rs b/polkadot/runtime/parachains/src/inclusion/benchmarking.rs index 1dac3c92cf16..ab95c5c2366a 100644 --- a/polkadot/runtime/parachains/src/inclusion/benchmarking.rs +++ b/polkadot/runtime/parachains/src/inclusion/benchmarking.rs @@ -14,6 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . +use bitvec::{bitvec, prelude::Lsb0}; +use frame_benchmarking::v2::*; +use pallet_message_queue as mq; +use polkadot_primitives::{ + vstaging::CommittedCandidateReceiptV2 as CommittedCandidateReceipt, CandidateCommitments, + HrmpChannelId, OutboundHrmpMessage, SessionIndex, +}; + use super::*; use crate::{ builder::generate_validator_pairs, @@ -21,13 +29,6 @@ use crate::{ hrmp::{HrmpChannel, HrmpChannels}, initializer, HeadData, ValidationCode, }; -use bitvec::{bitvec, prelude::Lsb0}; -use frame_benchmarking::benchmarks; -use pallet_message_queue as mq; -use polkadot_primitives::{ - vstaging::CommittedCandidateReceiptV2 as CommittedCandidateReceipt, CandidateCommitments, - HrmpChannelId, OutboundHrmpMessage, SessionIndex, -}; fn create_candidate_commitments( para_id: ParaId, @@ -70,7 +71,7 @@ fn create_candidate_commitments( BoundedVec::truncate_from(unbounded) }; - let new_validation_code = code_upgrade.then_some(ValidationCode(vec![42u8; 1024])); + let new_validation_code = code_upgrade.then_some(ValidationCode(vec![42_u8; 1024])); CandidateCommitments:: { upward_messages, @@ -87,18 +88,13 @@ fn create_messages(msg_len: usize, n_msgs: usize) -> Vec> { vec![vec![best_number; msg_len]; n_msgs] } -benchmarks! { - where_clause { - where - T: mq::Config + configuration::Config + initializer::Config, - } - - enact_candidate { - let u in 0 .. 2; - let h in 0 .. 2; - let c in 0 .. 1; +#[benchmarks(where T: mq::Config + configuration::Config + initializer::Config)] +mod benchmarks { + use super::*; - let para = 42_u32.into(); // not especially important. + #[benchmark] + fn enact_candidate(u: Linear<0, 2>, h: Linear<0, 2>, c: Linear<0, 1>) { + let para = 42_u32.into(); // not especially important. let max_len = mq::MaxMessageLenOf::::get() as usize; @@ -106,7 +102,7 @@ benchmarks! { let n_validators = config.max_validators.unwrap_or(500); let validators = generate_validator_pairs::(n_validators); - let session = SessionIndex::from(0u32); + let session = SessionIndex::from(0_u32); initializer::Pallet::::test_trigger_on_new_session( false, session, @@ -116,7 +112,7 @@ benchmarks! { let backing_group_size = config.scheduler_params.max_validators_per_core.unwrap_or(5); let head_data = HeadData(vec![0xFF; 1024]); - let relay_parent_number = BlockNumberFor::::from(10u32); + let relay_parent_number = BlockNumberFor::::from(10_u32); let commitments = create_candidate_commitments::(para, head_data, max_len, u, h, c != 0); let backers = bitvec![u8, Lsb0; 1; backing_group_size as usize]; let availability_votes = bitvec![u8, Lsb0; 1; n_validators as usize]; @@ -135,17 +131,26 @@ benchmarks! { ValidationCode(vec![1, 2, 3]).hash(), ); - let receipt = CommittedCandidateReceipt:: { - descriptor, - commitments, - }; + let receipt = CommittedCandidateReceipt:: { descriptor, commitments }; - Pallet::::receive_upward_messages(para, vec![vec![0; max_len]; 1].as_slice()); - } : { Pallet::::enact_candidate(relay_parent_number, receipt, backers, availability_votes, core_index, backing_group) } + Pallet::::receive_upward_messages(para, &vec![vec![0; max_len]; 1]); - impl_benchmark_test_suite!( + #[block] + { + Pallet::::enact_candidate( + relay_parent_number, + receipt, + backers, + availability_votes, + core_index, + backing_group, + ); + } + } + + impl_benchmark_test_suite! { Pallet, crate::mock::new_test_ext(Default::default()), crate::mock::Test - ); + } } diff --git a/prdoc/pr_6368.prdoc b/prdoc/pr_6368.prdoc new file mode 100644 index 000000000000..4fd3963eb05e --- /dev/null +++ b/prdoc/pr_6368.prdoc @@ -0,0 +1,7 @@ +title: Migrate inclusion benchmark to v2 +doc: +- audience: Runtime Dev + description: Migrate inclusion benchmark to v2. +crates: +- name: polkadot-runtime-parachains + bump: patch