Stake program update (#15308)
This commit is contained in:
@ -54,6 +54,13 @@ impl Default for StakeState {
|
||||
}
|
||||
}
|
||||
|
||||
fn checked_add(a: u64, b: u64) -> Result<u64, InstructionError> {
|
||||
match a.checked_add(b) {
|
||||
Some(sum) => Ok(sum),
|
||||
None => Err(InstructionError::InsufficientFunds),
|
||||
}
|
||||
}
|
||||
|
||||
impl StakeState {
|
||||
pub fn get_rent_exempt_reserve(rent: &Rent) -> u64 {
|
||||
rent.minimum_balance(std::mem::size_of::<StakeState>())
|
||||
@ -1207,7 +1214,8 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
|
||||
stake.delegation.stake
|
||||
};
|
||||
|
||||
(meta.lockup, staked + meta.rent_exempt_reserve, staked != 0)
|
||||
let staked_and_reserve = checked_add(staked, meta.rent_exempt_reserve)?;
|
||||
(meta.lockup, staked_and_reserve, staked != 0)
|
||||
}
|
||||
StakeState::Initialized(meta) => {
|
||||
meta.authorized
|
||||
@ -1231,15 +1239,16 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
|
||||
return Err(StakeError::LockupInForce.into());
|
||||
}
|
||||
|
||||
let lamports_and_reserve = checked_add(lamports, reserve)?;
|
||||
// if the stake is active, we mustn't allow the account to go away
|
||||
if is_staked // line coverage for branch coverage
|
||||
&& lamports + reserve > self.lamports()?
|
||||
&& lamports_and_reserve > self.lamports()?
|
||||
{
|
||||
return Err(InstructionError::InsufficientFunds);
|
||||
}
|
||||
|
||||
if lamports != self.lamports()? // not a full withdrawal
|
||||
&& lamports + reserve > self.lamports()?
|
||||
&& lamports_and_reserve > self.lamports()?
|
||||
{
|
||||
assert!(!is_staked);
|
||||
return Err(InstructionError::InsufficientFunds);
|
||||
|
Reference in New Issue
Block a user