Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inclusion: bench enact_candidate weight #5270

Merged
merged 62 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
b0fbeec
temp fix for para inherent weight overestimation
ordian Jul 19, 2024
940c02e
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Jul 22, 2024
67c295d
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Jul 22, 2024
08dc2cc
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Jul 22, 2024
f920d3b
fixup
ordian Jul 23, 2024
9c7d1b5
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Jul 23, 2024
42d0302
another fixup
ordian Jul 23, 2024
f4d2eee
fixup
ordian Jul 25, 2024
b235de4
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Jul 25, 2024
be07fcb
fix a typo
ordian Jul 26, 2024
9fe7a6b
polkadot bench: make bitfields full in builder
ordian Jul 26, 2024
ce6d0ac
rename some weight files
ordian Jul 26, 2024
64b367c
some more weight renames
ordian Jul 26, 2024
d305a1a
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Aug 6, 2024
c8b2c30
fmt
ordian Aug 6, 2024
e9258b7
rename rococo weights too
ordian Aug 6, 2024
6133e83
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Aug 7, 2024
c9f313c
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Aug 7, 2024
ea9abce
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Aug 7, 2024
254c11c
prdoc
ordian Aug 7, 2024
ca5ee10
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Aug 7, 2024
c4e0989
restore the comment
ordian Aug 7, 2024
85c6ffd
enact_candidate benchmarking
ordian Aug 6, 2024
d015191
fmt
ordian Aug 6, 2024
cb30247
probably not
ordian Aug 6, 2024
fc958de
remove 'receive_upward_messages' weight
ordian Aug 6, 2024
af4029f
account for enact_candidates in the full weight
ordian Jun 5, 2024
2f93386
add a test
ordian Jun 10, 2024
1ac0e55
remove manual weight calc and unrelated unused dep
ordian Aug 6, 2024
2f446d4
fmt
ordian Aug 6, 2024
bd3dc22
try fixing clippy
ordian Aug 7, 2024
3f22880
fix overweight test
ordian Aug 7, 2024
1a548d0
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Aug 7, 2024
323f651
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Aug 7, 2024
8b3b05d
prdoc
ordian Aug 7, 2024
82ee42c
Update prdoc/pr_5270.prdoc
ordian Aug 8, 2024
1f744d7
address review nits
ordian Aug 8, 2024
0f05cdc
assert overweight with enact_candidates
ordian Aug 9, 2024
53eb1c8
satisfy semver check
ordian Aug 12, 2024
a25fcd2
account for max enact weight in pre dispatch weight
ordian Aug 14, 2024
c007d63
try fixing semver again
ordian Aug 14, 2024
ef78697
Merge branch 'master' into ao-enact-candidate-weight
ordian Aug 14, 2024
cbe0b3f
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Aug 14, 2024
e57e3b2
Merge branch 'ao-fix-parainclusion-weight-overestimation' into ao-ena…
ordian Aug 14, 2024
277f40a
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Aug 16, 2024
df57a53
Merge branch 'ao-fix-parainclusion-weight-overestimation' into ao-ena…
ordian Aug 16, 2024
90e4eaf
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Aug 22, 2024
b5873d4
adjust some of the runtime builder params
ordian Aug 22, 2024
05d90cb
adjust backing bench
ordian Aug 22, 2024
bb75fb5
rename validaty to backing votes
ordian Aug 22, 2024
73d3e6e
fix a typo
ordian Aug 22, 2024
1ca7b53
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Aug 22, 2024
18c3e03
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Aug 23, 2024
26621c4
Merge branch 'ao-fix-parainclusion-weight-overestimation' into ao-ena…
ordian Aug 23, 2024
46c7965
Merge branch 'master' into ao-fix-parainclusion-weight-overestimation
ordian Aug 23, 2024
7c9ebfa
Merge branch 'ao-fix-parainclusion-weight-overestimation' into ao-ena…
ordian Aug 23, 2024
0a0b6d0
Update polkadot/runtime/parachains/src/inclusion/mod.rs
ordian Aug 28, 2024
3d1d839
fix complilation and fmt
ordian Aug 28, 2024
629a541
Merge branch 'master' into ao-enact-candidate-weight
ordian Aug 29, 2024
c857a18
ugh resolve merge conflict
ordian Aug 29, 2024
a9c4d93
compilation fix
ordian Aug 29, 2024
e39fb8a
don't break other tests
ordian Aug 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions polkadot/node/core/pvf/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ libc = { workspace = true }
nix = { features = ["resource", "sched"], workspace = true }
thiserror = { workspace = true }

codec = { features = [
"derive",
], workspace = true }
codec = { features = ["derive"], workspace = true }

