From c7f24aa8f7fc3d97a0c6d6d2b1d4a44a9057bb52 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Fri, 28 Jun 2024 08:44:31 +0300 Subject: [PATCH] Undo `is_collations_limit_reached` modifications --- .../src/validator_side/collation.rs | 49 ++----------------- .../src/validator_side/mod.rs | 8 +-- 2 files changed, 7 insertions(+), 50 deletions(-) diff --git a/polkadot/node/network/collator-protocol/src/validator_side/collation.rs b/polkadot/node/network/collator-protocol/src/validator_side/collation.rs index cbb926939d991..f03ac94a9dd16 100644 --- a/polkadot/node/network/collator-protocol/src/validator_side/collation.rs +++ b/polkadot/node/network/collator-protocol/src/validator_side/collation.rs @@ -28,7 +28,7 @@ //! └─▶Advertised ─▶ Pending ─▶ Fetched ─▶ Validated use std::{ - collections::{BTreeMap, HashMap, HashSet, VecDeque}, + collections::{BTreeMap, VecDeque}, future::Future, pin::Pin, task::Poll, @@ -53,7 +53,7 @@ use tokio_util::sync::CancellationToken; use crate::{error::SecondingError, LOG_TARGET}; -use super::{GroupAssignments, PeerData}; +use super::GroupAssignments; /// Candidate supplied with a para head it's built on top of. #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)] @@ -308,15 +308,10 @@ impl Collations { } } - /// Checks if another collation can be accepted. There are two limits: - /// 1. The number of collations that can be seconded. - /// 2. The number of collations that can be fetched per parachain. This is based on the number - /// of entries in the claim queue. - pub(super) fn is_collations_limit_reached( + /// Checks the limit of seconded candidates. + pub(super) fn is_seconded_limit_reached( &self, relay_parent_mode: ProspectiveParachainsMode, - para_id: ParaId, - peer_data: &HashMap, ) -> bool { let seconded_limit = if let ProspectiveParachainsMode::Enabled { max_candidate_depth, .. } = @@ -326,41 +321,7 @@ impl Collations { } else { 1 }; - - // All collators in `Collating` state for `para_id` we know about - let collators_for_para = peer_data - .iter() - .filter(|(_, data)| data.collating_para() == Some(para_id)) - .filter_map(|(_, data)| data.collator_id()) - .collect::>(); - - // If there is a pending fetch - count it - let pending_fetch = self - .fetching_from - .as_ref() - .map(|(collator_id, _)| if collators_for_para.contains(&collator_id) { 1 } else { 0 }) - .unwrap_or(0); - - // Successful fetches + a pending fetch < claim queue entries for `para_id` - let respected_per_para_limit = - self.claims_per_para.get(¶_id).copied().unwrap_or_default() >= - self.fetched_per_para.get(¶_id).copied().unwrap_or_default() + pending_fetch; - - let respected_seconding_limit = self.seconded_count < seconded_limit; - - gum::trace!( - target: LOG_TARGET, - ?para_id, - claims_per_para=?self.claims_per_para, - fetched_per_para=?self.fetched_per_para, - ?pending_fetch, - ?seconded_limit, - ?respected_per_para_limit, - ?respected_seconding_limit, - "is_collations_limit_reached" - ); - - !(respected_seconding_limit && respected_per_para_limit) + self.seconded_count >= seconded_limit } /// Adds a new collation to the waiting queue for the relay parent. This function doesn't diff --git a/polkadot/node/network/collator-protocol/src/validator_side/mod.rs b/polkadot/node/network/collator-protocol/src/validator_side/mod.rs index 823e21ff13776..ec7bca72242b8 100644 --- a/polkadot/node/network/collator-protocol/src/validator_side/mod.rs +++ b/polkadot/node/network/collator-protocol/src/validator_side/mod.rs @@ -1101,11 +1101,7 @@ where ) .map_err(AdvertisementError::Invalid)?; - if per_relay_parent.collations.is_collations_limit_reached( - relay_parent_mode, - para_id, - &state.peer_data, - ) { + if per_relay_parent.collations.is_seconded_limit_reached(relay_parent_mode) { return Err(AdvertisementError::SecondedLimitReached) } @@ -1197,7 +1193,7 @@ where }); let collations = &mut per_relay_parent.collations; - if collations.is_collations_limit_reached(relay_parent_mode, para_id, &state.peer_data) { + if collations.is_seconded_limit_reached(relay_parent_mode) { gum::trace!( target: LOG_TARGET, peer_id = ?peer_id,