From 4150add5630a38c3daae53c2a464ec7709d88eb9 Mon Sep 17 00:00:00 2001 From: Brooks Prumo Date: Thu, 14 Apr 2022 16:41:00 -0500 Subject: [PATCH] Add InsufficientStakeDelegation error --- runtime/src/bank.rs | 2 +- sdk/program/src/instruction.rs | 3 +++ sdk/program/src/program_error.rs | 8 ++++++++ storage-proto/proto/transaction_by_addr.proto | 1 + storage-proto/src/convert.rs | 4 ++++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 1ef3761d749e4b..fc311c96cae63e 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -239,7 +239,7 @@ impl RentDebits { } type BankStatusCache = StatusCache>; -#[frozen_abi(digest = "BQcJmh4VRCiNNtqjKPyphs9ULFbSUKGGfx6hz9SWBtqU")] +#[frozen_abi(digest = "3JVSVs9JHV2ZZNVTz3R6qKiFsaBYqzgTuxYjFJ1NwPSY")] pub type BankSlotDelta = SlotDelta>; // Eager rent collection repeats in cyclic manner. diff --git a/sdk/program/src/instruction.rs b/sdk/program/src/instruction.rs index 0de8f9337fcf2e..fc38a19febe50a 100644 --- a/sdk/program/src/instruction.rs +++ b/sdk/program/src/instruction.rs @@ -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 } diff --git a/sdk/program/src/program_error.rs b/sdk/program/src/program_error.rs index d0e7e7643b4c07..32069ad93093f2 100644 --- a/sdk/program/src/program_error.rs +++ b/sdk/program/src/program_error.rs @@ -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 { @@ -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"), } } } @@ -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 @@ -155,6 +159,7 @@ impl From 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 @@ -189,6 +194,7 @@ impl From 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), } } @@ -219,6 +225,7 @@ impl TryFrom 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), } } @@ -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 { diff --git a/storage-proto/proto/transaction_by_addr.proto b/storage-proto/proto/transaction_by_addr.proto index f4896906864efe..0211042b1bf7a7 100644 --- a/storage-proto/proto/transaction_by_addr.proto +++ b/storage-proto/proto/transaction_by_addr.proto @@ -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 { diff --git a/storage-proto/src/convert.rs b/storage-proto/src/convert.rs index 997898ea6062f7..8b6fcfa7ab9bad 100644 --- a/storage-proto/src/convert.rs +++ b/storage-proto/src/convert.rs @@ -706,6 +706,7 @@ impl TryFrom for TransactionError { 49 => InstructionError::IllegalOwner, 50 => InstructionError::MaxAccountsDataSizeExceeded, 51 => InstructionError::ActiveVoteAccountClose, + 52 => InstructionError::InsufficientStakeDelegation, _ => return Err("Invalid InstructionError"), }; @@ -1003,6 +1004,9 @@ impl From 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) => {