Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
stake-pool: revert WrongStakeStateV2
Browse files Browse the repository at this point in the history
  • Loading branch information
2501babe committed Oct 19, 2023
1 parent a39f15f commit d6491c0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 27 deletions.
4 changes: 2 additions & 2 deletions stake-pool/program/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ pub enum StakePoolError {
#[error("WrongPoolMint")]
WrongPoolMint,
/// Stake account is not in the state expected by the program.
#[error("WrongStakeStateV2")]
WrongStakeStateV2,
#[error("WrongStakeStake")]
WrongStakeStake,
/// User stake is not active
#[error("UserStakeNotActive")]
UserStakeNotActive,
Expand Down
32 changes: 15 additions & 17 deletions stake-pool/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn get_stake_state(
try_from_slice_unchecked::<stake::state::StakeStateV2>(&stake_account_info.data.borrow())?;
match stake_state {
stake::state::StakeStateV2::Stake(meta, stake, _) => Ok((meta, stake)),
_ => Err(StakePoolError::WrongStakeStateV2.into()),
_ => Err(StakePoolError::WrongStakeStake.into()),
}
}

Expand Down Expand Up @@ -224,7 +224,7 @@ fn check_if_stake_deactivating(
vote_account_address,
epoch,
);
Err(StakePoolError::WrongStakeStateV2.into())
Err(StakePoolError::WrongStakeStake.into())
} else {
Ok(())
}
Expand All @@ -246,7 +246,7 @@ fn check_if_stake_activating(
vote_account_address,
epoch,
);
Err(StakePoolError::WrongStakeStateV2.into())
Err(StakePoolError::WrongStakeStake.into())
} else {
Ok(())
}
Expand All @@ -266,15 +266,15 @@ fn check_stake_state(
"Validator stake for {} not usable by pool, must be owned by withdraw authority",
vote_account_address
);
return Err(StakePoolError::WrongStakeStateV2.into());
return Err(StakePoolError::WrongStakeStake.into());
}
if stake.delegation.voter_pubkey != *vote_account_address {
msg!(
"Validator stake {} not delegated to {}",
stake_account_info.key,
vote_account_address
);
return Err(StakePoolError::WrongStakeStateV2.into());
return Err(StakePoolError::WrongStakeStake.into());
}
Ok(())
}
Expand Down Expand Up @@ -869,7 +869,7 @@ impl Processor {
let total_lamports = if let stake::state::StakeStateV2::Initialized(meta) = stake_state {
if meta.lockup != stake::state::Lockup::default() {
msg!("Reserve stake account has some lockup");
return Err(StakePoolError::WrongStakeStateV2.into());
return Err(StakePoolError::WrongStakeStake.into());
}

if meta.authorized.staker != withdraw_authority_key {
Expand All @@ -878,7 +878,7 @@ impl Processor {
meta.authorized.staker,
withdraw_authority_key
);
return Err(StakePoolError::WrongStakeStateV2.into());
return Err(StakePoolError::WrongStakeStake.into());
}

if meta.authorized.withdrawer != withdraw_authority_key {
Expand All @@ -887,15 +887,15 @@ impl Processor {
meta.authorized.staker,
withdraw_authority_key
);
return Err(StakePoolError::WrongStakeStateV2.into());
return Err(StakePoolError::WrongStakeStake.into());
}
reserve_stake_info
.lamports()
.checked_sub(minimum_reserve_lamports(&meta))
.ok_or(StakePoolError::CalculationFailure)?
} else {
msg!("Reserve stake account not in intialized state");
return Err(StakePoolError::WrongStakeStateV2.into());
return Err(StakePoolError::WrongStakeStake.into());
};

if total_lamports > 0 {
Expand Down Expand Up @@ -1047,7 +1047,7 @@ impl Processor {
)?;
let reserve_meta = reserve_stake
.meta()
.ok_or(StakePoolError::WrongStakeStateV2)?;
.ok_or(StakePoolError::WrongStakeStake)?;
let minimum_lamports = minimum_reserve_lamports(&reserve_meta);
let reserve_lamports = reserve_stake_info.lamports();
if reserve_lamports.saturating_sub(required_lamports) < minimum_lamports {
Expand Down Expand Up @@ -2589,7 +2589,7 @@ impl Processor {
.ok_or(StakePoolError::CalculationFailure)?
} else {
msg!("Reserve stake account in unknown state, aborting");
return Err(StakePoolError::WrongStakeStateV2.into());
return Err(StakePoolError::WrongStakeStake.into());
};
for validator_stake_record in validator_list
.deserialize_slice::<ValidatorStakeInfo>(0, validator_list.len() as usize)?
Expand Down Expand Up @@ -3191,9 +3191,7 @@ impl Processor {
let stake_state = try_from_slice_unchecked::<stake::state::StakeStateV2>(
&stake_split_from.data.borrow(),
)?;
let meta = stake_state
.meta()
.ok_or(StakePoolError::WrongStakeStateV2)?;
let meta = stake_state.meta().ok_or(StakePoolError::WrongStakeStake)?;
let required_lamports = minimum_stake_lamports(&meta, stake_minimum_delegation);

let lamports_per_pool_token = stake_pool
Expand Down Expand Up @@ -3235,7 +3233,7 @@ impl Processor {
} else {
let delegation = stake_state
.delegation()
.ok_or(StakePoolError::WrongStakeStateV2)?;
.ok_or(StakePoolError::WrongStakeStake)?;
let vote_account_address = delegation.voter_pubkey;

if let Some(preferred_withdraw_validator) =
Expand Down Expand Up @@ -3515,7 +3513,7 @@ impl Processor {
}
} else {
msg!("Reserve stake account not in intialized state");
return Err(StakePoolError::WrongStakeStateV2.into());
return Err(StakePoolError::WrongStakeStake.into());
};

Self::token_burn(
Expand Down Expand Up @@ -4086,7 +4084,7 @@ impl PrintProgramError for StakePoolError {
StakePoolError::InvalidValidatorStakeList => msg!("Error: Invalid validator stake list account"),
StakePoolError::InvalidFeeAccount => msg!("Error: Invalid manager fee account"),
StakePoolError::WrongPoolMint => msg!("Error: Specified pool mint account is wrong"),
StakePoolError::WrongStakeStateV2 => msg!("Error: Stake account is not in the state expected by the program"),
StakePoolError::WrongStakeStake => msg!("Error: Stake account is not in the state expected by the program"),
StakePoolError::UserStakeNotActive => msg!("Error: User stake is not active"),
StakePoolError::ValidatorAlreadyAdded => msg!("Error: Stake account voting for this validator already exists in the pool"),
StakePoolError::ValidatorNotFound => msg!("Error: Stake account for this validator not found in the pool"),
Expand Down
2 changes: 1 addition & 1 deletion stake-pool/program/tests/decrease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,6 @@ async fn fail_additional_with_increasing() {
TransactionError::InstructionError(
_,
InstructionError::Custom(code)
) if code == StakePoolError::WrongStakeStateV2 as u32
) if code == StakePoolError::WrongStakeStake as u32
);
}
2 changes: 1 addition & 1 deletion stake-pool/program/tests/force_destake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ async fn fail_increase() {
error,
TransactionError::InstructionError(
0,
InstructionError::Custom(StakePoolError::WrongStakeStateV2 as u32)
InstructionError::Custom(StakePoolError::WrongStakeStake as u32)
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion stake-pool/program/tests/increase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ async fn fail_additional_with_decreasing() {
error,
TransactionError::InstructionError(
0,
InstructionError::Custom(StakePoolError::WrongStakeStateV2 as u32)
InstructionError::Custom(StakePoolError::WrongStakeStake as u32)
)
);
}
Expand Down
8 changes: 4 additions & 4 deletions stake-pool/program/tests/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ async fn fail_with_bad_reserve() {
error,
TransactionError::InstructionError(
2,
InstructionError::Custom(error::StakePoolError::WrongStakeStateV2 as u32),
InstructionError::Custom(error::StakePoolError::WrongStakeStake as u32),
)
);
}
Expand Down Expand Up @@ -1465,7 +1465,7 @@ async fn fail_with_bad_reserve() {
error,
TransactionError::InstructionError(
2,
InstructionError::Custom(error::StakePoolError::WrongStakeStateV2 as u32),
InstructionError::Custom(error::StakePoolError::WrongStakeStake as u32),
)
);
}
Expand Down Expand Up @@ -1520,7 +1520,7 @@ async fn fail_with_bad_reserve() {
error,
TransactionError::InstructionError(
2,
InstructionError::Custom(error::StakePoolError::WrongStakeStateV2 as u32),
InstructionError::Custom(error::StakePoolError::WrongStakeStake as u32),
)
);
}
Expand Down Expand Up @@ -1576,7 +1576,7 @@ async fn fail_with_bad_reserve() {
error,
TransactionError::InstructionError(
2,
InstructionError::Custom(error::StakePoolError::WrongStakeStateV2 as u32),
InstructionError::Custom(error::StakePoolError::WrongStakeStake as u32),
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion stake-pool/program/tests/redelegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ async fn fail_with_decreasing_stake() {
error,
TransactionError::InstructionError(
0,
InstructionError::Custom(StakePoolError::WrongStakeStateV2 as u32)
InstructionError::Custom(StakePoolError::WrongStakeStake as u32)
)
);
}
Expand Down

0 comments on commit d6491c0

Please sign in to comment.