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

Code before:
	///
	/// * There must exist track info for the track of the referendum.
	/// * The deciding stage has to begin before confirmation period.
	/// * If alarm is set the nudge call has to be at most `UndecidingTimeout` blocks away
	///  from the submission block.
	#[cfg(any(feature = "try-runtime", test))]
	fn try_state_referenda_info() -> Result<(), TryRuntimeError> {
		ReferendumInfoFor::<T, I>::iter().try_for_each(|(_, referendum)| {
			match referendum {
				ReferendumInfo::Ongoing(status) => {
					ensure!(
						Self::track(status.track).is_some(),
						"No track info for the track of the referendum."
					);

					if let Some(deciding) = status.deciding {
						ensure!(
							deciding.since <
								deciding.confirming.unwrap_or(T::BlockNumber::max_value()),
								"Deciding status cannot begin before confirming stage."
						)
					}

					if let Some(alarm) = status.alarm {
						ensure!(alarm.0 <= status.submitted.saturating_add(T::UndecidingTimeout::get()), "The alarm cannot be set more than `UndecidingTimeout` away from the submission block.")
					}
				},
				_ => {},
			}
			Ok(())
		})
	}

	/// Looking at tracks:
	///
	/// * The referendum indices stored in `TrackQueue` must exist as keys in the
	///  `ReferendumInfoFor` storage map.
	#[cfg(any(feature = "try-runtime", test))]
	fn try_state_tracks() -> Result<(), TryRuntimeError> {
		T::Tracks::tracks().iter().try_for_each(|track| {
			TrackQueue::<T, I>::get(track.0).iter().try_for_each(
				|(referendum_index, _)| -> Result<(), TryRuntimeError> {
					ensure!(
					ReferendumInfoFor::<T, I>::contains_key(referendum_index),
					"`ReferendumIndex` inside the `TrackQueue` should be a key in `ReferendumInfoFor`"
				);
					Ok(())
				},
			)?;
			Ok(())
		})

Review comment (bug):
```suggestion
```
This is true for the first alarm, but the alarm can be set after the first nudge call(e.g. at the beginning of the deciding period). For this reason, this check has been failing against the Polkadot state and I am removing it.

Code after:
	/// * There must exist track info for the track of the referendum.
	/// * The deciding stage has to begin before confirmation period.
	/// * If alarm is set the nudge call has to be at most [`UndecidingTimeout`] blocks away
	///  from the submission block.
	#[cfg(any(feature = "try-runtime", test))]
	fn try_state_referenda_info() -> Result<(), sp_runtime::TryRuntimeError> {
		ReferendumInfoFor::<T, I>::iter().try_for_each(|(_, referendum)| {
			match referendum {
				ReferendumInfo::Ongoing(status) => {
					ensure!(
						Self::track(status.track).is_some(),
						"No track info for the track of the referendum."
					);

					if let Some(deciding) = status.deciding {
						ensure!(
							deciding.since <
								deciding.confirming.unwrap_or(BlockNumberFor::<T>::max_value()),
							"Deciding status cannot begin before confirming stage."
						)
					}
				},
				_ => {},
			}
			Ok(())
		})
	}

	/// Looking at tracks:
	///
	/// * The referendum indices stored in [`TrackQueue`] must exist as keys in the
	///  [`ReferendumInfoFor`] storage map.
	#[cfg(any(feature = "try-runtime", test))]
	fn try_state_tracks() -> Result<(), sp_runtime::TryRuntimeError> {
		T::Tracks::tracks().iter().try_for_each(|track| {
			TrackQueue::<T, I>::get(track.0).iter().try_for_each(
				|(referendum_index, _)| -> Result<(), sp_runtime::TryRuntimeError> {
					ensure!(
					ReferendumInfoFor::<T, I>::contains_key(referendum_index),
					"`ReferendumIndex` inside the `TrackQueue` should be a key in `ReferendumInfoFor`"
				);
					Ok(())
				},
			)?;
			Ok(())
		})
	}
}