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

[Pools] fix derivation of pool account #4999

Merged
merged 78 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
11a0c44
migration test
Ank4n Jun 18, 2024
efd3324
fmt
Ank4n Jun 18, 2024
3f8d2fc
undo pool changes
Ank4n Jun 18, 2024
7388573
fixes all NotEnoughFunds error
Ank4n Jun 18, 2024
6634d25
return false if pool does not exist
Ank4n Jun 18, 2024
a3901a9
fix transfer on hold amount should still be held in dst acc
Ank4n Jun 18, 2024
462be1f
fmt
Ank4n Jun 18, 2024
c7e9f6c
unexpected errors check
Ank4n Jun 19, 2024
9a68720
all non staking accounts succeed when given minimum balance
Ank4n Jun 19, 2024
268d0a5
assert migrate tests
Ank4n Jun 19, 2024
000762f
remove clone
Ank4n Jun 21, 2024
a904fc8
uncomment
Ank4n Jun 21, 2024
0c776b8
incrementing provider fixes users migrating with zero balance
Ank4n Jun 29, 2024
699a2ec
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Jul 3, 2024
c3fa887
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Jul 5, 2024
3d2379e
test for clean up accounts
Ank4n Jul 6, 2024
ec9035c
providers are incremented correctly when migration agent/delegators
Ank4n Jul 6, 2024
a9d4595
migrated agents/delegators are also cleaned up correctly
Ank4n Jul 6, 2024
8a27ae0
improve remote tests
Ank4n Jul 6, 2024
8f77ac4
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Jul 7, 2024
7fd484a
add runtime api for total member balance
Ank4n Jul 7, 2024
9925a9f
ensure member can't bond extra if they are in unmigrated state
Ank4n Jul 7, 2024
4a9f35f
gate all calls if non migrated state as defensive measure
Ank4n Jul 7, 2024
bc3ce11
ensure all calls are gated
Ank4n Jul 7, 2024
5b91644
add runtime api for pool balance
Ank4n Jul 10, 2024
6ceb1ba
remove unused imports
Ank4n Jul 10, 2024
de48083
fix import
Ank4n Jul 11, 2024
fd8a451
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Jul 11, 2024
ab2317b
fix test
Ank4n Jul 11, 2024
cfdaf90
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Jul 12, 2024
d5634c4
add prdoc
Ank4n Jul 12, 2024
0da9807
fix prdoc bump
Ank4n Jul 13, 2024
00f7e6f
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Jul 13, 2024
1514c2b
add missing crate to prdoc
Ank4n Jul 13, 2024
3dee9c4
remove unintended file
Ank4n Jul 13, 2024
a52f819
fix derivation of pool account
Ank4n Jul 11, 2024
41c01e6
fix import
Ank4n Jul 11, 2024
85498be
migration code
Ank4n Jul 18, 2024
172b14d
remove released migrations
Ank4n Jul 18, 2024
28fb070
fix clippy
Ank4n Jul 18, 2024
8c96add
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Jul 18, 2024
89c1964
fix agent count
Ank4n Jul 18, 2024
2440303
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Aug 6, 2024
3c24530
Merge branch 'ankan/delegate-stake-remote-tests' into ankan/delegated…
Ank4n Aug 6, 2024
66b5458
remove unnecessary conversion
Ank4n Aug 6, 2024
9ac94ee
fix import
Ank4n Aug 7, 2024
0bef5a9
minor fixes
Ank4n Aug 7, 2024
0c57ab7
missing import
Ank4n Aug 7, 2024
95bf173
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Aug 7, 2024
0115e7c
rustdoc fix
Ank4n Aug 7, 2024
c6eafa5
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Aug 7, 2024
b585901
Merge branch 'ankan/delegate-stake-remote-tests' into ankan/delegated…
Ank4n Aug 7, 2024
2e486db
remove condition for minimum balance when migrating delegation
Ank4n Aug 10, 2024
c209d9e
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Aug 10, 2024
3e945c4
Merge branch 'ankan/delegate-stake-remote-tests' into ankan/delegated…
Ank4n Aug 10, 2024
cbfbf6f
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Aug 12, 2024
acbb674
refactor based on pr comments
Ank4n Aug 12, 2024
65cecb5
allow migration lower than ED
Ank4n Aug 12, 2024
eab6f35
Merge branch 'ankan/delegate-stake-remote-tests' into ankan/delegated…
Ank4n Aug 12, 2024
94b2e8b
add prdoc
Ank4n Aug 12, 2024
4081f12
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Aug 13, 2024
17bccae
Merge branch 'ankan/delegate-stake-remote-tests' into ankan/delegated…
Ank4n Aug 13, 2024
00ab010
move remote tests to another file
Ank4n Aug 13, 2024
7326b10
fix below ed test
Ank4n Aug 13, 2024
8cdde30
move remote tests to another file
Ank4n Aug 13, 2024
99698d6
fix below ed test
Ank4n Aug 13, 2024
5e465f2
revert comment
Ank4n Aug 13, 2024
c38f83c
ensure there is atleast ED to transfer
Ank4n Aug 13, 2024
b3a3263
fix imports
Ank4n Aug 13, 2024
dfcdc42
Update substrate/frame/delegated-staking/src/lib.rs
Ank4n Aug 13, 2024
5082542
Merge branch 'master' into ankan/delegate-stake-remote-tests
Ank4n Aug 13, 2024
bce9803
refactor inc dec of providers
Ank4n Aug 13, 2024
ae9a370
gate extrinsics on top level function
Ank4n Aug 13, 2024
251ba4c
fix clippy
Ank4n Aug 13, 2024
4ba0c97
remove empty line
Ank4n Aug 14, 2024
56c1075
Merge branch 'ankan/delegate-stake-remote-tests' into ankan/delegated…
Ank4n Aug 14, 2024
6d08f19
Merge branch 'master' into ankan/delegated-staking-fix-derivation
Ank4n Aug 14, 2024
a886fa9
fix rust doc
Ank4n Aug 14, 2024
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
Prev Previous commit
Next Next commit
undo pool changes
  • Loading branch information
