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

fix(lottery): drawings fail when restaking unstaked funds #1218

Merged
merged 15 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions pallets/pallet-lottery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ pub mod pallet {
/// FATAL: Assigning/Transferring winning claims
/// would **remove** user deposited funds from pallet
PotBalanceTooLow,
/// FATAL: Can't stake the requested amount with available funds
PotBalanceTooLowToStake,
/// Pallet balance is lower than the needed gas fee buffer
PotBalanceBelowGasReserve,
/// Pallet balance is too low to submit a needed transaction
Expand Down
12 changes: 10 additions & 2 deletions pallets/pallet-lottery/src/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,17 @@ impl<T: Config> Pallet<T> {
) -> DispatchResult {
log::trace!(function_name!());
// preconditions
if Self::surplus_funds().is_zero() {
return Err(Error::<T>::PotBalanceTooLow.into());
// funds eligible for staking:
// - newly deposited funds > min_deposit
// - unstaked-but-not-needed-for-withdrawals funds > min_deposit
if amount < Self::min_deposit() {
return Err(Error::<T>::DepositBelowMinAmount.into());
}
if amount > Self::surplus_funds() && amount > Self::unlocked_unstaking_funds() {
ferrell-code marked this conversation as resolved.
Show resolved Hide resolved
// we can't handle this withdrawal from new deposits or unstaked funds
return Err(Error::<T>::PotBalanceTooLowToStake.into());
}
// collator exists
let candidate_delegation_count;
if let Some(info) = pallet_parachain_staking::Pallet::<T>::candidate_info(&collator) {
candidate_delegation_count = info.delegation_count;
Expand Down