Skip to content

Commit

Permalink
implement type that set the proper storage version for pallet vesting…
Browse files Browse the repository at this point in the history
… and transaction payment
  • Loading branch information
gianfra-t committed Jan 11, 2024
1 parent a54632c commit 22e3c3c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
2 changes: 2 additions & 0 deletions frame/transaction-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ mod tests;
mod payment;
mod types;

pub mod migrations;

pub use pallet::*;
pub use payment::*;
pub use types::{FeeDetails, InclusionFee, RuntimeDispatchInfo};
Expand Down
22 changes: 22 additions & 0 deletions frame/transaction-payment/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@



// temporary code to set the migration to V1
pub mod v1 {
use super::*;

/// Manually setting the version to V1
pub struct ForceSetVersionToV2<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for ForceSetVersionToV2<T> {
fn on_runtime_upgrade() -> Weight {

if StorageVersion::<T>::get() == Releases::V1 {
StorageVersion::<T>::put(Releases::V1Ancient);
}

T::DbWeight::get().reads_writes(1, 1)
}

}

}
37 changes: 11 additions & 26 deletions frame/vesting/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,18 @@ pub mod v1 {
Ok(())
}

/// Migrate from single schedule to multi schedule storage.
/// WARNING: This migration will delete schedules if `MaxVestingSchedules < 1`.
pub fn migrate<T: Config>() -> Weight {
let mut reads_writes = 0;
/// Manually setting the version to V1
pub struct ForceSetVersionToV1<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for ForceSetVersionToV1<T> {
fn on_runtime_upgrade() -> Weight {

Vesting::<T>::translate::<VestingInfo<BalanceOf<T>, T::BlockNumber>, _>(
|_key, vesting_info| {
reads_writes += 1;
let v: Option<
BoundedVec<
VestingInfo<BalanceOf<T>, T::BlockNumber>,
MaxVestingSchedulesGet<T>,
>,
> = vec![vesting_info].try_into().ok();

if v.is_none() {
log::warn!(
target: "runtime::vesting",
"migration: Failed to move a vesting schedule into a BoundedVec"
);
}

v
},
);

T::DbWeight::get().reads_writes(reads_writes, reads_writes)
if StorageVersion::<T>::get() == Releases::V0 {
StorageVersion::<T>::put(Releases::V1);
}

T::DbWeight::get().reads_writes(1, 1)
}

}

#[cfg(feature = "try-runtime")]
Expand Down

0 comments on commit 22e3c3c

Please sign in to comment.