Repository: paritytech/substrate
File: frame/offences/src/migration.rs (Rust)

Code before:
			log::info!(target: LOG_TARGET,  "Number of reports to refund and delete: {}", ReportsByKindIndex::<T>::iter().count());

			Ok(Vec::new())
		}

		fn on_runtime_upgrade() -> Weight {
			let current = Pallet::<T>::current_storage_version();
			let onchain = Pallet::<T>::on_chain_storage_version();

			if onchain > 0 {
				log::info!("MigrateToV1 should be removed");
				return T::DbWeight::get().reads(1)
			}

			let status = v0::ReportsByKindIndex::<T>::drain().collect::<Vec<_>>();
			let weight = T::DbWeight::get().reads(status.len() as u64);

			current.put::<Pallet<T>>();

			weight
		}

		#[cfg(feature = "try-runtime")]
		fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
			let onchain = Pallet::<T>::on_chain_storage_version();
			ensure!(onchain < 2, "this migration needs to be removed");
			ensure!(onchain == 1, "this migration needs to be run");
			ensure!(
				ReportsByKindIndex::<T>::iter().count() == 0,
				"there are some dangling reports that need to be destroyed and refunded"
			);
			Ok(())
		}
	}
}

/// Type of data stored as a deferred offence
type DeferredOffenceOf<T> = (
	Vec<OffenceDetails<<T as frame_system::Config>::AccountId, <T as Config>::IdentificationTuple>>,
	Vec<Perbill>,
	SessionIndex,
);

// Deferred reports that have been rejected by the offence handler and need to be submitted
// at a later time.
#[storage_alias]
type DeferredOffences<T: Config> =
	StorageValue<crate::Pallet<T>, Vec<DeferredOffenceOf<T>>, ValueQuery>;

pub fn remove_deferred_storage<T: Config>() -> Weight {
	let mut weight = T::DbWeight::get().reads_writes(1, 1);

Review comment (suggestion):
```suggestion
```

Already checked in `pre_upgrade`

Code after:

	pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>);
	impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {
		#[cfg(feature = "try-runtime")]
		fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
			let onchain = Pallet::<T>::on_chain_storage_version();
			ensure!(onchain < 1, "pallet_offences::MigrateToV1 migration can be deleted");

			log::info!(
				target: LOG_TARGET,
				"Number of reports to refund and delete: {}",
				v0::ReportsByKindIndex::<T>::iter_keys().count()
			);

			Ok(Vec::new())
		}

		fn on_runtime_upgrade() -> Weight {
			let onchain = Pallet::<T>::on_chain_storage_version();

			if onchain > 0 {
				log::info!(target: LOG_TARGET, "pallet_offences::MigrateToV1 should be removed");
				return T::DbWeight::get().reads(1)
			}

			let keys_removed = v0::ReportsByKindIndex::<T>::clear(u32::MAX, None).unique as u64;
			let weight = T::DbWeight::get().reads_writes(keys_removed, keys_removed);

			StorageVersion::new(1).put::<Pallet<T>>();

			weight
		}

		#[cfg(feature = "try-runtime")]
		fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
			let onchain = Pallet::<T>::on_chain_storage_version();
			ensure!(onchain == 1, "pallet_offences::MigrateToV1 needs to be run");
			ensure!(
				v0::ReportsByKindIndex::<T>::iter_keys().count() == 0,
				"there are some dangling reports that need to be destroyed and refunded"
			);
			Ok(())
		}
	}
}

/// Type of data stored as a deferred offence
type DeferredOffenceOf<T> = (
	Vec<OffenceDetails<<T as frame_system::Config>::AccountId, <T as Config>::IdentificationTuple>>,
	Vec<Perbill>,
	SessionIndex,