From 6f2ecf7a6e3f17e7009e69000e85bf6a41a21283 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Wed, 21 Feb 2024 10:16:14 +0100 Subject: [PATCH] Fix try-runtime checks --- relay/polkadot/src/lib.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 5414d41c7a..00e93a5db1 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -1712,19 +1712,23 @@ pub mod migrations { impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC { log::warn!(target: "runtime::session_keys", "Skipping session keys migration pre-upgrade check due to spec version (already applied?)"); return Ok(Vec::new()) } log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state"); - let key_ids = SessionKeys::key_ids() + let key_ids: Vec<_> = SessionKeys::key_ids() .into_iter() .filter(|&k| *k != sp_core::crypto::key_types::BEEFY) .collect(); frame_support::ensure!( - key_ids.into_iter().find(|&k| *k == sp_core::crypto::key_types::IM_ONLINE) == None, + key_ids + .clone() + .into_iter() + .find(|&k| *k == sp_core::crypto::key_types::IM_ONLINE) == + None, "New session keys contain the ImOnline key that should have been removed", ); let storage_key = pallet_session::QueuedKeys::::hashed_key(); @@ -1736,7 +1740,7 @@ pub mod migrations { .into_iter() .for_each(|(id, keys)| { state.extend_from_slice(id.as_slice()); - for key_id in key_ids { + for key_id in key_ids.clone() { state.extend_from_slice(keys.get_raw(*key_id)); } }); @@ -1763,14 +1767,14 @@ pub mod migrations { return Ok(()) } - let key_ids = SessionKeys::key_ids() + let key_ids: Vec<_> = SessionKeys::key_ids() .into_iter() .filter(|&k| *k != sp_core::crypto::key_types::BEEFY) .collect(); let mut new_state: Vec = Vec::new(); pallet_session::QueuedKeys::::get().into_iter().for_each(|(id, keys)| { new_state.extend_from_slice(id.as_slice()); - for key_id in key_ids { + for key_id in key_ids.clone() { new_state.extend_from_slice(keys.get_raw(*key_id)); } });