Skip to content

Commit 41f2e73

Browse files
committed
fixes
1 parent 4d7810d commit 41f2e73

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

pallets/briefs/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ pub use pallet::*;
55
pub mod weights;
66
pub use weights::*;
77

8+
pub mod migrations;
9+
810
#[cfg(test)]
911
mod mock;
1012

@@ -57,12 +59,12 @@ pub mod pallet {
5759
BalanceOf<T>,
5860
AccountIdOf<T>,
5961
>>::StorageItem;
60-
type DepositIdOf<T> =
62+
pub(crate) type DepositIdOf<T> =
6163
<<T as Config>::DepositHandler as DepositHandler<BalanceOf<T>, AccountIdOf<T>>>::DepositId;
6264

6365
pub type BriefHash = H256;
6466

65-
const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);
67+
const STORAGE_VERSION: StorageVersion = StorageVersion::new(3);
6668

6769
#[pallet::pallet]
6870
#[pallet::storage_version(STORAGE_VERSION)]

pallets/briefs/src/migrations.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ mod v0 {
4545
#[allow(dead_code)]
4646
pub(crate) mod v1 {
4747
use super::*;
48+
49+
4850
pub fn migrate_to_v1<T: Config>(weight: &mut Weight) {
4951
if v2::StorageVersion::<T>::get() == v2::Release::V0 {
50-
crate::Briefs::<T>::translate(|_, brief: v0::BriefDataV0<T>| {
52+
v2::BriefsV2::<T>::translate(|_, brief: v0::BriefDataV0<T>| {
5153
*weight += T::DbWeight::get().reads_writes(2, 1);
5254
let maybe_milestones: Result<BoundedProposedMilestones<T>, _> = brief
5355
.milestones
@@ -69,7 +71,7 @@ pub(crate) mod v1 {
6971
if milestones.len() != brief.milestones.len() {
7072
return None;
7173
}
72-
Some(crate::BriefData {
74+
Some(v2::BriefDataV2 {
7375
brief_owners: brief.brief_owners,
7476
budget: brief.budget,
7577
currency_id: brief.currency_id,
@@ -91,6 +93,24 @@ pub(crate) mod v1 {
9193
pub mod v2 {
9294
use super::*;
9395

96+
#[storage_alias]
97+
pub type BriefsV2<T: Config> =
98+
CountedStorageMap<Pallet<T>, Blake2_128Concat, BriefHash, BriefDataV2<T>, OptionQuery>;
99+
100+
101+
#[derive(Encode, Decode, PartialEq, Eq, Clone, Debug, MaxEncodedLen, TypeInfo)]
102+
#[scale_info(skip_type_params(T))]
103+
pub struct BriefDataV2<T: Config> {
104+
pub brief_owners: BoundedBriefOwners<T>,
105+
pub budget: BalanceOf<T>,
106+
pub currency_id: CurrencyId,
107+
pub created_at: BlockNumberFor<T>,
108+
pub applicant: AccountIdOf<T>,
109+
pub milestones: BoundedProposedMilestones<T>,
110+
pub deposit_id: crate::DepositIdOf<T>,
111+
}
112+
113+
94114
#[storage_alias]
95115
pub type StorageVersion<T: Config> = StorageValue<Pallet<T>, Release, ValueQuery>;
96116

@@ -151,17 +171,17 @@ pub mod v3 {
151171
use super::*;
152172

153173
pub struct MigrateToV3<T: Config>(T);
154-
impl<T: Config> OnRuntimeUpgrade for MigrateToV2<T> {
174+
impl<T: Config> OnRuntimeUpgrade for MigrateToV3<T> {
155175
#[cfg(feature = "try-runtime")]
156176
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
157-
let onchain = StorageVersion::<T>::on_chain_storage_version();
158-
ensure!(onchain == 2, "onchain must be version 2 to run the migration.")
177+
let onchain = Pallet::<T>::on_chain_storage_version();
178+
ensure!(onchain == 2, "onchain must be version 2 to run the migration.");
159179
Ok(<Vec<u8> as Default>::default())
160180
}
161181

162182
fn on_runtime_upgrade() -> Weight {
163183
let current = Pallet::<T>::current_storage_version();
164-
let onchain = StorageVersion::<T>::on_chain_storage_version();
184+
let onchain = Pallet::<T>::on_chain_storage_version();
165185
let mut weight: Weight = Default::default();
166186
if current == 3 && onchain == 2 {
167187

@@ -177,9 +197,9 @@ pub mod v3 {
177197
eoa: None,
178198
};
179199

180-
T::DbWeight::get().reads_writes(2, 2)
200+
T::DbWeight::get().reads_writes(2, 2);
181201
Briefs::<T>::insert(key, migrated_brief);
182-
})
202+
});
183203

184204
current.put::<Pallet<T>>();
185205

pallets/proposals/src/migration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ pub mod v7 {
776776
});
777777

778778
ensure!(
779-
Pallet::<T>::current_storage_version() == 7,
779+
Pallet::<T>::on_chain_storage_version() == 7,
780780
"Storage version should be v7 after the migration"
781781
);
782782

runtime/imbue-kusama/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ pub mod migrations {
181181
use super::*;
182182
/// Unreleased migrations. Add new ones here:
183183
pub type Unreleased = (
184-
pallet_briefs::migration::v3::MigrateToV3<Runtime>,
184+
pallet_briefs::migrations::v3::MigrateToV3<Runtime>,
185185
pallet_fellowship::migration::v0::MigrateInitial<Runtime>,
186186
pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckingAccount>,
187187
pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,

0 commit comments

Comments
 (0)