Skip to content

Commit

Permalink
Add InsufficientStakeDelegation error
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo committed May 3, 2022
1 parent e1412c6 commit 4150add
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
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 = "BQcJmh4VRCiNNtqjKPyphs9ULFbSUKGGfx6hz9SWBtqU")]
#[frozen_abi(digest = "3JVSVs9JHV2ZZNVTz3R6qKiFsaBYqzgTuxYjFJ1NwPSY")]
pub type BankSlotDelta = SlotDelta<Result<()>>;

// Eager rent collection repeats in cyclic manner.
Expand Down
3 changes: 3 additions & 0 deletions sdk/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ pub enum InstructionError {
/// Active vote account close
#[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,
// Note: For any new error added here an equivalent ProgramError and its
// conversions must also be added
}
Expand Down
8 changes: 8 additions & 0 deletions sdk/program/src/program_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ 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 @@ -95,6 +97,7 @@ 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 @@ -127,6 +130,7 @@ 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 @@ -155,6 +159,7 @@ 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 @@ -189,6 +194,7 @@ 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 @@ -219,6 +225,7 @@ 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 @@ -251,6 +258,7 @@ 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: 1 addition & 0 deletions storage-proto/proto/transaction_by_addr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ 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: 4 additions & 0 deletions storage-proto/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ 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 @@ -1003,6 +1004,9 @@ 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 4150add

Please sign in to comment.