Ank4n committed Jun 29, 2024
commit 3f8d2fc4bb5401b0349286030a2cf245c6298f43
26 changes: 19 additions & 7 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,8 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
matches!(
c,
RuntimeCall::Staking(..) |
RuntimeCall::Session(..) | RuntimeCall::Utility(..) |
RuntimeCall::Session(..) |
RuntimeCall::Utility(..) |
RuntimeCall::FastUnstake(..) |
RuntimeCall::VoterList(..) |
RuntimeCall::NominationPools(..)
Expand Down Expand Up @@ -2698,6 +2699,11 @@ mod remote_tests {
.await
.unwrap();
ext.execute_with(|| {
// create an account with some balance
let alice = AccountId::from([1u8; 32]);
use frame_support::traits::Currency;
Balances::deposit_creating(&alice, 100_000 * UNITS);

let mut needs_migration = 0;
let mut success = 0;

Expand All @@ -2707,14 +2713,18 @@ mod remote_tests {
k.clone(),
) {
needs_migration = needs_migration + 1;
pallet_nomination_pools::Pallet::<Runtime>::migrate_to_delegate_stake(k)
.map(|_| success = success + 1)
.map_err(|e| log::error!("Failed to migrate pool {}: {:?}", k, e));
pallet_nomination_pools::Pallet::<Runtime>::migrate_pool_to_delegate_stake(
RuntimeOrigin::signed(alice.clone()).into(),
k,
)
.map(|_| success = success + 1)
.map_err(|e| log::error!(target: "remote_test", "Failed to migrate pool {}: {:?}", k, e));
}
});

// log summary
log::info!(
target: "remote_test",
"Migration summary: {} pools needed migration, {} pools successfully migrated",
needs_migration,
success
Expand All @@ -2729,16 +2739,18 @@ mod remote_tests {
k.clone(),
) {
needs_migration = needs_migration + 1;
pallet_nomination_pools::Pallet::<Runtime>::migrate_member_to_delegate_stake(
k.clone(),
pallet_nomination_pools::Pallet::<Runtime>::migrate_delegation(
RuntimeOrigin::signed(alice.clone()).into(),
sp_runtime::MultiAddress::Id(k.clone()),
)
.map(|_| success = success + 1)
.map_err(|e| log::error!("Failed to migrate member {}: {:?}", k, e));
.map_err(|e| log::error!(target: "remote_test", "Failed to migrate member {}: {:?}", k, e));
}
});

// log summary
log::info!(
target: "remote_test",
"Migration summary: {} members needed migration, {} members successfully migrated",
needs_migration,
success
Expand Down
58 changes: 27 additions & 31 deletions substrate/frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2916,7 +2916,32 @@ pub mod pallet {
);

let member_account = T::Lookup::lookup(member_account)?;
Self::migrate_member_to_delegate_stake(member_account)?;
let member =
PoolMembers::<T>::get(&member_account).ok_or(Error::<T>::PoolMemberNotFound)?;

// ensure pool is migrated.
ensure!(
T::StakeAdapter::pool_strategy(Pool::from(Self::generate_bonded_account(
member.pool_id
))) == adapter::StakeStrategyType::Delegate,
Error::<T>::NotMigrated
);

let pool_contribution = member.total_balance();
ensure!(pool_contribution >= MinJoinBond::<T>::get(), Error::<T>::MinimumBondNotMet);
// the member must have some contribution to be migrated.
ensure!(pool_contribution > Zero::zero(), Error::<T>::AlreadyMigrated);

let delegation =
T::StakeAdapter::member_delegation_balance(Member::from(member_account.clone()));
// delegation should not exist.
ensure!(delegation.is_none(), Error::<T>::AlreadyMigrated);

T::StakeAdapter::migrate_delegation(
Pool::from(Pallet::<T>::generate_bonded_account(member.pool_id)),
Member::from(member_account),
pool_contribution,
)?;

// if successful, we refund the fee.
Ok(Pays::No.into())
Expand Down Expand Up @@ -3069,42 +3094,13 @@ impl<T: Config> Pallet<T> {
T::PalletId::get().into_sub_account_truncating((AccountType::Bonded, id))
}

pub fn migrate_to_delegate_stake(id: PoolId) -> DispatchResult {
fn migrate_to_delegate_stake(id: PoolId) -> DispatchResult {
T::StakeAdapter::migrate_nominator_to_agent(
Pool::from(Self::generate_bonded_account(id)),
&Self::generate_reward_account(id),
)
}

pub fn migrate_member_to_delegate_stake(member_account: T::AccountId) -> DispatchResult {
let member =
PoolMembers::<T>::get(&member_account).ok_or(Error::<T>::PoolMemberNotFound)?;

// ensure pool is migrated.
ensure!(
T::StakeAdapter::pool_strategy(Pool::from(Self::generate_bonded_account(
member.pool_id
))) == adapter::StakeStrategyType::Delegate,
Error::<T>::NotMigrated
);

let pool_contribution = member.total_balance();
ensure!(pool_contribution >= MinJoinBond::<T>::get(), Error::<T>::MinimumBondNotMet);
// the member must have some contribution to be migrated.
ensure!(pool_contribution > Zero::zero(), Error::<T>::AlreadyMigrated);

let delegation =
T::StakeAdapter::member_delegation_balance(Member::from(member_account.clone()));
// delegation should not exist.
ensure!(delegation.is_none(), Error::<T>::AlreadyMigrated);

T::StakeAdapter::migrate_delegation(
Pool::from(Pallet::<T>::generate_bonded_account(member.pool_id)),
Member::from(member_account),
pool_contribution,
)
}

/// Create the reward account of a pool with the given id.
pub fn generate_reward_account(id: PoolId) -> T::AccountId {
// NOTE: in order to have a distinction in the test account id type (u128), we put
Expand Down