(cherry picked from commit 800472ddf5
)
Co-authored-by: Brooks Prumo <brooks@solana.com>
This commit is contained in:
@ -248,6 +248,10 @@ pub enum InstructionError {
|
||||
/// Illegal account owner
|
||||
#[error("Provided owner is not allowed")]
|
||||
IllegalOwner,
|
||||
|
||||
/// Accounts data budget exceeded
|
||||
#[error("Requested account data allocation exceeded the accounts data budget")]
|
||||
AccountsDataBudgetExceeded,
|
||||
// Note: For any new error added here an equivalent ProgramError and its
|
||||
// conversions must also be added
|
||||
}
|
||||
|
@ -49,6 +49,8 @@ pub enum ProgramError {
|
||||
UnsupportedSysvar,
|
||||
#[error("Provided owner is not allowed")]
|
||||
IllegalOwner,
|
||||
#[error("Requested account data allocation exceeded the accounts data budget")]
|
||||
AccountsDataBudgetExceeded,
|
||||
}
|
||||
|
||||
pub trait PrintProgramError {
|
||||
@ -87,6 +89,7 @@ impl PrintProgramError for ProgramError {
|
||||
Self::AccountNotRentExempt => msg!("Error: AccountNotRentExempt"),
|
||||
Self::UnsupportedSysvar => msg!("Error: UnsupportedSysvar"),
|
||||
Self::IllegalOwner => msg!("Error: IllegalOwner"),
|
||||
Self::AccountsDataBudgetExceeded => msg!("Error: AccountsDataBudgetExceeded"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -117,6 +120,7 @@ pub const BORSH_IO_ERROR: u64 = to_builtin!(15);
|
||||
pub const ACCOUNT_NOT_RENT_EXEMPT: u64 = to_builtin!(16);
|
||||
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);
|
||||
// Warning: Any new program errors added here must also be:
|
||||
// - Added to the below conversions
|
||||
// - Added as an equivilent to InstructionError
|
||||
@ -143,6 +147,7 @@ impl From<ProgramError> for u64 {
|
||||
ProgramError::AccountNotRentExempt => ACCOUNT_NOT_RENT_EXEMPT,
|
||||
ProgramError::UnsupportedSysvar => UNSUPPORTED_SYSVAR,
|
||||
ProgramError::IllegalOwner => ILLEGAL_OWNER,
|
||||
ProgramError::AccountsDataBudgetExceeded => ACCOUNTS_DATA_BUDGET_EXCEEDED,
|
||||
ProgramError::Custom(error) => {
|
||||
if error == 0 {
|
||||
CUSTOM_ZERO
|
||||
@ -175,6 +180,7 @@ impl From<u64> for ProgramError {
|
||||
ACCOUNT_NOT_RENT_EXEMPT => Self::AccountNotRentExempt,
|
||||
UNSUPPORTED_SYSVAR => Self::UnsupportedSysvar,
|
||||
ILLEGAL_OWNER => Self::IllegalOwner,
|
||||
ACCOUNTS_DATA_BUDGET_EXCEEDED => Self::AccountsDataBudgetExceeded,
|
||||
_ => Self::Custom(error as u32),
|
||||
}
|
||||
}
|
||||
@ -203,6 +209,7 @@ impl TryFrom<InstructionError> for ProgramError {
|
||||
Self::Error::AccountNotRentExempt => Ok(Self::AccountNotRentExempt),
|
||||
Self::Error::UnsupportedSysvar => Ok(Self::UnsupportedSysvar),
|
||||
Self::Error::IllegalOwner => Ok(Self::IllegalOwner),
|
||||
Self::Error::AccountsDataBudgetExceeded => Ok(Self::AccountsDataBudgetExceeded),
|
||||
_ => Err(error),
|
||||
}
|
||||
}
|
||||
@ -233,6 +240,7 @@ where
|
||||
ACCOUNT_NOT_RENT_EXEMPT => Self::AccountNotRentExempt,
|
||||
UNSUPPORTED_SYSVAR => Self::UnsupportedSysvar,
|
||||
ILLEGAL_OWNER => Self::IllegalOwner,
|
||||
ACCOUNTS_DATA_BUDGET_EXCEEDED => Self::AccountsDataBudgetExceeded,
|
||||
_ => {
|
||||
// A valid custom error has no bits set in the upper 32
|
||||
if error >> BUILTIN_BIT_SHIFT == 0 {
|
||||
|
@ -275,6 +275,10 @@ pub mod reject_all_elf_rw {
|
||||
solana_sdk::declare_id!("DeMpxgMq51j3rZfNK2hQKZyXknQvqevPSFPJFNTbXxsS");
|
||||
}
|
||||
|
||||
pub mod cap_accounts_data_len {
|
||||
solana_sdk::declare_id!("capRxUrBjNkkCpjrJxPGfPaWijB7q3JoDfsWXAnt46r");
|
||||
}
|
||||
|
||||
pub mod max_tx_account_locks {
|
||||
solana_sdk::declare_id!("CBkDroRDqm8HwHe6ak9cguPjUomrASEkfmxEaZ5CNNxz");
|
||||
}
|
||||
@ -342,6 +346,7 @@ lazy_static! {
|
||||
(reject_non_rent_exempt_vote_withdraws::id(), "fail vote withdraw instructions which leave the account non-rent-exempt"),
|
||||
(evict_invalid_stakes_cache_entries::id(), "evict invalid stakes cache entries on epoch boundaries"),
|
||||
(reject_all_elf_rw::id(), "reject all read-write data in program elfs"),
|
||||
(cap_accounts_data_len::id(), "cap the accounts data len"),
|
||||
(max_tx_account_locks::id(), "enforce max number of locked accounts per transaction"),
|
||||
/*************** ADD NEW FEATURES HERE ***************/
|
||||
]
|
||||
|
Reference in New Issue
Block a user