Refactor pallet-state-trie-migration to fungible::* traits (#1801)

## Summary

This PR consolidates `pallet-state-trie-migration` as a part of
https://github.com/paritytech/polkadot-sdk/issues/226 /
https://github.com/paritytech/polkadot-sdk/issues/171:

`pallet-state-trie-migration`:
- [x] replace `Currency` with `fungible` traits
- [x] run benchmarks
- [x] refactor to `DefaultConfig`

`pallet_nicks`:
- [x]  remove

others:
- [x] remove `as Fn*` or `asFun*` stuff based on discussion
[here](https://github.com/paritytech/polkadot-sdk/issues/226#issuecomment-1822861445)

---------

Co-authored-by: Richard Melkonian <35300528+0xmovses@users.noreply.github.com>
Co-authored-by: command-bot <>
This commit is contained in:
Branislav Kontur
2024-01-24 14:18:54 +01:00
committed by GitHub
parent a989ddfab9
commit 4374b5d598
17 changed files with 312 additions and 789 deletions
+17 -11
View File
@@ -20,11 +20,11 @@
use super::{Pallet as SafeMode, *};
use frame_benchmarking::v2::*;
use frame_support::traits::{fungible::Mutate as FunMutate, UnfilteredDispatchable};
use frame_support::traits::{fungible, UnfilteredDispatchable};
use frame_system::{Pallet as System, RawOrigin};
use sp_runtime::traits::{Bounded, One, Zero};
#[benchmarks(where T::Currency: FunMutate<T::AccountId>)]
#[benchmarks(where T::Currency: fungible::Mutate<T::AccountId>)]
mod benchmarks {
use super::*;
@@ -58,7 +58,7 @@ mod benchmarks {
let caller: T::AccountId = whitelisted_caller();
let origin = RawOrigin::Signed(caller.clone());
T::Currency::set_balance(&caller, init_bal::<T>());
<T::Currency as fungible::Mutate<_>>::set_balance(&caller, init_bal::<T>());
#[extrinsic_call]
_(origin);
@@ -91,7 +91,7 @@ mod benchmarks {
T::ExtendDepositAmount::get().ok_or_else(|| BenchmarkError::Weightless)?;
let alice: T::AccountId = whitelisted_caller();
T::Currency::set_balance(&alice, init_bal::<T>());
<T::Currency as fungible::Mutate<_>>::set_balance(&alice, init_bal::<T>());
System::<T>::set_block_number(1u32.into());
assert!(SafeMode::<T>::do_enter(None, 1u32.into()).is_ok());
@@ -152,7 +152,7 @@ mod benchmarks {
let alice: T::AccountId = whitelisted_caller();
let origin = RawOrigin::Signed(alice.clone());
T::Currency::set_balance(&alice, init_bal::<T>());
<T::Currency as fungible::Mutate<_>>::set_balance(&alice, init_bal::<T>());
// Mock the storage. This is needed in case the `EnterDepositAmount` is zero.
let block: BlockNumberFor<T> = 1u32.into();
let bal: BalanceOf<T> = 1u32.into();
@@ -169,7 +169,7 @@ mod benchmarks {
_(origin, alice.clone(), 1u32.into());
assert!(!Deposits::<T>::contains_key(&alice, &block));
assert_eq!(T::Currency::balance(&alice), init_bal::<T>());
assert_eq!(<T::Currency as fungible::Inspect<_>>::balance(&alice), init_bal::<T>());
Ok(())
}
@@ -180,7 +180,7 @@ mod benchmarks {
.map_err(|_| BenchmarkError::Weightless)?;
let alice: T::AccountId = whitelisted_caller();
T::Currency::set_balance(&alice, init_bal::<T>());
<T::Currency as fungible::Mutate<_>>::set_balance(&alice, init_bal::<T>());
// Mock the storage. This is needed in case the `EnterDepositAmount` is zero.
let block: BlockNumberFor<T> = 1u32.into();
@@ -189,7 +189,10 @@ mod benchmarks {
T::Currency::hold(&&HoldReason::EnterOrExtend.into(), &alice, bal)?;
EnteredUntil::<T>::put(&block);
assert_eq!(T::Currency::balance(&alice), init_bal::<T>() - 1u32.into());
assert_eq!(
<T::Currency as fungible::Inspect<_>>::balance(&alice),
init_bal::<T>() - 1u32.into()
);
assert!(SafeMode::<T>::do_exit(ExitReason::Force).is_ok());
System::<T>::set_block_number(System::<T>::block_number() + One::one());
@@ -200,7 +203,7 @@ mod benchmarks {
_(force_origin as T::RuntimeOrigin, alice.clone(), block);
assert!(!Deposits::<T>::contains_key(&alice, block));
assert_eq!(T::Currency::balance(&alice), init_bal::<T>());
assert_eq!(<T::Currency as fungible::Inspect<_>>::balance(&alice), init_bal::<T>());
Ok(())
}
@@ -210,7 +213,7 @@ mod benchmarks {
.map_err(|_| BenchmarkError::Weightless)?;
let alice: T::AccountId = whitelisted_caller();
T::Currency::set_balance(&alice, init_bal::<T>());
<T::Currency as fungible::Mutate<_>>::set_balance(&alice, init_bal::<T>());
// Mock the storage. This is needed in case the `EnterDepositAmount` is zero.
let block: BlockNumberFor<T> = 1u32.into();
@@ -224,7 +227,10 @@ mod benchmarks {
_(force_origin as T::RuntimeOrigin, alice.clone(), block);
assert!(!Deposits::<T>::contains_key(&alice, block));
assert_eq!(T::Currency::balance(&alice), init_bal::<T>() - 1u32.into());
assert_eq!(
<T::Currency as fungible::Inspect<_>>::balance(&alice),
init_bal::<T>() - 1u32.into()
);
Ok(())
}
+5 -5
View File
@@ -84,8 +84,8 @@ use frame_support::{
pallet_prelude::*,
traits::{
fungible::{
hold::{Inspect as FunHoldInspect, Mutate as FunHoldMutate},
Inspect as FunInspect,
self,
hold::{Inspect, Mutate},
},
tokens::{Fortitude, Precision},
CallMetadata, Contains, Defensive, GetCallMetadata, PalletInfoAccess, SafeModeNotify,
@@ -102,7 +102,7 @@ pub use pallet::*;
pub use weights::*;
type BalanceOf<T> =
<<T as Config>::Currency as FunInspect<<T as frame_system::Config>::AccountId>>::Balance;
<<T as Config>::Currency as fungible::Inspect<<T as frame_system::Config>::AccountId>>::Balance;
#[frame_support::pallet]
pub mod pallet {
@@ -117,8 +117,8 @@ pub mod pallet {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Currency type for this pallet, used for Deposits.
type Currency: FunHoldInspect<Self::AccountId>
+ FunHoldMutate<Self::AccountId, Reason = Self::RuntimeHoldReason>;
type Currency: Inspect<Self::AccountId>
+ Mutate<Self::AccountId, Reason = Self::RuntimeHoldReason>;
/// The hold reason when reserving funds for entering or extending the safe-mode.
type RuntimeHoldReason: From<HoldReason>;