Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 1e845de

Browse files
committed
Validator side improvements
1 parent 0d9bc24 commit 1e845de

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

node/network/collator-protocol/src/collator_side/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,8 @@ where
10761076

10771077
let collations = state
10781078
.per_relay_parent
1079-
.get_mut(removed)
1080-
.map(|per_relay_parent| std::mem::take(&mut per_relay_parent.collations))
1079+
.remove(removed)
1080+
.map(|per_relay_parent| per_relay_parent.collations)
10811081
.unwrap_or_default();
10821082
for collation in collations.into_values() {
10831083
state.collation_result_senders.remove(&collation.receipt.hash());
@@ -1103,7 +1103,6 @@ where
11031103
),
11041104
}
11051105
}
1106-
state.per_relay_parent.remove(removed);
11071106
state.span_per_relay_parent.remove(removed);
11081107
state.waiting_collation_fetches.remove(removed);
11091108
}

node/network/collator-protocol/src/validator_side/collation.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,14 @@ pub struct Collations {
134134
pub fetching_from: Option<CollatorId>,
135135
/// Collation that were advertised to us, but we did not yet fetch.
136136
pub waiting_queue: VecDeque<(PendingCollation, CollatorId)>,
137-
/// How many collations have been seconded per parachain.
138-
/// Only used when async backing is enabled.
139-
pub seconded_count: HashMap<ParaId, usize>,
137+
/// How many collations have been seconded.
138+
pub seconded_count: usize,
140139
}
141140

142141
impl Collations {
143142
/// Note a seconded collation for a given para.
144-
pub(super) fn note_seconded(&mut self, para_id: ParaId) {
145-
*self.seconded_count.entry(para_id).or_insert(0) += 1
143+
pub(super) fn note_seconded(&mut self) {
144+
self.seconded_count += 1
146145
}
147146

148147
/// Returns the next collation to fetch from the `unfetched_collations`.
@@ -172,31 +171,24 @@ impl Collations {
172171
match self.status {
173172
// We don't need to fetch any other collation when we already have seconded one.
174173
CollationStatus::Seconded => None,
175-
CollationStatus::Waiting => {
176-
while let Some(next) = self.waiting_queue.pop_front() {
177-
let para_id = next.0.para_id;
178-
if !self.is_fetch_allowed(relay_parent_mode, para_id) {
179-
continue
180-
}
181-
182-
return Some(next)
183-
}
184-
185-
None
186-
},
174+
CollationStatus::Waiting =>
175+
if !self.is_seconded_limit_reached(relay_parent_mode) {
176+
None
177+
} else {
178+
self.waiting_queue.pop_front()
179+
},
187180
CollationStatus::WaitingOnValidation | CollationStatus::Fetching =>
188181
unreachable!("We have reset the status above!"),
189182
}
190183
}
191184

192185
/// Checks the limit of seconded candidates for a given para.
193-
pub(super) fn is_fetch_allowed(
186+
pub(super) fn is_seconded_limit_reached(
194187
&self,
195188
relay_parent_mode: ProspectiveParachainsMode,
196-
para_id: ParaId,
197189
) -> bool {
198190
let seconded_limit =
199191
if relay_parent_mode.is_enabled() { MAX_CANDIDATE_DEPTH + 1 } else { 1 };
200-
self.seconded_count.get(&para_id).map_or(true, |&num| num < seconded_limit)
192+
self.seconded_count < seconded_limit
201193
}
202194
}

node/network/collator-protocol/src/validator_side/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ async fn handle_advertisement<Sender>(
10721072
PendingCollation::new(relay_parent, para_id, peer_id, prospective_candidate);
10731073

10741074
let collations = &mut per_relay_parent.collations;
1075-
if !collations.is_fetch_allowed(relay_parent_mode, para_id) {
1075+
if !collations.is_seconded_limit_reached(relay_parent_mode) {
10761076
gum::debug!(
10771077
target: LOG_TARGET,
10781078
peer_id = ?peer_id,
@@ -1342,7 +1342,7 @@ async fn process_msg<Context>(
13421342

13431343
if let Some(state) = state.per_relay_parent.get_mut(&parent) {
13441344
state.collations.status = CollationStatus::Seconded;
1345-
state.collations.note_seconded(pending_collation.para_id);
1345+
state.collations.note_seconded();
13461346
}
13471347
// If async backing is enabled, make an attempt to fetch next collation.
13481348
dequeue_next_collation_and_fetch(ctx, state, parent, collator_id).await;

0 commit comments

Comments
 (0)