diff --git a/crates/fee/src/lib.rs b/crates/fee/src/lib.rs index b5444fa9ee..c57968ac95 100644 --- a/crates/fee/src/lib.rs +++ b/crates/fee/src/lib.rs @@ -44,7 +44,7 @@ use sp_std::{ fmt::Debug, }; use staking::StakingApi; -use types::{BalanceOf, DefaultVaultCurrencyPair, DefaultVaultId, UnsignedFixedPoint, Version}; +use types::{BalanceOf, DefaultVaultCurrencyPair, DefaultVaultId, UnsignedFixedPoint}; #[frame_support::pallet] pub mod pallet { @@ -156,16 +156,6 @@ pub mod pallet { #[pallet::getter(fn replace_griefing_collateral)] pub type ReplaceGriefingCollateral = StorageValue<_, UnsignedFixedPoint, ValueQuery>; - #[pallet::type_value] - pub(super) fn DefaultForStorageVersion() -> Version { - Version::V0 - } - - /// Build storage at V1 (requires default 0). - #[pallet::storage] - #[pallet::getter(fn storage_version)] - pub(super) type StorageVersion = StorageValue<_, Version, ValueQuery, DefaultForStorageVersion>; - /// The fraction up rewards going straight to the vault operator. The rest goes to the vault's pool. #[pallet::storage] pub(super) type Commission = @@ -207,7 +197,11 @@ pub mod pallet { } } + /// The current storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); + #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); // The pallet's dispatchable functions. diff --git a/crates/issue/src/lib.rs b/crates/issue/src/lib.rs index 4ac852d942..c6eef06ec4 100644 --- a/crates/issue/src/lib.rs +++ b/crates/issue/src/lib.rs @@ -70,6 +70,14 @@ pub mod pallet { type WeightInfo: WeightInfo; } + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_runtime_upgrade() -> Weight { + StorageVersion::new(Version::V4 as u16).put::>(); + Default::default() + } + } + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { @@ -148,16 +156,6 @@ pub mod pallet { #[pallet::storage] pub(super) type IssueBtcDustValue = StorageValue<_, BalanceOf, ValueQuery>; - #[pallet::type_value] - pub(super) fn DefaultForStorageVersion() -> Version { - Version::V4 - } - - /// Build storage at V1 (requires default 0). - #[pallet::storage] - #[pallet::getter(fn storage_version)] - pub(super) type StorageVersion = StorageValue<_, Version, ValueQuery, DefaultForStorageVersion>; - #[pallet::genesis_config] pub struct GenesisConfig { pub issue_period: T::BlockNumber, @@ -182,7 +180,11 @@ pub mod pallet { } } + /// The current storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); + #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); // The pallet's dispatchable functions. diff --git a/crates/issue/src/types.rs b/crates/issue/src/types.rs index d1d1cadb2c..d7dc926623 100644 --- a/crates/issue/src/types.rs +++ b/crates/issue/src/types.rs @@ -11,15 +11,15 @@ use crate::Config; #[derive(Encode, Decode, Eq, PartialEq, TypeInfo, MaxEncodedLen)] pub enum Version { /// Initial version. - V0, + V0 = 0, /// BtcAddress type with script format. - V1, + V1 = 1, /// IssueRequestStatus - V2, + V2 = 2, /// ActiveBlockNumber, btc_height - V3, + V3 = 3, /// Removed refund - V4, + V4 = 4, } pub(crate) type BalanceOf = ::Balance; diff --git a/crates/oracle/src/lib.rs b/crates/oracle/src/lib.rs index 177a0530a8..43b49adb30 100644 --- a/crates/oracle/src/lib.rs +++ b/crates/oracle/src/lib.rs @@ -27,7 +27,7 @@ extern crate mocktopus; #[cfg(test)] use mocktopus::macros::mockable; -use crate::types::{BalanceOf, UnsignedFixedPoint, Version}; +use crate::types::{BalanceOf, UnsignedFixedPoint}; use codec::{Decode, Encode, MaxEncodedLen}; use currency::Amount; use frame_support::{ @@ -153,16 +153,6 @@ pub mod pallet { #[pallet::getter(fn authorized_oracles)] pub type AuthorizedOracles = StorageMap<_, Blake2_128Concat, T::AccountId, NameOf, ValueQuery>; - #[pallet::type_value] - pub(super) fn DefaultForStorageVersion() -> Version { - Version::V0 - } - - /// Build storage at V1 (requires default 0). - #[pallet::storage] - #[pallet::getter(fn storage_version)] - pub(super) type StorageVersion = StorageValue<_, Version, ValueQuery, DefaultForStorageVersion>; - #[pallet::genesis_config] pub struct GenesisConfig { pub max_delay: u32, @@ -192,7 +182,11 @@ pub mod pallet { } } + /// The current storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); + #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); // The pallet's dispatchable functions. diff --git a/crates/redeem/src/lib.rs b/crates/redeem/src/lib.rs index e580d02f97..db65c47ad5 100644 --- a/crates/redeem/src/lib.rs +++ b/crates/redeem/src/lib.rs @@ -29,7 +29,7 @@ pub mod types; #[doc(inline)] pub use crate::types::{DefaultRedeemRequest, RedeemRequest, RedeemRequestStatus}; -use crate::types::{BalanceOf, RedeemRequestExt, Version}; +use crate::types::{BalanceOf, RedeemRequestExt}; use bitcoin::types::{MerkleProof, Transaction}; use btc_relay::BtcAddress; use currency::Amount; @@ -163,16 +163,6 @@ pub mod pallet { #[pallet::getter(fn redeem_transaction_size)] pub(super) type RedeemTransactionSize = StorageValue<_, u32, ValueQuery>; - #[pallet::type_value] - pub(super) fn DefaultForStorageVersion() -> Version { - Version::V0 - } - - /// Build storage at V1 (requires default 0). - #[pallet::storage] - #[pallet::getter(fn storage_version)] - pub(super) type StorageVersion = StorageValue<_, Version, ValueQuery, DefaultForStorageVersion>; - #[pallet::genesis_config] pub struct GenesisConfig { pub redeem_period: T::BlockNumber, @@ -203,7 +193,11 @@ pub mod pallet { #[pallet::hooks] impl Hooks for Pallet {} + /// The current storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); + #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); // The pallet's dispatchable functions. diff --git a/crates/redeem/src/types.rs b/crates/redeem/src/types.rs index c14ddc4c6a..b48eca39eb 100644 --- a/crates/redeem/src/types.rs +++ b/crates/redeem/src/types.rs @@ -1,20 +1,11 @@ pub use primitives::redeem::{RedeemRequest, RedeemRequestStatus}; use primitives::VaultId; -use scale_info::TypeInfo; use sp_runtime::DispatchError; use vault_registry::types::CurrencyId; use crate::Config; -use codec::{Decode, Encode, MaxEncodedLen}; use currency::Amount; -/// Storage version. -#[derive(Encode, Decode, Eq, PartialEq, TypeInfo, MaxEncodedLen)] -pub enum Version { - /// Initial version. - V0, -} - pub(crate) type BalanceOf = ::Balance; pub(crate) type DefaultVaultId = VaultId<::AccountId, CurrencyId>; diff --git a/crates/replace/src/lib.rs b/crates/replace/src/lib.rs index dfac8e5971..f9362cfda0 100644 --- a/crates/replace/src/lib.rs +++ b/crates/replace/src/lib.rs @@ -25,7 +25,7 @@ extern crate mocktopus; #[cfg(test)] use mocktopus::macros::mockable; -use crate::types::{BalanceOf, ReplaceRequestExt, Version}; +use crate::types::{BalanceOf, ReplaceRequestExt}; pub use crate::types::{DefaultReplaceRequest, ReplaceRequest, ReplaceRequestStatus}; use bitcoin::types::{MerkleProof, Transaction}; use btc_relay::BtcAddress; @@ -153,16 +153,6 @@ pub mod pallet { #[pallet::getter(fn replace_btc_dust_value)] pub(super) type ReplaceBtcDustValue = StorageValue<_, BalanceOf, ValueQuery>; - #[pallet::type_value] - pub(super) fn DefaultForStorageVersion() -> Version { - Version::V0 - } - - /// Build storage at V1 (requires default 0). - #[pallet::storage] - #[pallet::getter(fn storage_version)] - pub(super) type StorageVersion = StorageValue<_, Version, ValueQuery, DefaultForStorageVersion>; - #[pallet::genesis_config] pub struct GenesisConfig { pub replace_period: T::BlockNumber, @@ -190,7 +180,11 @@ pub mod pallet { #[pallet::hooks] impl Hooks for Pallet {} + /// The current storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); + #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); // The pallet's dispatchable functions. diff --git a/crates/vault-registry/src/lib.rs b/crates/vault-registry/src/lib.rs index 7fa02c72a8..52ccf2358b 100644 --- a/crates/vault-registry/src/lib.rs +++ b/crates/vault-registry/src/lib.rs @@ -74,7 +74,11 @@ pub mod pallet { use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; + /// The current storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(6); + #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); #[pallet::config] @@ -634,16 +638,6 @@ pub mod pallet { pub(super) type TotalUserVaultCollateral = StorageMap<_, Blake2_128Concat, DefaultVaultCurrencyPair, BalanceOf, ValueQuery>; - #[pallet::type_value] - pub(super) fn DefaultForStorageVersion() -> Version { - Version::V6 - } - - /// Pallet storage version - #[pallet::storage] - #[pallet::getter(fn storage_version)] - pub(super) type StorageVersion = StorageValue<_, Version, ValueQuery, DefaultForStorageVersion>; - #[pallet::genesis_config] pub struct GenesisConfig { pub minimum_collateral_vault: Vec<(CurrencyId, BalanceOf)>, @@ -687,7 +681,8 @@ pub mod pallet { for (currency_pair, threshold) in self.liquidation_collateral_threshold.iter() { LiquidationCollateralThreshold::::insert(currency_pair, threshold); } - StorageVersion::::put(Version::V3); + + StorageVersion::new(Version::V6 as u16).put::>(); } } } diff --git a/crates/vault-registry/src/types.rs b/crates/vault-registry/src/types.rs index fe2e967493..3fa8923dff 100644 --- a/crates/vault-registry/src/types.rs +++ b/crates/vault-registry/src/types.rs @@ -23,19 +23,19 @@ pub use bitcoin::{Address as BtcAddress, PublicKey as BtcPublicKey}; #[derive(Encode, Decode, Eq, PartialEq, TypeInfo, MaxEncodedLen)] pub enum Version { /// Initial version. - V0, + V0 = 0, /// BtcAddress type with script format. - V1, + V1 = 1, /// added replace_collateral to vault, changed vaultStatus enum - V2, + V2 = 2, /// moved public_key out of the vault struct - V3, + V3 = 3, /// Fixed liquidation vault - V4, + V4 = 4, /// Added custom pervault secure collateral threshold - V5, + V5 = 5, /// Removed wallet - V6, + V6 = 6, } #[derive(Debug, PartialEq)] @@ -110,16 +110,20 @@ pub type DefaultVaultId = VaultId<::AccountId, Cur pub type DefaultVaultCurrencyPair = VaultCurrencyPair>; pub mod v1 { + use frame_support::{dispatch::GetStorageVersion, traits::StorageVersion}; + use super::*; pub fn migrate_v1_to_v6() -> frame_support::weights::Weight { // kintsugi is on V6 but interlay is still on V1 - if !matches!(crate::StorageVersion::::get(), Version::V1) { + let current_storage_version = Pallet::::current_storage_version(); + let _expected_storage_version = Version::V1 as u16; + if !matches!(current_storage_version, _expected_storage_version) { log::info!("Not running vault storage migration"); return T::DbWeight::get().reads(1); // already upgraded; don't run migration } // nothing to do other than update version - crate::StorageVersion::::put(Version::V6); + StorageVersion::new(Version::V6 as u16).put::>(); T::DbWeight::get().reads_writes(0, 1) } }