Skip to content

Commit

Permalink
Merge branch 'master' into dm-sync-peers-state-event
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchr authored Dec 30, 2024
2 parents 3812ec9 + f19640b commit d97689e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 31 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
7 changes: 7 additions & 0 deletions prdoc/pr_7005.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: Log peerset set ID -> protocol name mapping
doc:
- audience: Node Dev
description: To simplify debugging of peerset related issues like https://github.com/paritytech/polkadot-sdk/issues/6573#issuecomment-2563091343.
crates:
- name: sc-network
bump: patch
11 changes: 9 additions & 2 deletions substrate/client/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use libp2p::{
},
Multiaddr, PeerId,
};
use log::warn;
use log::{debug, warn};

use codec::DecodeAll;
use sc_network_common::role::Roles;
Expand All @@ -53,6 +53,9 @@ mod notifications;

pub mod message;

// Log target for this file.
const LOG_TARGET: &str = "sub-libp2p";

/// Maximum size used for notifications in the block announce and transaction protocols.
// Must be equal to `max(MAX_BLOCK_ANNOUNCE_SIZE, MAX_TRANSACTIONS_SIZE)`.
pub(crate) const BLOCK_ANNOUNCES_TRANSACTIONS_SUBSTREAM_SIZE: u64 = MAX_RESPONSE_SIZE;
Expand Down Expand Up @@ -124,6 +127,10 @@ impl<B: BlockT> Protocol<B> {
handle.set_metrics(notification_metrics.clone());
});

protocol_configs.iter().enumerate().for_each(|(i, (p, _, _))| {
debug!(target: LOG_TARGET, "Notifications protocol {:?}: {}", SetId::from(i), p.name);
});

(
Notifications::new(
protocol_controller_handles,
Expand Down Expand Up @@ -164,7 +171,7 @@ impl<B: BlockT> Protocol<B> {
{
self.behaviour.disconnect_peer(peer_id, SetId::from(position));
} else {
warn!(target: "sub-libp2p", "disconnect_peer() with invalid protocol name")
warn!(target: LOG_TARGET, "disconnect_peer() with invalid protocol name")
}
}

Expand Down

0 comments on commit d97689e

Please sign in to comment.