Skip to content

Commit

Permalink
fix lottery withdraw issue
Browse files Browse the repository at this point in the history
Signed-off-by: zqhxuyuan <zqhxuyuan@gmail.com>
  • Loading branch information
zqhxuyuan committed Apr 18, 2024
1 parent bd4aa43 commit 9da7e72
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pallets/pallet-lottery/src/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,22 @@ impl<T: Config> Pallet<T> {
if withdrawal_eligible_collators.is_empty() {
return vec![];
}
let mut eligible_collators: Vec<_> = collators_we_are_unstaking_from;
if let Some(state) =
pallet_parachain_staking::Pallet::<T>::delegator_state(crate::Pallet::<T>::account_id())
{
let owners: Vec<_> = state.delegations.0.iter()
.cloned()
.map(|uc| uc.owner)
.collect();
eligible_collators = withdrawal_eligible_collators.iter()
.filter(|account| owners.contains(account))
.cloned()
.collect();
}
// first concern: If there are inactive collators we are staked with, prefer these
let (mut collators, balance_unstaked) = withdraw_strategies::unstake_inactive_collators::<T>(
&withdrawal_eligible_collators,
&eligible_collators,
remaining_balance,
);
withdrawals.append(&mut collators);
Expand All @@ -221,7 +234,7 @@ impl<T: Config> Pallet<T> {
// If we have balance to withdraw left over, we have to unstake some healthy collator.
// Unstake starting from the highest overallocated collator ( since that yields the lowest APY ) going down until request is satisfied
let (mut collators, balance_unstaked) = withdraw_strategies::unstake_least_apy_collators::<T>(
&withdrawal_eligible_collators
&eligible_collators
.into_iter()
.filter(|collator| !withdrawals.contains(collator))
.collect(),
Expand Down

0 comments on commit 9da7e72

Please sign in to comment.