Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove old storage version and set new default #932

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions crates/vault-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use primitives::VaultCurrencyPair;

use crate::types::{
BalanceOf, BtcAddress, CurrencyId, DefaultSystemVault, RichSystemVault, RichVault, SignedInner, UnsignedFixedPoint,
Version,
};

use crate::types::DefaultVaultCurrencyPair;
Expand Down Expand Up @@ -86,8 +85,12 @@ pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);

#[pallet::pallet]
#[pallet::generate_store(trait Store)]
#[pallet::storage_version(STORAGE_VERSION)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do, exactly? Does it set it to 0 when building genesis, or does it set the default to 1? What I'm saying is, kintsugi and interlay might actually get set to 0..

Also, the whole situation with palletVersion/storageVersion is a bit of a mess. I thought we'd use palletVersion, since that storage item already exists on polkadotjs. But then I found this pr, which changed the old palletVersion to storageVersion. It turns out that the palletVersion is no longer used and that the item shown by polkadotjs is actualy the storageVersion: polkadot-js/api#546.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sander2 & @gregdhill


When performing an upgrade, we need to obtain the values for current_storage_version and on_chain_storage_version.

During the genesis build, we set the value for on_chain_storage_version, and in the macro, we set the value for current_storage_version.

For the runtime upgrade:

  • Retrieve both values and compare them.
  • In the code before the runtime upgrade Increment current_storage_version by one ie is the STORAGE_VERSION constant value.
  • If the migration is successful, increment on_chain_storage_version by one as well.
  • Both the on_chain_storage_version and current_storage_version should be the same if the runtime upgrade is successful.
  • But since we already have performed multiple runtime upgrades we need to make sure that on_chain_storage_version matches the current_storage_version. PR 1106 fixes it.

References:


#[pallet::without_storage_info] // vault struct contains vec which doesn't implement MaxEncodedLen
pub struct Pallet<T>(_);

Expand Down Expand Up @@ -142,7 +145,14 @@ pub mod pallet {
}

fn on_runtime_upgrade() -> frame_support::weights::Weight {
crate::types::v1::migrate_v1_to_v6::<T>()
let _ = frame_support::migration::clear_storage_prefix(
<Pallet<T>>::name().as_bytes(),
b"StorageVersion",
b"",
None,
None,
);
T::DbWeight::get().reads_writes(0, 1)
}
}

Expand Down Expand Up @@ -638,16 +648,6 @@ pub mod pallet {
pub(super) type TotalUserVaultCollateral<T: Config> =
StorageMap<_, Blake2_128Concat, DefaultVaultCurrencyPair<T>, BalanceOf<T>, 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<T: Config> = StorageValue<_, Version, ValueQuery, DefaultForStorageVersion>;

#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub minimum_collateral_vault: Vec<(CurrencyId<T>, BalanceOf<T>)>,
Expand Down Expand Up @@ -691,7 +691,6 @@ pub mod pallet {
for (currency_pair, threshold) in self.liquidation_collateral_threshold.iter() {
LiquidationCollateralThreshold::<T>::insert(currency_pair, threshold);
}
StorageVersion::<T>::put(Version::V3);
}
}
}
Expand Down
34 changes: 0 additions & 34 deletions crates/vault-registry/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,6 @@ use mocktopus::macros::mockable;

pub use bitcoin::{Address as BtcAddress, PublicKey as BtcPublicKey};

/// Storage version.
#[derive(Encode, Decode, Eq, PartialEq, TypeInfo, MaxEncodedLen)]
pub enum Version {
/// Initial version.
V0,
/// BtcAddress type with script format.
V1,
/// added replace_collateral to vault, changed vaultStatus enum
V2,
/// moved public_key out of the vault struct
V3,
/// Fixed liquidation vault
V4,
/// Added custom pervault secure collateral threshold
V5,
/// Removed wallet
V6,
}

#[derive(Debug, PartialEq)]
pub enum CurrencySource<T: frame_system::Config + orml_tokens::Config> {
/// Used by vault to back issued tokens
Expand Down Expand Up @@ -111,21 +92,6 @@ pub type DefaultVaultId<T> = VaultId<<T as frame_system::Config>::AccountId, Cur

pub type DefaultVaultCurrencyPair<T> = VaultCurrencyPair<CurrencyId<T>>;

pub mod v1 {
use super::*;

pub fn migrate_v1_to_v6<T: Config>() -> frame_support::weights::Weight {
// kintsugi is on V6 but interlay is still on V1
if !matches!(crate::StorageVersion::<T>::get(), Version::V1) {
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::<T>::put(Version::V6);
T::DbWeight::get().reads_writes(0, 1)
}
}

#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, Debug, TypeInfo, MaxEncodedLen)]
pub enum VaultStatus {
/// Vault is active - bool=true indicates that the vault accepts new issue requests
Expand Down