Repository: paritytech/substrate
File: frame/election-provider-multi-phase/src/signed.rs (Rust)

Code before:
				// the queue is full -- if this is better, insert it.
				let weakest_score = match self.indices.iter().next().defensive() {
					None => return InsertResult::NotInserted,
					Some((score, _, _)) => *score,
				};
				let threshold = T::BetterSignedThreshold::get();

				// if we haven't improved on the weakest score, don't change anything.
				if !submission.raw_solution.score.strict_threshold_better(weakest_score, threshold)
				{
					return InsertResult::NotInserted
				}

				self.swap_out_submission(
					0, // swap out the worse one, which is always index 0.
					Some((submission.raw_solution.score, block_number, self.next_idx)),
				)
			},
		};

		// this is the ONLY place that we insert, and we sort post insertion. If scores are the
		// same, we sort based on reverse of submission block number.
		self.indices
			.sort_by(|(score1, bn1, _), (score2, bn2, _)| match score1.cmp(score2) {
				Ordering::Equal => bn1.cmp(&bn2).reverse(),
				x @ _ => x,
			});

		// we've taken out the weakest, so update the storage map and the next index
		debug_assert!(!self.insertion_overlay.contains_key(&self.next_idx));
		self.insertion_overlay.insert(self.next_idx, submission);
		debug_assert!(!self.deletion_overlay.contains(&self.next_idx));
		self.next_idx += 1;
		match weakest {
			Some(weakest) => InsertResult::InsertedEjecting(weakest),
			None => InsertResult::Inserted,
		}
	}
}

impl<T: Config> Pallet<T> {
	/// `Self` accessor for `SignedSubmission<T>`.
	pub fn signed_submissions() -> SignedSubmissions<T> {
		SignedSubmissions::<T>::get()
	}

	/// Finish the signed phase. Process the signed submissions from best to worse until a valid one
	/// is found, rewarding the best one and slashing the invalid ones along the way.
	///
	/// Returns true if we have a good solution in the signed phase.
	///

Review comment (suggestion):
should be sufficient

```suggestion
				x => x,
```

Code after:
		let maybe_weakest = match self.indices.try_push((
			submission.raw_solution.score,
			block_number,
			self.next_idx,
		)) {
			Ok(_) => None,
			Err(_) => {
				// the queue is full -- if this is better, insert it.
				let weakest_score = match self.indices.iter().next().defensive() {
					None => return InsertResult::NotInserted,
					Some((score, _, _)) => *score,
				};
				let threshold = T::BetterSignedThreshold::get();

				// if we haven't improved on the weakest score, don't change anything.
				if !submission.raw_solution.score.strict_threshold_better(weakest_score, threshold)
				{
					return InsertResult::NotInserted
				}

				self.swap_out_submission(
					0, // swap out the worse one, which is always index 0.
					Some((submission.raw_solution.score, block_number, self.next_idx)),
				)
			},
		};

		// this is the ONLY place that we insert, and we sort post insertion. If scores are the
		// same, we sort based on reverse of submission block number.
		self.indices
			.sort_by(|(score1, bn1, _), (score2, bn2, _)| match score1.cmp(score2) {
				Ordering::Equal => bn1.cmp(&bn2).reverse(),
				x => x,
			});

		// we've taken out the weakest, so update the storage map and the next index
		debug_assert!(!self.insertion_overlay.contains_key(&self.next_idx));
		self.insertion_overlay.insert(self.next_idx, submission);
		debug_assert!(!self.deletion_overlay.contains(&self.next_idx));
		self.next_idx += 1;
		match maybe_weakest {
			Some(weakest) => InsertResult::InsertedEjecting(weakest),
			None => InsertResult::Inserted,
		}
	}
}

impl<T: Config> Pallet<T> {
	/// `Self` accessor for `SignedSubmission<T>`.
	pub fn signed_submissions() -> SignedSubmissions<T> {
		SignedSubmissions::<T>::get()