Skip to content

Commit

Permalink
fix: pallet account id after runtime upgrade (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
irmannmal authored Aug 23, 2022
1 parent f2a6495 commit 5bd40e8
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 91 deletions.
48 changes: 6 additions & 42 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'debio'
version = '2.1.3'
version = '2.1.4'
edition = '2021'
license = 'AGPL-3.0'
authors = ['DeBio Dev Team <[email protected]>']
Expand Down Expand Up @@ -77,8 +77,7 @@ beefy-gadget-rpc = { git = 'https://github.com/paritytech/substrate.git', branch

# Octopus Dependencies
## Octopus Pallet Dependencies
pallet-octopus-appchain = { git = "https://github.com/octopus-network/octopus-pallets.git", branch = "release-v0.9.18-2" }
pallet-octopus-lpos = { git = 'https://github.com/octopus-network/octopus-pallets.git', branch = 'release-v0.9.18' }
pallet-octopus-appchain = { git = 'https://github.com/octopus-network/octopus-pallets.git', branch = 'release-v0.9.18-2' }

# Local Dependencies
# DeBio Runtime Dependencies
Expand Down
2 changes: 1 addition & 1 deletion node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ fn genesis(
sudo: SudoConfig { key: Some(root_key) },
labs: LabsConfig { lab_verifier_key: Some(api_admin_key.clone()) },
orders: OrdersConfig { escrow_key: Some(api_admin_key.clone()) },
rewards: RewardsConfig { rewarder_key: api_admin_key.clone() },
rewards: RewardsConfig { rewarder_key: Some(api_admin_key.clone()) },
genetic_analysts: GeneticAnalystsConfig {
genetic_analyst_verifier_key: Some(api_admin_key.clone()),
},
Expand Down
14 changes: 12 additions & 2 deletions pallets/genetic-analysis-orders/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub mod interface;
pub mod migrations;
pub mod weights;
use interface::GeneticAnalysisOrderInterface;

Expand All @@ -12,7 +13,7 @@ use frame_support::{
RuntimeDebug, SaturatedConversion,
},
sp_std::convert::TryInto,
traits::{Currency, ExistenceRequirement},
traits::{Currency, ExistenceRequirement, StorageVersion},
PalletId,
};
pub use pallet::*;
Expand Down Expand Up @@ -119,6 +120,9 @@ impl<Hash, AccountId, Balance, Moment: Default>
}
}

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

#[frame_support::pallet]
pub mod pallet {
use crate::*;
Expand All @@ -135,17 +139,23 @@ pub mod pallet {
type Currency: Currency<<Self as frame_system::Config>::AccountId>;
type GeneticAnalysisOrdersWeightInfo: WeightInfo;
/// Currency type for this pallet.
#[pallet::constant]
type PalletId: Get<PalletId>;
}

// ----- This is template code, every pallet needs this ---
#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_runtime_upgrade() -> Weight {
migrations::migrate::<T>()
}
}
// --------------------------------------------------------

// ---- Types --------------------------------------------
Expand Down
26 changes: 26 additions & 0 deletions pallets/genetic-analysis-orders/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crate::{Config, Pallet, PalletAccount, Weight};
use frame_support::traits::Get;

pub fn migrate<T: Config>() -> Weight {
use frame_support::traits::StorageVersion;

let version = StorageVersion::get::<Pallet<T>>();
let mut weight: Weight = 0;

if version < 2 {
weight = weight.saturating_add(v2::migrate::<T>());
StorageVersion::new(2).put::<Pallet<T>>();
}

weight
}

mod v2 {
use super::*;

pub fn migrate<T: Config>() -> Weight {
PalletAccount::<T>::put(<Pallet<T>>::account_id());

T::DbWeight::get().writes(1)
}
}
3 changes: 2 additions & 1 deletion pallets/genetic-analysts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ where
}

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

