From b3187fc05e220bc3d6b43593cc94cf4ab23f29a7 Mon Sep 17 00:00:00 2001 From: Kirill Konevets Date: Wed, 7 Sep 2022 15:27:31 +0300 Subject: [PATCH] cope with Solana raising stake minimum delegation to 1.0 sol https://github.com/solana-labs/solana/issues/24357 need more tests --- cli/maintainer/src/maintenance.rs | 21 ++++++++++++++++----- program/tests/mod.rs | 1 - 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cli/maintainer/src/maintenance.rs b/cli/maintainer/src/maintenance.rs index 523c00b81..992092151 100644 --- a/cli/maintainer/src/maintenance.rs +++ b/cli/maintainer/src/maintenance.rs @@ -21,6 +21,7 @@ use solana_program::{ program_pack::Pack, pubkey::Pubkey, rent::Rent, + stake::state::StakeState, stake_history::StakeHistory, }; use solana_sdk::{ @@ -674,7 +675,17 @@ impl SolidoState { validator: &PubkeyAndEntry, stake_account: &(Pubkey, StakeAccount), amount: Lamports, - ) -> (Pubkey, Instruction) { + ) -> Option<(Pubkey, Instruction)> { + let stake_rent_exempt_amount = StakeState::get_rent_exempt_reserve(&self.rent); + let minimum_stake_amount = + (Lamports(1_000_000_000) + Lamports(stake_rent_exempt_amount)).ok()?; + if amount < minimum_stake_amount { + // Due to Solana aiming to raise stake minimum delegation to 1SOL we should + // wait till stake amount be large enough for stake account to exist. + // https://github.com/solana-labs/solana/issues/24357 + return None; + } + let (validator_unstake_account, _) = validator.find_stake_account_address( &self.solido_program_id, &self.solido_address, @@ -682,7 +693,7 @@ impl SolidoState { StakeType::Unstake, ); let (stake_account_address, _) = stake_account; - ( + Some(( validator_unstake_account, lido::instruction::unstake( &self.solido_program_id, @@ -696,7 +707,7 @@ impl SolidoState { }, amount, ), - ) + )) } /// If there is a validator being deactivated, try to unstake its funds. @@ -728,7 +739,7 @@ impl SolidoState { validator, &stake_accounts[0], stake_account_balance.balance.total(), - ); + )?; let task = MaintenanceOutput::UnstakeFromInactiveValidator(Unstake { validator_vote_account: validator.pubkey, from_stake_account: stake_account_address, @@ -1132,7 +1143,7 @@ impl SolidoState { } let (unstake_account, instruction) = - self.get_unstake_instruction(validator, stake_account, amount); + self.get_unstake_instruction(validator, stake_account, amount)?; let task = MaintenanceOutput::UnstakeFromActiveValidator(Unstake { validator_vote_account: validator.pubkey, from_stake_account: stake_account.0, diff --git a/program/tests/mod.rs b/program/tests/mod.rs index ca1d50b19..1e20c20f4 100644 --- a/program/tests/mod.rs +++ b/program/tests/mod.rs @@ -12,5 +12,4 @@ // By putting everything in a single module, we sidestep this problem. pub mod tests; -#[macro_use] extern crate testlib;