Skip to content

Commit

Permalink
Address feedback: no new error type, more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joncinque committed May 3, 2022
1 parent 66e8ec2 commit da3efde
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 25 deletions.
9 changes: 3 additions & 6 deletions programs/stake/src/stake_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3248,7 +3248,7 @@ mod tests {
},
];

// should pass, withdrawing account down to minimum balance
// should pass, withdrawing initialized account down to minimum balance
process_instruction(
&serialize(&StakeInstruction::Withdraw(stake_lamports)).unwrap(),
transaction_accounts.clone(),
Expand Down Expand Up @@ -3765,10 +3765,7 @@ mod tests {
];
for (stake_delegation, expected_result) in [
(minimum_delegation, Ok(())),
(
minimum_delegation - 1,
Err(InstructionError::InsufficientStakeDelegation),
),
(minimum_delegation - 1, Err(StakeError::InsufficientStake)),
] {
for stake_state in &[
StakeState::Initialized(meta),
Expand Down Expand Up @@ -3800,7 +3797,7 @@ mod tests {
),
],
instruction_accounts.clone(),
expected_result.clone(),
expected_result.clone().map_err(|e| e.into()),
);
}
}
Expand Down
8 changes: 7 additions & 1 deletion programs/stake/src/stake_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,10 +1027,16 @@ fn validate_delegated_amount(
let stake_amount = account
.get_lamports()
.saturating_sub(meta.rent_exempt_reserve); // can't stake the rent

// Previously, `initialize` checked that the stake account balance met
// the minimum delegation amount.
// With the `stake_allow_zero_undelegated_amount` feature, stake accounts
// may be initialized with a lower balance, so check the minimum in this
// function, on delegation.
if feature_set.is_active(&stake_allow_zero_undelegated_amount::id())
&& stake_amount < crate::get_minimum_delegation(feature_set)
{
return Err(InstructionError::InsufficientStakeDelegation);
return Err(StakeError::InsufficientStake.into());
}
Ok(ValidatedDelegatedInfo { stake_amount })
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl RentDebits {
}

type BankStatusCache = StatusCache<Result<()>>;
#[frozen_abi(digest = "3JVSVs9JHV2ZZNVTz3R6qKiFsaBYqzgTuxYjFJ1NwPSY")]
#[frozen_abi(digest = "BQcJmh4VRCiNNtqjKPyphs9ULFbSUKGGfx6hz9SWBtqU")]
pub type BankSlotDelta = SlotDelta<Result<()>>;

// Eager rent collection repeats in cyclic manner.
Expand Down
4 changes: 0 additions & 4 deletions sdk/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,6 @@ pub enum InstructionError {
/// Active vote account close
#[error("Cannot close vote account unless it stopped voting at least one full epoch ago")]
ActiveVoteAccountClose,

// Insufficient stake delegation
#[error("Stake amount is below the minimum delegation requirements")]
InsufficientStakeDelegation,
// Note: For any new error added here an equivalent ProgramError and its
// conversions must also be added
}
Expand Down
8 changes: 0 additions & 8 deletions sdk/program/src/program_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ pub enum ProgramError {
MaxAccountsDataSizeExceeded,
#[error("Cannot close vote account unless it stopped voting at least one full epoch ago")]
ActiveVoteAccountClose,
#[error("Stake amount is below the minimum delegation requirements")]
InsufficientStakeDelegation,
}

pub trait PrintProgramError {
Expand Down Expand Up @@ -97,7 +95,6 @@ impl PrintProgramError for ProgramError {
Self::IllegalOwner => msg!("Error: IllegalOwner"),
Self::MaxAccountsDataSizeExceeded => msg!("Error: MaxAccountsDataSizeExceeded"),
Self::ActiveVoteAccountClose => msg!("Error: ActiveVoteAccountClose"),
Self::InsufficientStakeDelegation => msg!("Error: InsufficientStakeDelegation"),
}
}
}
Expand Down Expand Up @@ -130,7 +127,6 @@ pub const UNSUPPORTED_SYSVAR: u64 = to_builtin!(17);
pub const ILLEGAL_OWNER: u64 = to_builtin!(18);
pub const MAX_ACCOUNTS_DATA_SIZE_EXCEEDED: u64 = to_builtin!(19);
pub const ACTIVE_VOTE_ACCOUNT_CLOSE: u64 = to_builtin!(20);
pub const INSUFFICIENT_STAKE_DELEGATION: u64 = to_builtin!(21);
// Warning: Any new program errors added here must also be:
// - Added to the below conversions
// - Added as an equivilent to InstructionError
Expand Down Expand Up @@ -159,7 +155,6 @@ impl From<ProgramError> for u64 {
ProgramError::IllegalOwner => ILLEGAL_OWNER,
ProgramError::MaxAccountsDataSizeExceeded => MAX_ACCOUNTS_DATA_SIZE_EXCEEDED,
ProgramError::ActiveVoteAccountClose => ACTIVE_VOTE_ACCOUNT_CLOSE,
ProgramError::InsufficientStakeDelegation => INSUFFICIENT_STAKE_DELEGATION,
ProgramError::Custom(error) => {
if error == 0 {
CUSTOM_ZERO
Expand Down Expand Up @@ -194,7 +189,6 @@ impl From<u64> for ProgramError {
ILLEGAL_OWNER => Self::IllegalOwner,
MAX_ACCOUNTS_DATA_SIZE_EXCEEDED => Self::MaxAccountsDataSizeExceeded,
ACTIVE_VOTE_ACCOUNT_CLOSE => Self::ActiveVoteAccountClose,
INSUFFICIENT_STAKE_DELEGATION => Self::InsufficientStakeDelegation,
_ => Self::Custom(error as u32),
}
}
Expand Down Expand Up @@ -225,7 +219,6 @@ impl TryFrom<InstructionError> for ProgramError {
Self::Error::IllegalOwner => Ok(Self::IllegalOwner),
Self::Error::MaxAccountsDataSizeExceeded => Ok(Self::MaxAccountsDataSizeExceeded),
Self::Error::ActiveVoteAccountClose => Ok(Self::ActiveVoteAccountClose),
Self::Error::InsufficientStakeDelegation => Ok(Self::InsufficientStakeDelegation),
_ => Err(error),
}
}
Expand Down Expand Up @@ -258,7 +251,6 @@ where
ILLEGAL_OWNER => Self::IllegalOwner,
MAX_ACCOUNTS_DATA_SIZE_EXCEEDED => Self::MaxAccountsDataSizeExceeded,
ACTIVE_VOTE_ACCOUNT_CLOSE => Self::ActiveVoteAccountClose,
INSUFFICIENT_STAKE_DELEGATION => Self::InsufficientStakeDelegation,
_ => {
// A valid custom error has no bits set in the upper 32
if error >> BUILTIN_BIT_SHIFT == 0 {
Expand Down
1 change: 0 additions & 1 deletion storage-proto/proto/transaction_by_addr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ enum InstructionErrorType {
ILLEGAL_OWNER = 49;
MAX_ACCOUNTS_DATA_SIZE_EXCEEDED = 50;
ACTIVE_VOTE_ACCOUNT_CLOSE = 51;
INSUFFICIENT_STAKE_DELEGATION = 52;
}

message UnixTimestamp {
Expand Down
4 changes: 0 additions & 4 deletions storage-proto/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,6 @@ impl TryFrom<tx_by_addr::TransactionError> for TransactionError {
49 => InstructionError::IllegalOwner,
50 => InstructionError::MaxAccountsDataSizeExceeded,
51 => InstructionError::ActiveVoteAccountClose,
52 => InstructionError::InsufficientStakeDelegation,
_ => return Err("Invalid InstructionError"),
};

Expand Down Expand Up @@ -1004,9 +1003,6 @@ impl From<TransactionError> for tx_by_addr::TransactionError {
InstructionError::ActiveVoteAccountClose => {
tx_by_addr::InstructionErrorType::ActiveVoteAccountClose
}
InstructionError::InsufficientStakeDelegation => {
tx_by_addr::InstructionErrorType::InsufficientStakeDelegation
}
} as i32,
custom: match instruction_error {
InstructionError::Custom(custom) => {
Expand Down

0 comments on commit da3efde

Please sign in to comment.