Skip to content

Commit

Permalink
chore: remove the expiry storage from the swapping and lp pallets
Browse files Browse the repository at this point in the history
expiry is now done in the ingress-egress pallet
  • Loading branch information
kylezs committed Sep 26, 2023
1 parent 5cad7df commit 49d6e6b
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

7 changes: 6 additions & 1 deletion state-chain/pallets/cf-lp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ targets = ['x86_64-unknown-linux-gnu']
cf-chains = { path = '../../chains', default-features = false }
cf-primitives = { path = '../../primitives', default-features = false }
cf-traits = { path = '../../traits', default-features = false }
cf-runtime-upgrade-utilities = { path = '../../runtime-upgrade-utilities', default-features = false }

serde = { version = '1.0.126', default_features = false, features = [
'alloc',
Expand Down Expand Up @@ -49,6 +50,7 @@ std = [
'cf-chains/std',
'cf-primitives/std',
'cf-traits/std',
'cf-runtime-upgrade-utilities/std',
'codec/std',
'frame-benchmarking/std',
'frame-support/std',
Expand All @@ -66,4 +68,7 @@ runtime-benchmarks = [
'frame-system/runtime-benchmarks',
'pallet-cf-account-roles/runtime-benchmarks',
]
try-runtime = ['frame-support/try-runtime']
try-runtime = [
'cf-runtime-upgrade-utilities/try-runtime',
'frame-support/try-runtime',
]
4 changes: 4 additions & 0 deletions state-chain/pallets/cf-lp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ mod mock;
#[cfg(test)]
mod tests;

pub mod migrations;
pub mod weights;
pub use weights::WeightInfo;

pub const PALLET_VERSION: StorageVersion = StorageVersion::new(1);

impl_pallet_safe_mode!(PalletSafeMode; deposit_enabled, withdrawal_enabled);

#[frame_support::pallet]
Expand Down Expand Up @@ -113,6 +116,7 @@ pub mod pallet {
}

#[pallet::pallet]
#[pallet::storage_version(PALLET_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(PhantomData<T>);

Expand Down
6 changes: 6 additions & 0 deletions state-chain/pallets/cf-lp/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod remove_expiries;

use cf_runtime_upgrade_utilities::VersionedMigration;

pub type PalletMigration<T> =
(VersionedMigration<crate::Pallet<T>, remove_expiries::Migration<T>, 0, 1>,);
35 changes: 35 additions & 0 deletions state-chain/pallets/cf-lp/src/migrations/remove_expiries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::*;
use frame_support::{dispatch::Vec, traits::OnRuntimeUpgrade};
use sp_std::marker::PhantomData;

pub struct Migration<T: Config>(PhantomData<T>);

mod old {

use super::*;

use cf_primitives::ChannelId;
use frame_support::pallet_prelude::ValueQuery;

#[frame_support::storage_alias]
pub type SwapTTL<T: Config> = StorageValue<Pallet<T>, BlockNumberFor<T>, ValueQuery>;

#[frame_support::storage_alias]
pub type SwapChannelExpiries<T: Config> = StorageMap<
Pallet<T>,
Twox64Concat,
BlockNumberFor<T>,
Vec<(ChannelId, ForeignChainAddress)>,
ValueQuery,
>;
}

impl<T: Config> OnRuntimeUpgrade for Migration<T> {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
let _ = old::SwapChannelExpiries::<T>::drain().collect::<Vec<_>>();

let _ = old::SwapTTL::<T>::take();

Weight::zero()
}
}
7 changes: 6 additions & 1 deletion state-chain/pallets/cf-swapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ targets = ['x86_64-unknown-linux-gnu']
# Internal dependencies
cf-chains = { path = '../../chains', default-features = false }
cf-primitives = { path = '../../primitives', default-features = false }
cf-runtime-upgrade-utilities = { path = '../../runtime-upgrade-utilities', default-features = false }
cf-traits = { path = '../../traits', default-features = false }

log = { version = '0.4.16', default-features = false }
Expand Down Expand Up @@ -48,6 +49,7 @@ default = ['std']
std = [
'cf-chains/std',
'cf-primitives/std',
'cf-runtime-upgrade-utilities/std',
'cf-traits/std',
'codec/std',
'frame-benchmarking/std',
Expand All @@ -68,4 +70,7 @@ runtime-benchmarks = [
'frame-system/runtime-benchmarks',
'pallet-cf-account-roles/runtime-benchmarks',
]
try-runtime = ['frame-support/try-runtime']
try-runtime = [
'cf-runtime-upgrade-utilities/try-runtime',
'frame-support/try-runtime',
]
4 changes: 4 additions & 0 deletions state-chain/pallets/cf-swapping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ mod tests;

mod benchmarking;

pub mod migrations;
pub mod weights;
pub use weights::WeightInfo;

pub const PALLET_VERSION: StorageVersion = StorageVersion::new(1);

const BASIS_POINTS_PER_MILLION: u32 = 100;

#[derive(Clone, Debug, PartialEq, Eq, Encode, Decode, TypeInfo, MaxEncodedLen)]
Expand Down Expand Up @@ -202,6 +205,7 @@ pub mod pallet {
}

#[pallet::pallet]
#[pallet::storage_version(PALLET_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(PhantomData<T>);

Expand Down
6 changes: 6 additions & 0 deletions state-chain/pallets/cf-swapping/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod remove_expiries;

use cf_runtime_upgrade_utilities::VersionedMigration;

pub type PalletMigration<T> =
(VersionedMigration<crate::Pallet<T>, remove_expiries::Migration<T>, 0, 1>,);
34 changes: 34 additions & 0 deletions state-chain/pallets/cf-swapping/src/migrations/remove_expiries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::*;
use frame_support::traits::OnRuntimeUpgrade;
use sp_std::marker::PhantomData;

pub struct Migration<T: Config>(PhantomData<T>);

mod old {

use super::*;

use frame_support::pallet_prelude::ValueQuery;

#[frame_support::storage_alias]
pub type SwapTTL<T: Config> = StorageValue<Pallet<T>, BlockNumberFor<T>, ValueQuery>;

#[frame_support::storage_alias]
pub type SwapChannelExpiries<T: Config> = StorageMap<
Pallet<T>,
Twox64Concat,
BlockNumberFor<T>,
Vec<(ChannelId, ForeignChainAddress)>,
ValueQuery,
>;
}

impl<T: Config> OnRuntimeUpgrade for Migration<T> {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
let _ = old::SwapChannelExpiries::<T>::drain().collect::<Vec<_>>();

let _ = old::SwapTTL::<T>::take();

Weight::zero()
}
}

0 comments on commit 49d6e6b

Please sign in to comment.