Skip to content

Commit

Permalink
Undo is_collations_limit_reached modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
tdimitrov committed Jun 28, 2024
1 parent 0f28aa8 commit c7f24aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//! └─▶Advertised ─▶ Pending ─▶ Fetched ─▶ Validated

use std::{
collections::{BTreeMap, HashMap, HashSet, VecDeque},
collections::{BTreeMap, VecDeque},
future::Future,
pin::Pin,
task::Poll,
Expand All @@ -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)]
Expand Down Expand Up @@ -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<PeerId, PeerData>,
) -> bool {
let seconded_limit =
if let ProspectiveParachainsMode::Enabled { max_candidate_depth, .. } =
Expand All @@ -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::<HashSet<_>>();

// 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(&para_id).copied().unwrap_or_default() >=
self.fetched_per_para.get(&para_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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c7f24aa

Please sign in to comment.