#[frame_support::pallet]
pub mod pallet {
Expand Down Expand Up @@ -192,6 +192,7 @@ pub mod pallet {
type UserProfile: UserProfileProvider<Self, Self::EthereumAddress, Self::ProfileRoles>;
type GeneticAnalystWeightInfo: WeightInfo;
/// Currency type for this pallet.
#[pallet::constant]
type PalletId: Get<PalletId>;
}

Expand Down
21 changes: 17 additions & 4 deletions pallets/genetic-analysts/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use crate::{
AccountIdOf, BalanceOf, Config, GeneticAnalyst, GeneticAnalystInfo, GeneticAnalysts, HashOf,
MomentOf, Pallet, Vec, Weight,
MomentOf, Pallet, PalletAccount, Vec, Weight,
};
use frame_support::traits::Get;
use frame_support::{pallet_prelude::Decode, traits::Get};
use primitives_availability_status::AvailabilityStatus;
use primitives_stake_status::StakeStatus;
use primitives_verification_status::VerificationStatus;

use frame_support::pallet_prelude::Decode;

pub fn migrate<T: Config>() -> Weight {
use frame_support::traits::StorageVersion;

Expand All @@ -20,6 +18,11 @@ pub fn migrate<T: Config>() -> Weight {
StorageVersion::new(2).put::<Pallet<T>>();
}

if version == 2 {
weight = weight.saturating_add(v3::migrate::<T>());
StorageVersion::new(3).put::<Pallet<T>>();
}

weight
}

Expand Down Expand Up @@ -65,3 +68,13 @@ mod v2 {
weight
}
}

mod v3 {
use super::*;

pub fn migrate<T: Config>() -> Weight {
PalletAccount::<T>::put(<Pallet<T>>::account_id());

T::DbWeight::get().writes(1)
}
}
6 changes: 3 additions & 3 deletions pallets/labs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub use scale_info::TypeInfo;

pub mod interface;
pub mod migrations;
pub mod weights;
Expand All @@ -10,6 +8,7 @@ pub mod weights;
/// Learn more about FRAME and the core library of Substrate FRAME pallets:
/// https://substrate.dev/docs/en/knowledgebase/runtime/frame
pub use pallet::*;
pub use scale_info::TypeInfo;
pub use weights::WeightInfo;

pub use crate::interface::LabInterface;
Expand Down Expand Up @@ -157,7 +156,7 @@ where
}

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

#[frame_support::pallet]
pub mod pallet {
Expand Down Expand Up @@ -201,6 +200,7 @@ pub mod pallet {
type UserProfile: UserProfileProvider<Self, Self::EthereumAddress, Self::ProfileRoles>;
type LabWeightInfo: WeightInfo;
/// Currency type for this pallet.
#[pallet::constant]
type PalletId: Get<PalletId>;
}

Expand Down
22 changes: 18 additions & 4 deletions pallets/labs/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::{
AccountIdOf, BalanceOf, Config, HashOf, Lab, LabInfo, Labs, MomentOf, Pallet, Vec, Weight,
AccountIdOf, BalanceOf, Config, HashOf, Lab, LabInfo, Labs, MomentOf, Pallet, PalletAccount,
Vec, Weight,
};
use frame_support::traits::Get;
use frame_support::{pallet_prelude::Decode, traits::Get};
use primitives_stake_status::StakeStatus;
use primitives_verification_status::VerificationStatus;

use frame_support::pallet_prelude::Decode;

pub fn migrate<T: Config>() -> Weight {
use frame_support::traits::StorageVersion;

Expand All @@ -18,6 +17,11 @@ pub fn migrate<T: Config>() -> Weight {
StorageVersion::new(2).put::<Pallet<T>>();
}

if version == 2 {
weight = weight.saturating_add(v3::migrate::<T>());
StorageVersion::new(3).put::<Pallet<T>>();
}

weight
}

Expand Down Expand Up @@ -57,3 +61,13 @@ mod v2 {
weight
}
}

mod v3 {
use super::*;

pub fn migrate<T: Config>() -> Weight {
PalletAccount::<T>::put(<Pallet<T>>::account_id());

T::DbWeight::get().writes(1)
}
}
Loading

0 comments on commit 5bd40e8

Please sign in to comment.