cumulus_pallet_xcmp_queue/migration/
v6.rs1use crate::*;
20use frame_support::{pallet_prelude::*, traits::UncheckedOnRuntimeUpgrade};
21
22pub type MigrateV5ToV6<T> = frame_support::migrations::VersionedMigration<
25 5,
26 6,
27 unversioned::UncheckedMigrateV5ToV6<T>,
28 Pallet<T>,
29 <T as frame_system::Config>::DbWeight,
30>;
31
32mod v5 {
34 use super::*;
35
36 #[derive(Clone, Eq, PartialEq, Encode, Decode, TypeInfo, Debug, MaxEncodedLen)]
37 pub struct OutboundChannelDetails {
38 pub recipient: ParaId,
40 pub state: OutboundState,
42 pub signals_exist: bool,
44 pub first_index: u16,
46 pub last_index: u16,
48 }
49
50 #[frame_support::storage_alias]
51 pub(super) type OutboundXcmpStatus<T: Config> = StorageValue<
52 Pallet<T>,
53 BoundedVec<OutboundChannelDetails, <T as Config>::MaxActiveOutboundChannels>,
54 ValueQuery,
55 >;
56}
57
58mod unversioned {
59 use super::*;
60 pub struct UncheckedMigrateV5ToV6<T: Config>(PhantomData<T>);
61}
62
63impl<T: Config> UncheckedOnRuntimeUpgrade for unversioned::UncheckedMigrateV5ToV6<T> {
64 fn on_runtime_upgrade() -> frame_support::weights::Weight {
65 let translate = |pre: Vec<v5::OutboundChannelDetails>|
69 -> BoundedVec<OutboundChannelDetails, T::MaxActiveOutboundChannels> {
70 BoundedVec::defensive_truncate_from(
71 pre.iter()
72 .map(|pre_channel_details| OutboundChannelDetails {
73 recipient: pre_channel_details.recipient,
74 state: pre_channel_details.state,
75 signals_exist: pre_channel_details.signals_exist,
76 first_index: pre_channel_details.first_index,
77 last_index: pre_channel_details.last_index,
78 flags: OutboundChannelFlags::empty(),
80 })
81 .collect(),
82 )
83 };
84
85 if OutboundXcmpStatus::<T>::translate(|pre| pre.map(translate)).is_err() {
86 defensive!(
87 "unexpected error when performing translation of the OutboundXcmpStatus type \
88 during storage upgrade to v6"
89 );
90 }
91
92 let proof_size = 2 * BoundedVec::<
95 OutboundChannelDetails,
96 <T as Config>::MaxActiveOutboundChannels,
97 >::max_encoded_len();
98 Weight::from_parts(0, proof_size as u64)
99 .saturating_add(T::DbWeight::get().reads_writes(1, 1))
100 }
101}