Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
use inner for nested types in nomination pools (#11030)
Browse files Browse the repository at this point in the history
* Use nested inner type for pool

* make tests and benchmarks work

* remove feat

* all tests work now

* fix node-runtime
  • Loading branch information
kianenigma authored Mar 15, 2022
1 parent 9721dd1 commit 3b30c36
Show file tree
Hide file tree
Showing 7 changed files with 716 additions and 816 deletions.
2 changes: 2 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ impl pallet_bags_list::Config for Runtime {

parameter_types! {
pub const PostUnbondPoolsWindow: u32 = 4;
pub const NominationPoolsPalletId: PalletId = PalletId(*b"py/npols");
}

use sp_runtime::traits::Convert;
Expand All @@ -723,6 +724,7 @@ impl pallet_nomination_pools::Config for Runtime {
type StakingInterface = pallet_staking::Pallet<Self>;
type PostUnbondingPoolsWindow = PostUnbondPoolsWindow;
type MaxMetadataLen = ConstU32<256>;
type PalletId = NominationPoolsPalletId;
}

parameter_types! {
Expand Down
2 changes: 1 addition & 1 deletion frame/nomination-pools/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ std = [
"pallet-nomination-pools/std",
"sp-runtime/std",
"sp-staking/std"
]
]
34 changes: 19 additions & 15 deletions frame/nomination-pools/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use frame_election_provider_support::SortedListProvider;
use frame_support::{ensure, traits::Get};
use frame_system::RawOrigin as Origin;
use pallet_nomination_pools::{
BalanceOf, BondedPoolStorage, BondedPools, Delegators, Metadata, MinCreateBond, MinJoinBond,
Pallet as Pools, PoolState, RewardPools, SubPoolsStorage,
BalanceOf, BondedPoolInner, BondedPools, Delegators, Metadata, MinCreateBond, MinJoinBond,
Pallet as Pools, PoolRoles, PoolState, RewardPools, SubPoolsStorage,
};
use sp_runtime::traits::{StaticLookup, Zero};
use sp_staking::{EraIndex, StakingInterface};
Expand Down Expand Up @@ -67,7 +67,7 @@ fn create_pool_account<T: pallet_nomination_pools::Config>(
.unwrap();

let pool_account = pallet_nomination_pools::BondedPools::<T>::iter()
.find(|(_, bonded_pool)| bonded_pool.depositor == pool_creator)
.find(|(_, bonded_pool)| bonded_pool.roles.depositor == pool_creator)
.map(|(pool_account, _)| pool_account)
.expect("pool_creator created a pool above");

Expand Down Expand Up @@ -189,7 +189,7 @@ impl<T: Config> ListScenario<T> {
// Sanity check the delegator was added correctly
let delegator = Delegators::<T>::get(&joiner).unwrap();
assert_eq!(delegator.points, amount);
assert_eq!(delegator.pool, self.origin1);
assert_eq!(delegator.bonded_pool_account, self.origin1);

self
}
Expand Down Expand Up @@ -475,14 +475,16 @@ frame_benchmarking::benchmarks! {
let (pool_account, new_pool) = BondedPools::<T>::iter().next().unwrap();
assert_eq!(
new_pool,
BondedPoolStorage {
BondedPoolInner {
points: min_create_bond,
depositor: depositor.clone(),
root: depositor.clone(),
nominator: depositor.clone(),
state_toggler: depositor.clone(),
state: PoolState::Open,
delegator_counter: 1
delegator_counter: 1,
roles: PoolRoles {
depositor: depositor.clone(),
root: depositor.clone(),
nominator: depositor.clone(),
state_toggler: depositor.clone(),
},
}
);
assert_eq!(
Expand Down Expand Up @@ -516,14 +518,16 @@ frame_benchmarking::benchmarks! {
let (pool_account, new_pool) = BondedPools::<T>::iter().next().unwrap();
assert_eq!(
new_pool,
BondedPoolStorage {
BondedPoolInner {
points: min_create_bond,
depositor: depositor.clone(),
root: depositor.clone(),
nominator: depositor.clone(),
state_toggler: depositor.clone(),
state: PoolState::Open,
delegator_counter: 1,
roles: PoolRoles {
depositor: depositor.clone(),
root: depositor.clone(),
nominator: depositor.clone(),
state_toggler: depositor.clone(),
}
}
);
assert_eq!(
Expand Down
4 changes: 3 additions & 1 deletion frame/nomination-pools/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// limitations under the License.

use frame_election_provider_support::VoteWeight;
use frame_support::{pallet_prelude::*, parameter_types, traits::ConstU64};
use frame_support::{pallet_prelude::*, parameter_types, traits::ConstU64, PalletId};
use sp_runtime::traits::{Convert, IdentityLookup};

type AccountId = u64;
Expand Down Expand Up @@ -141,6 +141,7 @@ impl Convert<sp_core::U256, Balance> for U256ToBalance {

parameter_types! {
pub static PostUnbondingPoolsWindow: u32 = 10;
pub const PoolsPalletId: PalletId = PalletId(*b"py/nopls");
}

impl pallet_nomination_pools::Config for Runtime {
Expand All @@ -152,6 +153,7 @@ impl pallet_nomination_pools::Config for Runtime {
type StakingInterface = Staking;
type PostUnbondingPoolsWindow = PostUnbondingPoolsWindow;
type MaxMetadataLen = ConstU32<256>;
type PalletId = PoolsPalletId;
}

impl crate::Config for Runtime {}
Expand Down
Loading

0 comments on commit 3b30c36

Please sign in to comment.