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

stake-pool: Add lamports check for transient stake account on decrease #3805

Merged
merged 1 commit into from
Nov 19, 2022
Merged
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
10 changes: 6 additions & 4 deletions stake-pool/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,11 +1214,14 @@ impl Processor {
&[transient_stake_bump_seed],
];

let stake_minimum_delegation = stake::tools::get_minimum_delegation()?;
let stake_rent = rent.minimum_balance(std::mem::size_of::<stake::state::StakeState>());
if lamports <= stake_rent {
let current_minimum_lamports =
stake_rent.saturating_add(minimum_delegation(stake_minimum_delegation));
if lamports < current_minimum_lamports {
msg!(
"Need more than {} lamports for transient stake to be rent-exempt, {} provided",
stake_rent,
"Need at least {} lamports for transient stake meet minimum delegation and rent-exempt requirements, {} provided",
current_minimum_lamports,
lamports
);
return Err(ProgramError::AccountNotRentExempt);
Expand All @@ -1228,7 +1231,6 @@ impl Processor {
.lamports()
.checked_sub(lamports)
.ok_or(ProgramError::InsufficientFunds)?;
let stake_minimum_delegation = stake::tools::get_minimum_delegation()?;
let required_lamports = minimum_stake_lamports(&meta, stake_minimum_delegation);
if remaining_lamports < required_lamports {
msg!("Need at least {} lamports in the stake account after decrease, {} requested, {} is the current possible maximum",
Expand Down