polkadot-parachain-primitives = { workspace = true, default-features = true }
polkadot-primitives = { workspace = true, default-features = true }
Expand Down
31 changes: 16 additions & 15 deletions polkadot/runtime/parachains/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ fn account<AccountId: Decode>(name: &'static str, index: u32, seed: u32) -> Acco
.expect("infinite input; no invalid input; qed")
}

pub fn generate_validator_pairs<T: frame_system::Config>(
validator_count: u32,
) -> Vec<(T::AccountId, ValidatorId)> {
(0..validator_count)
.map(|i| {
let public = ValidatorId::generate_pair(None);

// The account Id is not actually used anywhere, just necessary to fulfill the
// expected type of the `validators` param of `test_trigger_on_new_session`.
let account: T::AccountId = account("validator", i, i);
(account, public)
})
.collect()
}

/// Create a 32 byte slice based on the given number.
fn byte32_slice_from(n: u32) -> [u8; 32] {
let mut slice = [0u8; 32];
Expand Down Expand Up @@ -423,20 +438,6 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
}
}

/// Generate validator key pairs and account ids.
fn generate_validator_pairs(validator_count: u32) -> Vec<(T::AccountId, ValidatorId)> {
(0..validator_count)
.map(|i| {
let public = ValidatorId::generate_pair(None);

// The account Id is not actually used anywhere, just necessary to fulfill the
// expected type of the `validators` param of `test_trigger_on_new_session`.
let account: T::AccountId = account("validator", i, i);
(account, public)
})
.collect()
}

fn signing_context(&self) -> SigningContext<T::Hash> {
SigningContext {
parent_hash: Self::header(self.block_number).hash(),
Expand Down Expand Up @@ -800,7 +801,7 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
c.scheduler_params.num_cores = used_cores as u32;
});

let validator_ids = Self::generate_validator_pairs(self.max_validators());
let validator_ids = generate_validator_pairs::<T>(self.max_validators());
let target_session = SessionIndex::from(self.target_session);
let builder = self.setup_session(target_session, validator_ids, used_cores, extra_cores);

Expand Down
3 changes: 1 addition & 2 deletions polkadot/runtime/parachains/src/dmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<T: Config> Pallet<T> {
}

