Repository: paritytech/substrate
File: frame/referenda/src/lib.rs (Rust)

Code before:
		elapsed: BlockNumberFor<T>,
		period: BlockNumberFor<T>,
		support_needed: &Curve,
		approval_needed: &Curve,
		id: TrackIdOf<T, I>,
	) -> bool {
		let x = Perbill::from_rational(elapsed.min(period), period);
		support_needed.passing(x, tally.support(id)) &&
			approval_needed.passing(x, tally.approval(id))
	}

	/// Clear metadata if exist for a given referendum index.
	fn do_clear_metadata(index: ReferendumIndex) {
		if let Some(hash) = MetadataOf::<T, I>::take(index) {
			Self::deposit_event(Event::<T, I>::MetadataCleared { index, hash });
		}
	}

	/// Ensure the correctness of the state of this pallet.
	///
	/// The following assertions must always apply.
	///
	/// General assertions:
	///
	/// * `ReferendumCount` must always be equal to the number of referenda in `ReferendumInfoFor`.
	/// * Referendum indices in `MetadataOf` must also be stored in `ReferendumInfoFor`.
	#[cfg(any(feature = "try-runtime", test))]
	fn do_try_state() -> Result<(), sp_runtime::TryRuntimeError> {
		ensure!(
			ReferendumCount::<T, I>::get() as usize ==
				ReferendumInfoFor::<T, I>::iter_keys().count(),
			"Number of referenda in `ReferendumInfoFor` is different than `ReferendumCount`"
		);

		MetadataOf::<T, I>::iter_keys().try_for_each(|referendum_index| -> DispatchResult {
			ensure!(
				ReferendumInfoFor::<T, I>::contains_key(referendum_index),
				"Referendum indices in `MetadataOf` must also be stored in `ReferendumInfoOf`"
			);
			Ok(())
		})?;

		Self::try_state_referenda_info()?;
		Self::try_state_tracks()?;

		Ok(())
	}

	/// Looking at referenda info:
	///
	/// - Data regarding ongoing phase:

Review comment (suggestion):
```suggestion
	/// * Referendum indices in [`MetadataOf`] must also be stored in [`ReferendumInfoFor`].
```

Code after:
		elapsed: BlockNumberFor<T>,
		period: BlockNumberFor<T>,
		support_needed: &Curve,
		approval_needed: &Curve,
		id: TrackIdOf<T, I>,
	) -> bool {
		let x = Perbill::from_rational(elapsed.min(period), period);
		support_needed.passing(x, tally.support(id)) &&
			approval_needed.passing(x, tally.approval(id))
	}

	/// Clear metadata if exist for a given referendum index.
	fn do_clear_metadata(index: ReferendumIndex) {
		if let Some(hash) = MetadataOf::<T, I>::take(index) {
			Self::deposit_event(Event::<T, I>::MetadataCleared { index, hash });
		}
	}

	/// Ensure the correctness of the state of this pallet.
	///
	/// The following assertions must always apply.
	///
	/// General assertions:
	///
	/// * [`ReferendumCount`] must always be equal to the number of referenda in
	///   [`ReferendumInfoFor`].
	/// * Referendum indices in [`MetadataOf`] must also be stored in [`ReferendumInfoFor`].
	#[cfg(any(feature = "try-runtime", test))]
	fn do_try_state() -> Result<(), sp_runtime::TryRuntimeError> {
		ensure!(
			ReferendumCount::<T, I>::get() as usize ==
				ReferendumInfoFor::<T, I>::iter_keys().count(),
			"Number of referenda in `ReferendumInfoFor` is different than `ReferendumCount`"
		);

		MetadataOf::<T, I>::iter_keys().try_for_each(|referendum_index| -> DispatchResult {
			ensure!(
				ReferendumInfoFor::<T, I>::contains_key(referendum_index),
				"Referendum indices in `MetadataOf` must also be stored in `ReferendumInfoOf`"
			);
			Ok(())
		})?;

		Self::try_state_referenda_info()?;
		Self::try_state_tracks()?;

		Ok(())
	}

	/// Looking at referenda info:
	///