Skip to content

Commit

Permalink
remove old migrations and bump up versions
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Mar 15, 2024
1 parent 79ce288 commit a4eb604
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 2,032 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

130 changes: 0 additions & 130 deletions pallets/block-rewards/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,133 +164,3 @@ pub mod init {
}
}
}

pub mod v2 {
use frame_support::{
pallet_prelude::ValueQuery, storage_alias, DefaultNoBound, RuntimeDebugNoBound,
};
use parity_scale_codec::MaxEncodedLen;
use scale_info::TypeInfo;

use super::*;
use crate::{CollatorChanges, SessionChanges};

const LOG_PREFIX: &str = "RelativeTreasuryInflation";

#[derive(
Encode, Decode, TypeInfo, DefaultNoBound, MaxEncodedLen, PartialEq, Eq, RuntimeDebugNoBound,
)]
#[scale_info(skip_type_params(T))]
struct OldSessionData<T: Config> {
pub collator_reward: T::Balance,
pub total_reward: T::Balance,
pub collator_count: u32,
}

#[derive(
PartialEq,
Clone,
DefaultNoBound,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
RuntimeDebugNoBound,
)]
#[scale_info(skip_type_params(T))]
struct OldSessionChanges<T: Config> {
pub collators: CollatorChanges<T>,
pub collator_count: Option<u32>,
pub collator_reward: Option<T::Balance>,
pub total_reward: Option<T::Balance>,
}

#[storage_alias]
type ActiveSessionData<T: Config> = StorageValue<Pallet<T>, OldSessionData<T>, ValueQuery>;
#[storage_alias]
type NextSessionChanges<T: Config> = StorageValue<Pallet<T>, OldSessionChanges<T>, ValueQuery>;

pub struct RelativeTreasuryInflationMigration<T, InflationRate>(
PhantomData<(T, InflationRate)>,
);

impl<T, InflationPercentage> OnRuntimeUpgrade
for RelativeTreasuryInflationMigration<T, InflationPercentage>
where
T: Config,
InflationPercentage: Get<u32>,
{
fn on_runtime_upgrade() -> Weight {
if Pallet::<T>::on_chain_storage_version() == StorageVersion::new(1) {
let active = ActiveSessionData::<T>::take();
let next = NextSessionChanges::<T>::take();

pallet::ActiveSessionData::<T>::put(SessionData {
collator_reward: active.collator_reward,
collator_count: active.collator_count,
treasury_inflation_rate: inflation_rate::<T>(InflationPercentage::get()),
last_update: T::Time::now(),
});
log::info!("{LOG_PREFIX} Translated ActiveSessionData");

pallet::NextSessionChanges::<T>::put(SessionChanges {
collators: next.collators,
collator_count: next.collator_count,
collator_reward: next.collator_reward,
treasury_inflation_rate: Some(inflation_rate::<T>(InflationPercentage::get())),
last_update: T::Time::now(),
});
log::info!("{LOG_PREFIX} Translated NextSessionChanges");
Pallet::<T>::current_storage_version().put::<Pallet<T>>();

T::DbWeight::get().reads_writes(1, 5)
} else {
log::info!("{LOG_PREFIX} BlockRewards pallet already on version 2, migration can be removed");
T::DbWeight::get().reads(1)
}
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
assert_eq!(
Pallet::<T>::on_chain_storage_version(),
StorageVersion::new(1),
);
assert!(
Pallet::<T>::on_chain_storage_version() < Pallet::<T>::current_storage_version()
);

let active = ActiveSessionData::<T>::get();
let next = NextSessionChanges::<T>::get();

log::info!("{LOG_PREFIX} PRE UPGRADE: Finished");

Ok((active, next).encode())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(pre_state: Vec<u8>) -> Result<(), TryRuntimeError> {
let (old_active, old_next): (OldSessionData<T>, OldSessionChanges<T>) =
Decode::decode(&mut pre_state.as_slice()).expect("Pre state valid; qed");
let active = pallet::ActiveSessionData::<T>::get();
let next = pallet::NextSessionChanges::<T>::get();

assert_eq!(old_active.collator_reward, active.collator_reward);
assert_eq!(old_active.collator_count, active.collator_count);
assert_eq!(old_next.collators, next.collators);
assert_eq!(old_next.collator_count, next.collator_count);
assert_eq!(old_next.collator_reward, next.collator_reward);
assert_eq!(
next.treasury_inflation_rate,
Some(inflation_rate::<T>(InflationPercentage::get()))
);
assert_eq!(
Pallet::<T>::current_storage_version(),
Pallet::<T>::on_chain_storage_version()
);

log::info!("{LOG_PREFIX} POST UPGRADE: Finished");
Ok(())
}
}
}
2 changes: 1 addition & 1 deletion runtime/altair/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "altair-runtime"
version = "0.10.34"
version = "0.10.35"
build = "build.rs"
authors.workspace = true
edition.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions runtime/altair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("altair"),
impl_name: create_runtime_str!("altair"),
authoring_version: 1,
spec_version: 1034,
spec_version: 1035,
impl_version: 1,
#[cfg(not(feature = "disable-runtime-api"))]
apis: RUNTIME_API_VERSIONS,
Expand Down Expand Up @@ -1946,7 +1946,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
migrations::UpgradeAltair1034,
migrations::UpgradeAltair1035,
>;

// Frame Order in this block dictates the index of each one in the metadata
Expand Down
Loading

0 comments on commit a4eb604

Please sign in to comment.