/// Prunes the specified number of messages from the downward message queue of the given para.
pub(crate) fn prune_dmq(para: ParaId, processed_downward_messages: u32) -> Weight {
pub(crate) fn prune_dmq(para: ParaId, processed_downward_messages: u32) {
let q_len = DownwardMessageQueues::<T>::mutate(para, |q| {
let processed_downward_messages = processed_downward_messages as usize;
if processed_downward_messages > q.len() {
Expand All @@ -306,7 +306,6 @@ impl<T: Config> Pallet<T> {
if q_len <= (threshold as usize) {
Self::decrease_fee_factor(para);
}
T::DbWeight::get().reads_writes(1, 1)
}

/// Returns the Head of Message Queue Chain for the given para or `None` if there is none
Expand Down
19 changes: 2 additions & 17 deletions polkadot/runtime/parachains/src/hrmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1305,9 +1305,7 @@ impl<T: Config> Pallet<T> {
remaining
}

pub(crate) fn prune_hrmp(recipient: ParaId, new_hrmp_watermark: BlockNumberFor<T>) -> Weight {
let mut weight = Weight::zero();

pub(crate) fn prune_hrmp(recipient: ParaId, new_hrmp_watermark: BlockNumberFor<T>) {
// sift through the incoming messages digest to collect the paras that sent at least one
// message to this parachain between the old and new watermarks.
let senders = HrmpChannelDigests::<T>::mutate(&recipient, |digest| {
Expand All @@ -1323,7 +1321,6 @@ impl<T: Config> Pallet<T> {
*digest = leftover;
senders
});
weight += T::DbWeight::get().reads_writes(1, 1);

// having all senders we can trivially find out the channels which we need to prune.
let channels_to_prune =
Expand Down Expand Up @@ -1356,21 +1353,13 @@ impl<T: Config> Pallet<T> {
channel.total_size -= pruned_size as u32;
}
});

weight += T::DbWeight::get().reads_writes(2, 2);
}

HrmpWatermarks::<T>::insert(&recipient, new_hrmp_watermark);
weight += T::DbWeight::get().reads_writes(0, 1);

weight
}

/// Process the outbound HRMP messages by putting them into the appropriate recipient queues.
///
/// Returns the amount of weight consumed.
pub(crate) fn queue_outbound_hrmp(sender: ParaId, out_hrmp_msgs: HorizontalMessages) -> Weight {
let mut weight = Weight::zero();
pub(crate) fn queue_outbound_hrmp(sender: ParaId, out_hrmp_msgs: HorizontalMessages) {
let now = frame_system::Pallet::<T>::block_number();

for out_msg in out_hrmp_msgs {
Expand Down Expand Up @@ -1426,11 +1415,7 @@ impl<T: Config> Pallet<T> {
recipient_digest.push((now, vec![sender]));
}
HrmpChannelDigests::<T>::insert(&channel_id.recipient, recipient_digest);

weight += T::DbWeight::get().reads_writes(2, 2);
}

weight
}

/// Initiate opening a channel from a parachain to a given recipient with given channel
Expand Down
123 changes: 117 additions & 6 deletions polkadot/runtime/parachains/src/inclusion/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,134 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

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::{
CandidateCommitments, CollatorId, CollatorSignature, CommittedCandidateReceipt, HrmpChannelId,
OutboundHrmpMessage, SessionIndex,
};
use sp_core::sr25519;

fn create_candidate_commitments<T: crate::hrmp::pallet::Config>(
para_id: ParaId,
head_data: HeadData,
max_msg_len: usize,
ump_msg_count: u32,
hrmp_msg_count: u32,
code_upgrade: bool,
) -> CandidateCommitments {
let upward_messages = {
let unbounded = create_messages(max_msg_len, ump_msg_count as _);
BoundedVec::truncate_from(unbounded)
};

let horizontal_messages = {
let unbounded = create_messages(max_msg_len, hrmp_msg_count as _);

for n in 0..unbounded.len() {
let channel_id = HrmpChannelId { sender: para_id, recipient: para_id + n as u32 + 1 };
HrmpChannels::<T>::insert(
&channel_id,
HrmpChannel {
sender_deposit: 42,
recipient_deposit: 42,
max_capacity: 10_000_000,
max_total_size: 1_000_000_000,
max_message_size: 10_000_000,
msg_count: 0,
total_size: 0,
mqc_head: None,
},
);
}

let unbounded = unbounded
.into_iter()
.enumerate()
.map(|(n, data)| OutboundHrmpMessage { recipient: para_id + n as u32 + 1, data })
.collect();
BoundedVec::truncate_from(unbounded)
};

let new_validation_code = code_upgrade.then_some(ValidationCode(vec![42u8; 1024]));

CandidateCommitments::<u32> {
upward_messages,
horizontal_messages,
new_validation_code,
head_data,
processed_downward_messages: 0,
hrmp_watermark: 10,
}
}

fn create_messages(msg_len: usize, n_msgs: usize) -> Vec<Vec<u8>> {
let best_number = 73_u8; // Chuck Norris of numbers
vec![vec![best_number; msg_len]; n_msgs]
}

benchmarks! {
where_clause {
where
T: mq::Config,
T: mq::Config + configuration::Config + initializer::Config,
}

receive_upward_messages {
let i in 1 .. 1000;
enact_candidate {
let u in 1 .. 32;
let h in 1 .. 32;
alindima marked this conversation as resolved.
Show resolved Hide resolved
let c in 0 .. 1;

let para = 42_u32.into(); // not especially important.

let max_len = mq::MaxMessageLenOf::<T>::get() as usize;
let para = 42u32.into(); // not especially important.
let upward_messages = vec![vec![0; max_len]; i 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);
initializer::Pallet::<T>::test_trigger_on_new_session(
false,
session,
validators.iter().map(|(a, v)| (a, v.clone())),
None,
);
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 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];
let core_index = CoreIndex::from(0);
let backing_group = GroupIndex::from(0);

let descriptor = CandidateDescriptor::<T::Hash> {
para_id: para,
relay_parent: Default::default(),
collator: CollatorId::from(sr25519::Public::from_raw([42u8; 32])),
persisted_validation_data_hash: Default::default(),
pov_hash: Default::default(),
erasure_root: Default::default(),
signature: CollatorSignature::from(sr25519::Signature::from_raw([42u8; 64])),
para_head: Default::default(),
validation_code_hash: ValidationCode(vec![1, 2, 3]).hash(),
};

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

Pallet::<T>::receive_upward_messages(para, vec![vec![0; max_len]; 1].as_slice());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was used previously in the receive_updward_messages benchmark. i assume it is to initialize some storage items (e.g. a page in the message queue) such that the cost of further msg processing are now more realistic

}: { Pallet::<T>::receive_upward_messages(para, upward_messages.as_slice()) }
} : { Pallet::<T>::enact_candidate(relay_parent_number, receipt, backers, availability_votes, core_index, backing_group) }

impl_benchmark_test_suite!(
Pallet,
Expand Down
Loading
Loading