Skip to content

Commit

Permalink
v1.18: relax stake split destination check (backport of anza-xyz#162) (
Browse files Browse the repository at this point in the history
…anza-xyz#368)

relax stake split destination check (anza-xyz#162)

* relax stake split destination check

* change stake_account error handling logic

* fmt

* modify logic

* change error message when account is neither owned by stake program or system program

* add a comment explaining nested ifs in stake_account error handling

* fix typos in comments

* update comment

(cherry picked from commit 6bcb77d)

Co-authored-by: Nagaprasad V R <81755170+Nagaprasadvr@users.noreply.github.com>
  • Loading branch information
2 people authored and willhickey committed Mar 23, 2024
1 parent 0d6ce77 commit 0d65246
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions cli/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use {
},
stake_history::{Epoch, StakeHistory},
system_instruction::{self, SystemError},
system_program,
sysvar::{clock, stake_history},
transaction::Transaction,
},
Expand Down Expand Up @@ -1980,15 +1981,26 @@ pub fn process_split_stake(

let rent_exempt_reserve = if !sign_only {
if let Ok(stake_account) = rpc_client.get_account(&split_stake_account_address) {
let err_msg = if stake_account.owner == stake::program::id() {
format!("Stake account {split_stake_account_address} already exists")
if stake_account.owner == stake::program::id() {
return Err(CliError::BadParameter(format!(
"Stake account {split_stake_account_address} already exists"
))
.into());
} else if stake_account.owner == system_program::id() {
if !stake_account.data.is_empty() {
return Err(CliError::BadParameter(format!(
"Account {split_stake_account_address} has data and cannot be used to split stake"
))
.into());
}
// if `stake_account`'s owner is the system_program and its data is
// empty, `stake_account` is allowed to receive the stake split
} else {
format!(
"Account {split_stake_account_address} already exists and is not a stake \
account"
)
};
return Err(CliError::BadParameter(err_msg).into());
return Err(CliError::BadParameter(format!(
"Account {split_stake_account_address} already exists and cannot be used to split stake"
))
.into());
}
}

let minimum_balance =
Expand Down

0 comments on commit 0d65246

Please sign in to comment.