Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
f-gate committed Dec 6, 2023
1 parent 4d7810d commit 41f2e73
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
6 changes: 4 additions & 2 deletions pallets/briefs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub use pallet::*;
pub mod weights;
pub use weights::*;

pub mod migrations;

#[cfg(test)]
mod mock;

Expand Down Expand Up @@ -57,12 +59,12 @@ pub mod pallet {
BalanceOf<T>,
AccountIdOf<T>,
>>::StorageItem;
type DepositIdOf<T> =
pub(crate) type DepositIdOf<T> =
<<T as Config>::DepositHandler as DepositHandler<BalanceOf<T>, AccountIdOf<T>>>::DepositId;

pub type BriefHash = H256;

const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);
const STORAGE_VERSION: StorageVersion = StorageVersion::new(3);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
Expand Down
36 changes: 28 additions & 8 deletions pallets/briefs/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ mod v0 {
#[allow(dead_code)]
pub(crate) mod v1 {
use super::*;


pub fn migrate_to_v1<T: Config>(weight: &mut Weight) {
if v2::StorageVersion::<T>::get() == v2::Release::V0 {
crate::Briefs::<T>::translate(|_, brief: v0::BriefDataV0<T>| {
v2::BriefsV2::<T>::translate(|_, brief: v0::BriefDataV0<T>| {
*weight += T::DbWeight::get().reads_writes(2, 1);
let maybe_milestones: Result<BoundedProposedMilestones<T>, _> = brief
.milestones
Expand All @@ -69,7 +71,7 @@ pub(crate) mod v1 {
if milestones.len() != brief.milestones.len() {
return None;
}
Some(crate::BriefData {
Some(v2::BriefDataV2 {
brief_owners: brief.brief_owners,
budget: brief.budget,
currency_id: brief.currency_id,
Expand All @@ -91,6 +93,24 @@ pub(crate) mod v1 {
pub mod v2 {
use super::*;

#[storage_alias]
pub type BriefsV2<T: Config> =
CountedStorageMap<Pallet<T>, Blake2_128Concat, BriefHash, BriefDataV2<T>, OptionQuery>;


#[derive(Encode, Decode, PartialEq, Eq, Clone, Debug, MaxEncodedLen, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct BriefDataV2<T: Config> {
pub brief_owners: BoundedBriefOwners<T>,
pub budget: BalanceOf<T>,
pub currency_id: CurrencyId,
pub created_at: BlockNumberFor<T>,
pub applicant: AccountIdOf<T>,
pub milestones: BoundedProposedMilestones<T>,
pub deposit_id: crate::DepositIdOf<T>,
}


#[storage_alias]
pub type StorageVersion<T: Config> = StorageValue<Pallet<T>, Release, ValueQuery>;

Expand Down Expand Up @@ -151,17 +171,17 @@ pub mod v3 {
use super::*;

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

fn on_runtime_upgrade() -> Weight {
let current = Pallet::<T>::current_storage_version();
let onchain = StorageVersion::<T>::on_chain_storage_version();
let onchain = Pallet::<T>::on_chain_storage_version();
let mut weight: Weight = Default::default();
if current == 3 && onchain == 2 {

Expand All @@ -177,9 +197,9 @@ pub mod v3 {
eoa: None,
};

T::DbWeight::get().reads_writes(2, 2)
T::DbWeight::get().reads_writes(2, 2);
Briefs::<T>::insert(key, migrated_brief);
})
});

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

Expand Down
2 changes: 1 addition & 1 deletion pallets/proposals/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ pub mod v7 {
});

ensure!(
Pallet::<T>::current_storage_version() == 7,
Pallet::<T>::on_chain_storage_version() == 7,
"Storage version should be v7 after the migration"
);

Expand Down
2 changes: 1 addition & 1 deletion runtime/imbue-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub mod migrations {
use super::*;
/// Unreleased migrations. Add new ones here:
pub type Unreleased = (
pallet_briefs::migration::v3::MigrateToV3<Runtime>,
pallet_briefs::migrations::v3::MigrateToV3<Runtime>,
pallet_fellowship::migration::v0::MigrateInitial<Runtime>,
pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckingAccount>,
pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
Expand Down

0 comments on commit 41f2e73

Please sign in to comment.