From 7df1ccbc5c435930f5e7c6077e1dbf88ea064ba5 Mon Sep 17 00:00:00 2001 From: nakul1010 Date: Mon, 26 Jun 2023 11:12:24 +0530 Subject: [PATCH 1/7] fix: changed storage version for fee, issue, oracle, redeem and replace pallets. --- crates/fee/src/lib.rs | 9 ++++----- crates/issue/src/lib.rs | 8 ++++---- crates/oracle/src/lib.rs | 8 ++++---- crates/redeem/src/lib.rs | 10 +++++----- crates/redeem/src/types.rs | 1 + crates/replace/src/lib.rs | 8 ++++---- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/crates/fee/src/lib.rs b/crates/fee/src/lib.rs index b5444fa9ee..7e4c1d2fbf 100644 --- a/crates/fee/src/lib.rs +++ b/crates/fee/src/lib.rs @@ -161,11 +161,6 @@ pub mod pallet { 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 +202,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..7cd68935ec 100644 --- a/crates/issue/src/lib.rs +++ b/crates/issue/src/lib.rs @@ -153,10 +153,6 @@ pub mod pallet { 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 { @@ -182,7 +178,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/oracle/src/lib.rs b/crates/oracle/src/lib.rs index 177a0530a8..b2486b3ee5 100644 --- a/crates/oracle/src/lib.rs +++ b/crates/oracle/src/lib.rs @@ -158,10 +158,6 @@ pub mod pallet { 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 { @@ -192,7 +188,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..1a61f3e4f3 100644 --- a/crates/redeem/src/lib.rs +++ b/crates/redeem/src/lib.rs @@ -168,11 +168,6 @@ pub mod pallet { 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,9 +198,14 @@ 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. #[pallet::call] impl Pallet { diff --git a/crates/redeem/src/types.rs b/crates/redeem/src/types.rs index c14ddc4c6a..0992b1c9e3 100644 --- a/crates/redeem/src/types.rs +++ b/crates/redeem/src/types.rs @@ -8,6 +8,7 @@ use crate::Config; use codec::{Decode, Encode, MaxEncodedLen}; use currency::Amount; +// ToDo: remove this permanently /// Storage version. #[derive(Encode, Decode, Eq, PartialEq, TypeInfo, MaxEncodedLen)] pub enum Version { diff --git a/crates/replace/src/lib.rs b/crates/replace/src/lib.rs index dfac8e5971..00ee8caf3b 100644 --- a/crates/replace/src/lib.rs +++ b/crates/replace/src/lib.rs @@ -158,10 +158,6 @@ pub mod pallet { 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 { @@ -190,7 +186,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. From fa728c572f6c943e5fc411f87557c4f78125c1bf Mon Sep 17 00:00:00 2001 From: nakul1010 Date: Mon, 26 Jun 2023 11:16:46 +0530 Subject: [PATCH 2/7] ci: code formatted. --- crates/issue/src/lib.rs | 1 - crates/oracle/src/lib.rs | 1 - crates/redeem/src/lib.rs | 1 - crates/replace/src/lib.rs | 1 - 4 files changed, 4 deletions(-) diff --git a/crates/issue/src/lib.rs b/crates/issue/src/lib.rs index 7cd68935ec..a6d667dd9b 100644 --- a/crates/issue/src/lib.rs +++ b/crates/issue/src/lib.rs @@ -153,7 +153,6 @@ pub mod pallet { Version::V4 } - #[pallet::genesis_config] pub struct GenesisConfig { pub issue_period: T::BlockNumber, diff --git a/crates/oracle/src/lib.rs b/crates/oracle/src/lib.rs index b2486b3ee5..8c07859061 100644 --- a/crates/oracle/src/lib.rs +++ b/crates/oracle/src/lib.rs @@ -158,7 +158,6 @@ pub mod pallet { Version::V0 } - #[pallet::genesis_config] pub struct GenesisConfig { pub max_delay: u32, diff --git a/crates/redeem/src/lib.rs b/crates/redeem/src/lib.rs index 1a61f3e4f3..4110340ef6 100644 --- a/crates/redeem/src/lib.rs +++ b/crates/redeem/src/lib.rs @@ -205,7 +205,6 @@ pub mod pallet { #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); - // The pallet's dispatchable functions. #[pallet::call] impl Pallet { diff --git a/crates/replace/src/lib.rs b/crates/replace/src/lib.rs index 00ee8caf3b..01c740752e 100644 --- a/crates/replace/src/lib.rs +++ b/crates/replace/src/lib.rs @@ -158,7 +158,6 @@ pub mod pallet { Version::V0 } - #[pallet::genesis_config] pub struct GenesisConfig { pub replace_period: T::BlockNumber, From 6b1eca67655507ee71bc1e3b8db91ce835a885f8 Mon Sep 17 00:00:00 2001 From: nakul1010 Date: Mon, 26 Jun 2023 11:29:37 +0530 Subject: [PATCH 3/7] fix: removed unused Version DefaultForStorageVersion type value. --- crates/fee/src/lib.rs | 7 +------ crates/issue/src/lib.rs | 9 ++------- crates/oracle/src/lib.rs | 7 +------ crates/redeem/src/lib.rs | 7 +------ crates/replace/src/lib.rs | 7 +------ 5 files changed, 6 insertions(+), 31 deletions(-) diff --git a/crates/fee/src/lib.rs b/crates/fee/src/lib.rs index 7e4c1d2fbf..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,11 +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 - } - /// The fraction up rewards going straight to the vault operator. The rest goes to the vault's pool. #[pallet::storage] pub(super) type Commission = diff --git a/crates/issue/src/lib.rs b/crates/issue/src/lib.rs index a6d667dd9b..ad587043ce 100644 --- a/crates/issue/src/lib.rs +++ b/crates/issue/src/lib.rs @@ -31,7 +31,7 @@ pub mod types; #[doc(inline)] pub use crate::types::{DefaultIssueRequest, IssueRequest, IssueRequestStatus}; -use crate::types::{BalanceOf, DefaultVaultId, Version}; +use crate::types::{BalanceOf, DefaultVaultId}; use bitcoin::types::{MerkleProof, Transaction}; use btc_relay::{BtcAddress, BtcPublicKey}; use currency::Amount; @@ -148,11 +148,6 @@ pub mod pallet { #[pallet::storage] pub(super) type IssueBtcDustValue = StorageValue<_, BalanceOf, ValueQuery>; - #[pallet::type_value] - pub(super) fn DefaultForStorageVersion() -> Version { - Version::V4 - } - #[pallet::genesis_config] pub struct GenesisConfig { pub issue_period: T::BlockNumber, @@ -178,7 +173,7 @@ pub mod pallet { } /// The current storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(4); #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] diff --git a/crates/oracle/src/lib.rs b/crates/oracle/src/lib.rs index 8c07859061..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,11 +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 - } - #[pallet::genesis_config] pub struct GenesisConfig { pub max_delay: u32, diff --git a/crates/redeem/src/lib.rs b/crates/redeem/src/lib.rs index 4110340ef6..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,11 +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 - } - #[pallet::genesis_config] pub struct GenesisConfig { pub redeem_period: T::BlockNumber, diff --git a/crates/replace/src/lib.rs b/crates/replace/src/lib.rs index 01c740752e..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,11 +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 - } - #[pallet::genesis_config] pub struct GenesisConfig { pub replace_period: T::BlockNumber, From 0a09131ce5155754686d96974c2dda74d549a60e Mon Sep 17 00:00:00 2001 From: nakul1010 Date: Mon, 26 Jun 2023 12:34:20 +0530 Subject: [PATCH 4/7] fix: update storage version type for vault-reg pallet. --- crates/vault-registry/src/lib.rs | 17 ++++++----------- crates/vault-registry/src/types.rs | 22 +++++++++++++--------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/crates/vault-registry/src/lib.rs b/crates/vault-registry/src/lib.rs index 7fa02c72a8..4cc6c6e463 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::V3 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) } } From 97933c21b7a27952d03166b0f7b33a59254bf1ad Mon Sep 17 00:00:00 2001 From: nakul1010 Date: Mon, 26 Jun 2023 12:37:02 +0530 Subject: [PATCH 5/7] fix: completed todo in redeem. --- crates/redeem/src/types.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/crates/redeem/src/types.rs b/crates/redeem/src/types.rs index 0992b1c9e3..b48eca39eb 100644 --- a/crates/redeem/src/types.rs +++ b/crates/redeem/src/types.rs @@ -1,21 +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; -// ToDo: remove this permanently -/// 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>; From 6651f53dbf9134bbab0c42cd848570fbb889c4a7 Mon Sep 17 00:00:00 2001 From: nakul1010 Date: Thu, 29 Jun 2023 21:49:35 +0530 Subject: [PATCH 6/7] fix: updated version --- crates/issue/src/lib.rs | 17 +++++++++++++++-- crates/issue/src/types.rs | 10 +++++----- crates/vault-registry/src/lib.rs | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/issue/src/lib.rs b/crates/issue/src/lib.rs index ad587043ce..1a51b50ed5 100644 --- a/crates/issue/src/lib.rs +++ b/crates/issue/src/lib.rs @@ -31,7 +31,7 @@ pub mod types; #[doc(inline)] pub use crate::types::{DefaultIssueRequest, IssueRequest, IssueRequestStatus}; -use crate::types::{BalanceOf, DefaultVaultId}; +use crate::types::{BalanceOf, DefaultVaultId, Version}; use bitcoin::types::{MerkleProof, Transaction}; use btc_relay::{BtcAddress, BtcPublicKey}; use currency::Amount; @@ -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 { @@ -169,11 +177,16 @@ pub mod pallet { fn build(&self) { IssuePeriod::::put(self.issue_period); IssueBtcDustValue::::put(self.issue_btc_dust_value); + let current_storage_version = Pallet::::current_storage_version(); + println!("--- current_storage_version before: {:?}", current_storage_version); + + let on_chain_storage_version = Pallet::::on_chain_storage_version(); + println!("--- on_chain_storage_version before: {:?}", on_chain_storage_version); } } /// The current storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(4); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] 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/vault-registry/src/lib.rs b/crates/vault-registry/src/lib.rs index 4cc6c6e463..52ccf2358b 100644 --- a/crates/vault-registry/src/lib.rs +++ b/crates/vault-registry/src/lib.rs @@ -682,7 +682,7 @@ pub mod pallet { LiquidationCollateralThreshold::::insert(currency_pair, threshold); } - StorageVersion::new(Version::V3 as u16).put::>(); + StorageVersion::new(Version::V6 as u16).put::>(); } } } From a96a0b5a7d2a5838eb56ea1a646637051fdd94db Mon Sep 17 00:00:00 2001 From: nakul1010 Date: Thu, 29 Jun 2023 22:44:49 +0530 Subject: [PATCH 7/7] fix: removed debug print statements --- crates/issue/src/lib.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/crates/issue/src/lib.rs b/crates/issue/src/lib.rs index 1a51b50ed5..c6eef06ec4 100644 --- a/crates/issue/src/lib.rs +++ b/crates/issue/src/lib.rs @@ -177,11 +177,6 @@ pub mod pallet { fn build(&self) { IssuePeriod::::put(self.issue_period); IssueBtcDustValue::::put(self.issue_btc_dust_value); - let current_storage_version = Pallet::::current_storage_version(); - println!("--- current_storage_version before: {:?}", current_storage_version); - - let on_chain_storage_version = Pallet::::on_chain_storage_version(); - println!("--- on_chain_storage_version before: {:?}", on_chain_storage_version); } }