From 05ed37854f99e9dc0a56eb8963d77767f3453024 Mon Sep 17 00:00:00 2001 From: "E. Fynn" Date: Thu, 22 Sep 2022 11:32:30 -0300 Subject: [PATCH] Withdraw inactive stake before unstaking When the validator is flagged as inactive, we try to unstake everything from it, but we accumulate some inactive stake when we merge stake accounts, this needs to be withdrawn even if it does not exceed the `MINIMUM_WITHDRAW_AMOUNT`. --- cli/maintainer/src/maintenance.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cli/maintainer/src/maintenance.rs b/cli/maintainer/src/maintenance.rs index b13c2ed3d..8e585bad5 100644 --- a/cli/maintainer/src/maintenance.rs +++ b/cli/maintainer/src/maintenance.rs @@ -1015,8 +1015,15 @@ impl SolidoState { // of Lamports, we don't bother withdrawing. We try to do this // so we don't pay more for fees than the amount that we'll // withdraw. Or if we have stake to remove from unstake accounts. - if expected_difference_stake > SolidoState::MINIMUM_WITHDRAW_AMOUNT - || removed_unstake > Lamports(0) + // If we're dealing with an inactive validator, we try to withraw + // all inactive stake. + let minimum_withdraw_amount = if validator.entry.active { + SolidoState::MINIMUM_WITHDRAW_AMOUNT + } else { + Lamports(0) + }; + + if expected_difference_stake > minimum_withdraw_amount || removed_unstake > Lamports(0) { // The balance of this validator is not up to date, try to update it. let mut stake_account_addrs = Vec::new(); @@ -1610,11 +1617,11 @@ pub fn try_perform_maintenance( // as possible. .or_else(|| state.try_merge_on_all_stakes()) .or_else(|| state.try_update_exchange_rate()) + .or_else(|| state.try_update_stake_account_balance()) .or_else(|| state.try_unstake_from_inactive_validator()) // Collecting validator fees goes after updating the exchange rate, // because it may be rejected if the exchange rate is outdated. // Same for updating the validator balance. - .or_else(|| state.try_update_stake_account_balance()) .or_else(|| state.try_deactivate_validator_if_commission_exceeds_max()) .or_else(|| state.try_stake_deposit()) .or_else(|| state.try_unstake_from_active_validators())