Skip to content

Commit

Permalink
Migrate inclusion benchmark to v2 (#6368)
Browse files Browse the repository at this point in the history
Migrate inclusion benchmark to v2.

---

Polkadot address: 156HGo9setPcU2qhFMVWLkcmtCEGySLwNqa3DaEiYSWtte4Y

---------

Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
3 people authored Dec 29, 2024
1 parent b7afe48 commit cdf3a2d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
63 changes: 34 additions & 29 deletions polkadot/runtime/parachains/src/inclusion/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

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,
configuration,
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<T: crate::hrmp::pallet::Config>(
para_id: ParaId,
Expand Down Expand Up @@ -70,7 +71,7 @@ fn create_candidate_commitments<T: crate::hrmp::pallet::Config>(
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::<u32> {
upward_messages,
Expand All @@ -87,26 +88,21 @@ fn create_messages(msg_len: usize, n_msgs: usize) -> Vec<Vec<u8>> {
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::<T>::get() as usize;

let config = configuration::ActiveConfig::<T>::get();
let n_validators = config.max_validators.unwrap_or(500);
let validators = generate_validator_pairs::<T>(n_validators);

let session = SessionIndex::from(0u32);
let session = SessionIndex::from(0_u32);
initializer::Pallet::<T>::test_trigger_on_new_session(
false,
session,
Expand All @@ -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::<T>::from(10u32);
let relay_parent_number = BlockNumberFor::<T>::from(10_u32);
let commitments = create_candidate_commitments::<T>(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];
Expand All @@ -135,17 +131,26 @@ benchmarks! {
ValidationCode(vec![1, 2, 3]).hash(),
);

let receipt = CommittedCandidateReceipt::<T::Hash> {
descriptor,
commitments,
};
let receipt = CommittedCandidateReceipt::<T::Hash> { descriptor, commitments };

Pallet::<T>::receive_upward_messages(para, vec![vec![0; max_len]; 1].as_slice());
} : { Pallet::<T>::enact_candidate(relay_parent_number, receipt, backers, availability_votes, core_index, backing_group) }
Pallet::<T>::receive_upward_messages(para, &vec![vec![0; max_len]; 1]);

impl_benchmark_test_suite!(
#[block]
{
Pallet::<T>::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
);
}
}
7 changes: 7 additions & 0 deletions prdoc/pr_6368.prdoc
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cdf3a2d

Please sign in to comment.