Skip to content

Commit

Permalink
Add MINIMUM_STAKE_BALANCE constant
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo committed Feb 2, 2022
1 parent 75563f6 commit e66ae1e
Show file tree
Hide file tree
Showing 7 changed files with 430 additions and 69 deletions.
475 changes: 407 additions & 68 deletions programs/stake/src/stake_state.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl RentDebits {
}

type BankStatusCache = StatusCache<Result<()>>;
#[frozen_abi(digest = "6XkxpmzmKZguLZMS1KmU7N2dAcv8MmNhyobJCwRLkTdi")]
#[frozen_abi(digest = "EvhraCb1yPeNhvqLxzD9fkFSSUyPEyLxhEt37vAvG1Jo")]
pub type BankSlotDelta = SlotDelta<Result<()>>;

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

/// The amount of stake to delegate is too small
#[error("Stake delegation amount is too small")]
StakeDelegationTooSmall,
// 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 @@ -53,6 +53,8 @@ pub enum ProgramError {
AccountsDataBudgetExceeded,
#[error("Cannot close vote account unless it stopped voting at least one full epoch ago")]
ActiveVoteAccountClose,
#[error("Stake delegation amount is too small")]
StakeDelegationTooSmall,
}

pub trait PrintProgramError {
Expand Down Expand Up @@ -93,6 +95,7 @@ impl PrintProgramError for ProgramError {
Self::IllegalOwner => msg!("Error: IllegalOwner"),
Self::AccountsDataBudgetExceeded => msg!("Error: AccountsDataBudgetExceeded"),
Self::ActiveVoteAccountClose => msg!("Error: ActiveVoteAccountClose"),
Self::StakeDelegationTooSmall => msg!("Error: StakeDelegationTooSmall"),
}
}
}
Expand Down Expand Up @@ -125,6 +128,7 @@ pub const UNSUPPORTED_SYSVAR: u64 = to_builtin!(17);
pub const ILLEGAL_OWNER: u64 = to_builtin!(18);
pub const ACCOUNTS_DATA_BUDGET_EXCEEDED: u64 = to_builtin!(19);
pub const ACTIVE_VOTE_ACCOUNT_CLOSE: u64 = to_builtin!(20);
pub const STAKE_DELEGATION_TOO_SMALL: 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 @@ -153,6 +157,7 @@ impl From<ProgramError> for u64 {
ProgramError::IllegalOwner => ILLEGAL_OWNER,
ProgramError::AccountsDataBudgetExceeded => ACCOUNTS_DATA_BUDGET_EXCEEDED,
ProgramError::ActiveVoteAccountClose => ACTIVE_VOTE_ACCOUNT_CLOSE,
ProgramError::StakeDelegationTooSmall => STAKE_DELEGATION_TOO_SMALL,
ProgramError::Custom(error) => {
if error == 0 {
CUSTOM_ZERO
Expand Down Expand Up @@ -187,6 +192,7 @@ impl From<u64> for ProgramError {
ILLEGAL_OWNER => Self::IllegalOwner,
ACCOUNTS_DATA_BUDGET_EXCEEDED => Self::AccountsDataBudgetExceeded,
ACTIVE_VOTE_ACCOUNT_CLOSE => Self::ActiveVoteAccountClose,
STAKE_DELEGATION_TOO_SMALL => Self::StakeDelegationTooSmall,
_ => Self::Custom(error as u32),
}
}
Expand Down Expand Up @@ -217,6 +223,7 @@ impl TryFrom<InstructionError> for ProgramError {
Self::Error::IllegalOwner => Ok(Self::IllegalOwner),
Self::Error::AccountsDataBudgetExceeded => Ok(Self::AccountsDataBudgetExceeded),
Self::Error::ActiveVoteAccountClose => Ok(Self::ActiveVoteAccountClose),
Self::Error::StakeDelegationTooSmall => Ok(Self::StakeDelegationTooSmall),
_ => Err(error),
}
}
Expand Down Expand Up @@ -249,6 +256,7 @@ where
ILLEGAL_OWNER => Self::IllegalOwner,
ACCOUNTS_DATA_BUDGET_EXCEEDED => Self::AccountsDataBudgetExceeded,
ACTIVE_VOTE_ACCOUNT_CLOSE => Self::ActiveVoteAccountClose,
STAKE_DELEGATION_TOO_SMALL => Self::StakeDelegationTooSmall,
_ => {
// A valid custom error has no bits set in the upper 32
if error >> BUILTIN_BIT_SHIFT == 0 {
Expand Down
5 changes: 5 additions & 0 deletions sdk/program/src/stake/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ pub mod state;
pub mod program {
crate::declare_id!("Stake11111111111111111111111111111111111111");
}

/// The minimum stake amount that can be delegated, in lamports.
/// NOTE: This is also used to calculate the minimum balance of a stake account, which is the
/// rent exempt reserve _plus_ the minimum stake delegation.
pub const MINIMUM_STAKE_DELEGATION: u64 = 1;
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 @@ -114,6 +114,7 @@ enum InstructionErrorType {
ILLEGAL_OWNER = 49;
ACCOUNTS_DATA_BUDGET_EXCEEDED = 50;
ACTIVE_VOTE_ACCOUNT_CLOSE = 51;
STAKE_DELEGATION_TOO_SMALL = 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 @@ -690,6 +690,7 @@ impl TryFrom<tx_by_addr::TransactionError> for TransactionError {
49 => InstructionError::IllegalOwner,
50 => InstructionError::AccountsDataBudgetExceeded,
51 => InstructionError::ActiveVoteAccountClose,
52 => InstructionError::StakeDelegationTooSmall,
_ => return Err("Invalid InstructionError"),
};

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

0 comments on commit e66ae1e

Please sign in to comment.