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