Skip to content

Commit

Permalink
Cleanup migrations (#823)
Browse files Browse the repository at this point in the history
* Cleanup migrations
  • Loading branch information
simonsso authored Feb 9, 2024
1 parent 7738ee6 commit 89f228c
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 767 deletions.
2 changes: 1 addition & 1 deletion node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::sync::Arc;
use primitives::{AccountId, Balance, Block, Nonce};

use sc_client_api::AuxStore;
pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
pub use sc_rpc::DenyUnsafe;
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
Expand Down
2 changes: 1 addition & 1 deletion node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::{sync::Arc, time::Duration};
// rpc
use jsonrpsee::RpcModule;

pub use primitives::{AccountId, Balance, Block, BlockNumber, Hash, Header, Nonce};
pub use primitives::{AccountId, Balance, Block, Nonce};

// Cumulus Imports
use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};
Expand Down
6 changes: 1 addition & 5 deletions pallets/grants/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,7 @@ impl ExtBuilder {
});

pallet_balances::GenesisConfig::<Test> {
balances: self
.endowed_accounts
.into_iter()
.map(|(account_id, initial_balance)| (account_id, initial_balance))
.collect::<Vec<_>>(),
balances: self.endowed_accounts.into_iter().collect::<Vec<_>>(),
}
.assimilate_storage(&mut storage)
.unwrap_or_else(|err| {
Expand Down
82 changes: 0 additions & 82 deletions pallets/sponsorship/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,87 +309,5 @@ mod benchmarks {
assert_eq!(user_detail.reserve_quota.balance(), T::Currency::minimum_balance());
}

#[benchmark]
fn migrate_users(l: Linear<1, 1_000>) {
use crate::migration::v0::{migrate_users, User as V0User, UserDetailsOf as V0UserDetailsOf};
use frame_support::storage::generator::StorageDoubleMap;

let pot: T::PotId = 0u32.into();
let users: Vec<T::AccountId> = (0..l).map(|i| account("user", i, SEED)).collect();

for user in &users {
let user_details = V0UserDetailsOf::<T> {
proxy: user.clone(),
fee_quota: LimitedBalance::with_limit(3u32.into()),
reserve_quota: LimitedBalance::with_limit(6u32.into()),
};
V0User::<T>::insert(pot, user, user_details);
}

let starting_key = V0User::<T>::prefix_hash();

#[block]
{
migrate_users::<T>(l as usize, starting_key);
}

users.iter().for_each(|user| {
assert_eq!(
User::<T>::get(pot, user),
Some(UserDetailsOf::<T> {
proxy: user.clone(),
fee_quota: LimitedBalance::with_limit(3u32.into()),
reserve_quota: LimitedBalance::with_limit(6u32.into()),
deposit: Zero::zero(),
})
);
});
}

#[benchmark]
fn migrate_pots(l: Linear<1, 1_000>) {
use crate::migration::v0::{migrate_pots, Pot as V0Pot, PotDetailsOf as V0PotDetailsOf};
use frame_support::storage::generator::StorageMap;

let caller: T::AccountId = whitelisted_caller();
let pots: Vec<T::PotId> = (0..l).map(|i| i.into()).collect();

pots.iter()
.map(|pot| {
(
*pot,
V0PotDetailsOf::<T> {
sponsor: caller.clone(),
sponsorship_type: T::SponsorshipType::default(),
fee_quota: LimitedBalance::with_limit(5u32.into()),
reserve_quota: LimitedBalance::with_limit(7u32.into()),
},
)
})
.for_each(|(pot, pot_details)| {
V0Pot::<T>::insert(pot, pot_details);
});

let starting_key = V0Pot::<T>::prefix_hash();

#[block]
{
migrate_pots::<T>(l as usize, starting_key);
}

pots.iter().for_each(|pot| {
assert_eq!(
Pot::<T>::get(pot),
Some(PotDetailsOf::<T> {
sponsor: caller.clone(),
sponsorship_type: T::SponsorshipType::default(),
fee_quota: LimitedBalance::with_limit(5u32.into()),
reserve_quota: LimitedBalance::with_limit(7u32.into()),
deposit: Zero::zero(),
})
);
});
}

impl_benchmark_test_suite!(Sponsorship, crate::mock::new_test_ext(), crate::mock::Test);
}
32 changes: 6 additions & 26 deletions pallets/sponsorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

#![cfg_attr(not(feature = "std"), no_std)]

use frame_support::pallet_prelude::{ensure, Decode, Encode, MaxEncodedLen, PhantomData, RuntimeDebug, TypeInfo};
use frame_support::pallet_prelude::{
ensure, Decode, Encode, MaxEncodedLen, PhantomData, RuntimeDebug, StorageVersion, TypeInfo,
};
use frame_support::{
dispatch::{DispatchInfo, DispatchResult, Dispatchable, GetDispatchInfo, Pays, PostDispatchInfo},
traits::{
Expand All @@ -29,8 +31,7 @@ use frame_support::{
};
use pallet_transaction_payment::OnChargeTransaction;
use sp_io::hashing::blake2_256;
#[cfg(feature = "try-runtime")]
use sp_runtime::TryRuntimeError;

use sp_runtime::{
traits::{DispatchInfoOf, One, PostDispatchInfoOf, SignedExtension, TrailingZeroInput, Zero},
transaction_validity::{InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction},
Expand All @@ -43,7 +44,7 @@ use sp_std::{
};
use support::LimitedBalance;

pub use migration::STORAGE_VERSION;
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
pub use pallet::*;

#[cfg(test)]
Expand All @@ -55,7 +56,6 @@ mod tests;
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;

pub(crate) mod migration;
pub mod weights;
pub use weights::*;

Expand Down Expand Up @@ -122,7 +122,7 @@ pub mod pallet {
use scale_info::prelude::boxed::Box;

#[pallet::pallet]
#[pallet::storage_version(migration::STORAGE_VERSION)]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

Expand Down Expand Up @@ -567,26 +567,6 @@ pub mod pallet {
Ok(())
}
}
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
migration::on_initialize::<T>(n)
}

fn on_runtime_upgrade() -> Weight {
migration::on_runtime_upgrade::<T>()
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
migration::pre_upgrade::<T>()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError> {
migration::post_upgrade::<T>(_state)
}
}
}

/// The pre-sponsor call preps are the details returned from `pre_sponsor_for` that are needed
Expand Down
Loading

0 comments on commit 89f228c

Please sign in to comment.