From 66a3ce74a5a5da5d9b7febc787f3721504bcd06b Mon Sep 17 00:00:00 2001 From: SunTiebing <87381708+SunTiebing@users.noreply.github.com> Date: Fri, 21 Jun 2024 09:46:28 +0800 Subject: [PATCH] fix bug: storage migration anomaly (#1276) * SLPx mint support commission id * remove the channel_id parameter from the mint method * add mint_with_channel_id method * perform data migration for OrderQueue storage * slpx: set the default value of channel_id to 0 * resolve conflicts * change the location of the old data structure during storage migration * fix bug: storage migration anomaly --- pallets/slpx/src/migration.rs | 47 ++++++++++++++++------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/pallets/slpx/src/migration.rs b/pallets/slpx/src/migration.rs index 934c227ef..a0c5945b2 100644 --- a/pallets/slpx/src/migration.rs +++ b/pallets/slpx/src/migration.rs @@ -106,7 +106,7 @@ mod v0 { } pub mod v1 { - use frame_support::traits::StorageVersion; + use frame_support::pallet_prelude::StorageVersion; use super::*; @@ -146,32 +146,29 @@ pub fn migrate_to_v1() -> Weight { let mut weight: Weight = Weight::zero(); let old_orders = v0::OrderQueue::::get(); - - let mut new_orders: BoundedVec<_, ConstU32<1000>> = BoundedVec::default(); for old_order in old_orders.into_iter() { - new_orders - .try_push(Order { - source_chain_caller: old_order.source_chain_caller, - bifrost_chain_caller: old_order.bifrost_chain_caller, - derivative_account: old_order.derivative_account, - create_block_number: old_order.create_block_number, - currency_id: old_order.currency_id, - currency_amount: old_order.currency_amount, - order_type: old_order.order_type, - remark: old_order.remark, - target_chain: old_order.target_chain, - // default to 0 - channel_id: 0u32, - }) - .expect("BoundedVec should not overflow"); - weight = weight.saturating_add(T::DbWeight::get().reads_writes(0, 1)); + let order = Order { + source_chain_caller: old_order.source_chain_caller, + bifrost_chain_caller: old_order.bifrost_chain_caller, + derivative_account: old_order.derivative_account, + create_block_number: old_order.create_block_number, + currency_id: old_order.currency_id, + currency_amount: old_order.currency_amount, + order_type: old_order.order_type, + remark: old_order.remark, + target_chain: old_order.target_chain, + // default to 0 + channel_id: 0u32, + }; + + OrderQueue::::mutate(|order_queue| -> DispatchResultWithPostInfo { + order_queue.try_push(order.clone()).map_err(|_| Error::::ArgumentsError)?; + Ok(().into()) + }) + .expect("BoundedVec should not overflow"); + + weight = weight.saturating_add(T::DbWeight::get().writes(1)); } - OrderQueue::::put(new_orders); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - - v0::OrderQueue::::kill(); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - weight }