Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 5d754f4

Browse files
committed
Update checks for deduping
1 parent 70038c4 commit 5d754f4

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

stake-pool/program/src/processor.rs

+30-31
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ impl Processor {
12051205
)?;
12061206
if validator_stake_info.transient_stake_lamports > 0 {
12071207
if maybe_ephemeral_stake_seed.is_none() {
1208-
msg!("Attempting to decrease stake on a validator with transient stake, use DecreaseAdditionalValidatorStake with the existing seed");
1208+
msg!("Attempting to decrease stake on a validator with pending transient stake, use DecreaseAdditionalValidatorStake with the existing seed");
12091209
return Err(StakePoolError::TransientAccountInUse.into());
12101210
}
12111211
if transient_stake_seed != validator_stake_info.transient_seed_suffix {
@@ -1246,9 +1246,10 @@ impl Processor {
12461246
return Err(ProgramError::InsufficientFunds);
12471247
}
12481248

1249-
let maybe_split_from_account_info =
1250-
if let Some(ephemeral_stake_seed) = maybe_ephemeral_stake_seed {
1251-
let ephemeral_stake_account_info = maybe_ephemeral_stake_account_info.unwrap();
1249+
let source_stake_account_info =
1250+
if let Some((ephemeral_stake_seed, ephemeral_stake_account_info)) =
1251+
maybe_ephemeral_stake_seed.zip(maybe_ephemeral_stake_account_info)
1252+
{
12521253
let ephemeral_stake_bump_seed = check_ephemeral_stake_address(
12531254
program_id,
12541255
stake_pool_info.key,
@@ -1287,39 +1288,37 @@ impl Processor {
12871288
stake_pool.stake_withdraw_bump_seed,
12881289
)?;
12891290

1290-
if validator_stake_info.transient_stake_lamports > 0 {
1291-
// transient stake exists, try to merge
1292-
let stake_history_info = maybe_stake_history_info.unwrap();
1293-
Self::stake_merge(
1294-
stake_pool_info.key,
1295-
ephemeral_stake_account_info.clone(),
1296-
withdraw_authority_info.clone(),
1297-
AUTHORITY_WITHDRAW,
1298-
stake_pool.stake_withdraw_bump_seed,
1299-
transient_stake_account_info.clone(),
1300-
clock_info.clone(),
1301-
stake_history_info.clone(),
1302-
stake_program_info.clone(),
1303-
)?;
1304-
None
1305-
} else {
1306-
// otherwise, split everything from the ephemeral stake, into the transient
1307-
Some(ephemeral_stake_account_info)
1308-
}
1291+
ephemeral_stake_account_info
13091292
} else {
13101293
// if no ephemeral account is provided, split everything from the
13111294
// validator stake account, into the transient stake account
1312-
Some(validator_stake_account_info)
1295+
validator_stake_account_info
13131296
};
13141297

1315-
if let Some(split_from_account_info) = maybe_split_from_account_info {
1316-
let transient_stake_bump_seed = check_transient_stake_address(
1317-
program_id,
1298+
let transient_stake_bump_seed = check_transient_stake_address(
1299+
program_id,
1300+
stake_pool_info.key,
1301+
transient_stake_account_info.key,
1302+
&vote_account_address,
1303+
transient_stake_seed,
1304+
)?;
1305+
1306+
if validator_stake_info.transient_stake_lamports > 0 {
1307+
let stake_history_info = maybe_stake_history_info.unwrap();
1308+
// transient stake exists, try to merge from the source account,
1309+
// which is always an ephemeral account
1310+
Self::stake_merge(
13181311
stake_pool_info.key,
1319-
transient_stake_account_info.key,
1320-
&vote_account_address,
1321-
transient_stake_seed,
1312+
source_stake_account_info.clone(),
1313+
withdraw_authority_info.clone(),
1314+
AUTHORITY_WITHDRAW,
1315+
stake_pool.stake_withdraw_bump_seed,
1316+
transient_stake_account_info.clone(),
1317+
clock_info.clone(),
1318+
stake_history_info.clone(),
1319+
stake_program_info.clone(),
13221320
)?;
1321+
} else {
13231322
let transient_stake_account_signer_seeds: &[&[_]] = &[
13241323
TRANSIENT_STAKE_SEED_PREFIX,
13251324
&vote_account_address.to_bytes(),
@@ -1337,7 +1336,7 @@ impl Processor {
13371336
// split into transient stake account
13381337
Self::stake_split(
13391338
stake_pool_info.key,
1340-
split_from_account_info.clone(),
1339+
source_stake_account_info.clone(),
13411340
withdraw_authority_info.clone(),
13421341
AUTHORITY_WITHDRAW,
13431342
stake_pool.stake_withdraw_bump_seed,

0 commit comments

Comments
 (0)