diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index b772f5efc..415e11b91 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -158,7 +158,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("root"), impl_name: create_runtime_str!("root"), authoring_version: 1, - spec_version: 56, + spec_version: 57, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 10, @@ -1465,20 +1465,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - ( - pallet_multisig::migrations::v1::MigrateToV1, - pallet_preimage::migration::v1::Migration, - pallet_scheduler::migration::v3::MigrateToV4, - pallet_assets::migration::v1::MigrateToV1, - pallet_balances::migration::MigrateToTrackInactive, - pallet_scheduler::migration::v4::CleanupAgendas, - pallet_staking::migrations::v13::MigrateToV13, - pallet_grandpa::migrations::CleanupSetIdSessionMap, - pallet_offences::migration::v1::MigrateToV1, - pallet_im_online::migration::v1::Migration, - pallet_election_provider_multi_phase::migrations::v1::MigrateToV1, - migrations::AllMigrations, - ), + (migrations::AllMigrations,), >; impl_runtime_apis! { diff --git a/runtime/src/migrations/ethy.rs b/runtime/src/migrations/ethy.rs deleted file mode 100644 index 96ecd4d65..000000000 --- a/runtime/src/migrations/ethy.rs +++ /dev/null @@ -1,230 +0,0 @@ -// Copyright 2022-2023 Futureverse Corporation Limited -// -// Licensed under the LGPL, Version 3.0 (the "License"); -// you may not use this file except in compliance with the License. -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// You may obtain a copy of the License at the root of this project source code - -use crate::{EthBridge, Runtime, Weight}; -use frame_support::{ - dispatch::GetStorageVersion, - traits::{OnRuntimeUpgrade, StorageVersion}, -}; -#[allow(unused_imports)] -use sp_std::vec::Vec; - -pub struct Upgrade; - -impl OnRuntimeUpgrade for Upgrade { - fn on_runtime_upgrade() -> Weight { - let current = EthBridge::current_storage_version(); - let onchain = EthBridge::on_chain_storage_version(); - log::info!(target: "Migration", "Ethy: Running migration with current storage version {current:?} / on-chain {onchain:?}"); - - let mut weight = ::DbWeight::get().reads(2); - - if onchain == 0 { - log::info!(target: "Migration", "Ethy: Migrating from on-chain version 0 to on-chain version 1."); - weight += v1::migrate::(); - - StorageVersion::new(1).put::(); - - log::info!(target: "Migration", "Ethy: Migration successfully completed."); - } else { - log::info!(target: "Migration", "Ethy: No migration was done, however migration code needs to be removed."); - } - - weight - } - - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { - log::info!(target: "Migration", "Ethy: Upgrade to v1 Pre Upgrade."); - let onchain = EthBridge::on_chain_storage_version(); - // Return OK(()) if upgrade has already been done - if onchain == 1 { - return Ok(Vec::new()) - } - assert_eq!(onchain, 0); - - Ok(Vec::new()) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), &'static str> { - log::info!(target: "Migration", "Ethy: Upgrade to v1 Post Upgrade."); - let current = EthBridge::current_storage_version(); - let onchain = EthBridge::on_chain_storage_version(); - assert_eq!(current, 1); - assert_eq!(onchain, 1); - Ok(()) - } -} - -#[allow(dead_code)] -#[allow(unused_imports)] -pub mod v1 { - use super::*; - use crate::migrations::{Map, Value}; - use codec::{Decode, Encode, MaxEncodedLen}; - use frame_support::{ - sp_runtime::RuntimeDebug, - storage_alias, - weights::{constants::RocksDbWeight, Weight}, - BoundedVec, StorageHasher, Twox64Concat, - }; - use pallet_ethy::{BridgePauseStatus, BridgePaused, ProcessedMessageIds}; - use scale_info::TypeInfo; - use seed_primitives::ethy::EventClaimId; - use sp_core::{Get, H160}; - - type AccountId = ::AccountId; - - pub fn migrate() -> Weight - where - AccountId: From, - { - log::info!(target: "Migration", "Ethy: migrating ProcessedMessageIds"); - let mut weight: Weight = RocksDbWeight::get().reads_writes(1, 1); - - let mut processed_message_ids = - Value::unsafe_storage_get::>(b"EthBridge", b"ProcessedMessageIds") - .unwrap_or_default(); - let prune_weight = pallet_ethy::Pallet::::prune_claim_ids(&mut processed_message_ids); - weight = weight.saturating_add(prune_weight); - let message_ids = BoundedVec::truncate_from(processed_message_ids); - ProcessedMessageIds::::put(message_ids); - - log::info!(target: "Migration", "Ethy: migrating BridgePaused"); - weight = weight.saturating_add(RocksDbWeight::get().reads_writes(1, 1)); - - let bridge_paused = - Value::unsafe_storage_get::(b"EthBridge", b"BridgePaused").unwrap_or_default(); - - let paused_status = - BridgePauseStatus { manual_pause: bridge_paused, authorities_change: false }; - BridgePaused::::put(paused_status); - - log::info!(target: "Migration", "Ethy: successfully migrated BridgePaused and ProcessedMessageIds"); - - weight - } - - #[cfg(test)] - mod tests { - use super::*; - use crate::{migrations::tests::new_test_ext, MaxProcessedMessageIds}; - use pallet_ethy::MissedMessageIds; - - #[test] - fn migration_test_1() { - new_test_ext().execute_with(|| { - // Setup storage - StorageVersion::new(0).put::(); - - // token locks with no listings - let event_ids: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - Value::unsafe_storage_put::>( - b"EthBridge", - b"ProcessedMessageIds", - event_ids, - ); - - // Do runtime upgrade - Upgrade::on_runtime_upgrade(); - assert_eq!(EthBridge::on_chain_storage_version(), 1); - - let event_ids = ProcessedMessageIds::::get(); - assert_eq!(event_ids.into_inner(), vec![10]); - let missed_ids = MissedMessageIds::::get(); - assert!(missed_ids.is_empty()); - }); - } - - #[test] - fn migration_test_2() { - new_test_ext().execute_with(|| { - // Setup storage - StorageVersion::new(0).put::(); - - // Create false data with all even numbers between 0 and 4000 - let max = MaxProcessedMessageIds::get() as u64; - let event_ids: Vec = - (0u64..max * 2).into_iter().map(|x| x * 2).collect(); - - assert_eq!(event_ids.len(), (max * 2) as usize); - Value::unsafe_storage_put::>( - b"EthBridge", - b"ProcessedMessageIds", - event_ids, - ); - - // Do runtime upgrade - Upgrade::on_runtime_upgrade(); - assert_eq!(EthBridge::on_chain_storage_version(), 1); - - // ProcessedMessageIds should be the second half of the original list - // i.e. all even numbers between 2000 and 4000 - let expected_event_ids: Vec = - (max..max * 2).into_iter().map(|x| x * 2).collect(); - let event_ids = ProcessedMessageIds::::get(); - assert_eq!(event_ids.len(), max as usize); - assert_eq!(event_ids.into_inner(), expected_event_ids); - - // MissedMessageIds should be all the odd message Ids in the first half of the - // original list. i.e. 1,3,5,7 - let expected_missed_ids: Vec = - (0..max).into_iter().map(|x| x * 2 + 1).collect(); - let missed_ids = MissedMessageIds::::get(); - assert_eq!(missed_ids.len(), max as usize); - assert_eq!(missed_ids, expected_missed_ids); - }); - } - - #[test] - fn migration_test_bridge_paused_1() { - new_test_ext().execute_with(|| { - // Setup storage - StorageVersion::new(0).put::(); - - // token locks with no listings - Value::unsafe_storage_put::(b"EthBridge", b"BridgePaused", false); - - // Do runtime upgrade - Upgrade::on_runtime_upgrade(); - assert_eq!(EthBridge::on_chain_storage_version(), 1); - - let pause_status = BridgePaused::::get(); - assert_eq!( - pause_status, - BridgePauseStatus { manual_pause: false, authorities_change: false } - ); - }); - } - - #[test] - fn migration_test_bridge_paused_2() { - new_test_ext().execute_with(|| { - // Setup storage - StorageVersion::new(0).put::(); - - // token locks with no listings - Value::unsafe_storage_put::(b"EthBridge", b"BridgePaused", true); - - // Do runtime upgrade - Upgrade::on_runtime_upgrade(); - assert_eq!(EthBridge::on_chain_storage_version(), 1); - - let pause_status = BridgePaused::::get(); - assert_eq!( - pause_status, - BridgePauseStatus { manual_pause: true, authorities_change: false } - ); - }); - } - } -}