Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tao-stones committed Mar 21, 2023
1 parent 8d368df commit de8a840
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 27 deletions.
4 changes: 1 addition & 3 deletions program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,15 +773,13 @@ impl<'a> InvokeContext<'a> {
let post_remaining_units = self.get_remaining();
*compute_units_consumed = pre_remaining_units.saturating_sub(post_remaining_units);

// startign from feature `native_programs_consume_cu`, all builtin programs should consume
// compute unitsi, otherwise will result to InstructionError.
if is_builtin_program
&& *compute_units_consumed == 0
&& self
.feature_set
.is_active(&native_programs_consume_cu::id())
{
return Err(InstructionError::BuiltinProgramsMustConsumeUnits);
return Err(InstructionError::BuiltinProgramsMustConsumeComputeUnits);
}

process_executable_chain_time.stop();
Expand Down
4 changes: 2 additions & 2 deletions program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ impl Default for ProgramTest {

// deactivate feature `native_program_consume_cu` to continue support existing mock/test
// programs that do not consume units.
let mut deactivate_feature_set = HashSet::default();
deactivate_feature_set.insert(solana_sdk::feature_set::native_programs_consume_cu::id());
let deactivate_feature_set =
HashSet::from([solana_sdk::feature_set::native_programs_consume_cu::id()]);

Self {
accounts: vec![],
Expand Down
13 changes: 6 additions & 7 deletions programs/sbf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2181,18 +2181,17 @@ fn test_program_sbf_disguised_as_sbf_loader() {

for program in programs.iter() {
let GenesisConfigInfo {
mut genesis_config,
genesis_config,
mint_keypair,
..
} = create_genesis_config(50);
// disable native_programs_consume_cu feature to allow test program
// not consume units.
genesis_config
.accounts
.remove(&solana_sdk::feature_set::native_programs_consume_cu::id())
.unwrap();

let mut bank = Bank::new_for_tests(&genesis_config);
// disable native_programs_consume_cu feature to allow test program
// not consume units.
let mut feature_set = FeatureSet::all_enabled();
feature_set.deactivate(&solana_sdk::feature_set::native_programs_consume_cu::id());
bank.feature_set = Arc::new(feature_set);
let (name, id, entrypoint) = solana_bpf_loader_program!();
bank.add_builtin(&name, &id, entrypoint);
bank.deactivate_feature(
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl RentDebits {
}

pub type BankStatusCache = StatusCache<Result<()>>;
#[frozen_abi(digest = "FT6XYtzchg9h2JACEKKf8FZD5skSnPzKY4YrJ1jUWr8U")]
#[frozen_abi(digest = "GBTLfFjModD9ykS9LV4pGi4S8eCrUj2JjWSDQLf8tMwV")]
pub type BankSlotDelta = SlotDelta<Result<()>>;

// Eager rent collection repeats in cyclic manner.
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ pub enum InstructionError {

/// Builtin programs must consume compute units
#[error("Builtin programs must consume compute units")]
BuiltinProgramsMustConsumeUnits,
BuiltinProgramsMustConsumeComputeUnits,
// Note: For any new error added here an equivalent ProgramError and its
// conversions must also be added
}
Expand Down
24 changes: 15 additions & 9 deletions sdk/program/src/program_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub enum ProgramError {
#[error("Instruction trace length exceeded the maximum allowed per transaction")]
MaxInstructionTraceLengthExceeded,
#[error("Builtin programs must consume compute units")]
BuiltinProgramsMustConsumeUnits,
BuiltinProgramsMustConsumeComputeUnits,
}

pub trait PrintProgramError {
Expand Down Expand Up @@ -104,8 +104,8 @@ impl PrintProgramError for ProgramError {
Self::MaxInstructionTraceLengthExceeded => {
msg!("Error: MaxInstructionTraceLengthExceeded")
}
Self::BuiltinProgramsMustConsumeUnits => {
msg!("Error: BuiltinProgramsMustConsumeUnits")
Self::BuiltinProgramsMustConsumeComputeUnits => {
msg!("Error: BuiltinProgramsMustConsumeComputeUnits")
}
}
}
Expand Down Expand Up @@ -140,7 +140,7 @@ pub const ILLEGAL_OWNER: u64 = to_builtin!(18);
pub const MAX_ACCOUNTS_DATA_ALLOCATIONS_EXCEEDED: u64 = to_builtin!(19);
pub const INVALID_ACCOUNT_DATA_REALLOC: u64 = to_builtin!(20);
pub const MAX_INSTRUCTION_TRACE_LENGTH_EXCEEDED: u64 = to_builtin!(21);
pub const BUILTIN_PROGRAMS_MUST_CONSUME_UNITS: u64 = to_builtin!(22);
pub const BUILTIN_PROGRAMS_MUST_CONSUME_COMPUTE_UNITS: u64 = to_builtin!(22);
// Warning: Any new program errors added here must also be:
// - Added to the below conversions
// - Added as an equivalent to InstructionError
Expand Down Expand Up @@ -174,7 +174,9 @@ impl From<ProgramError> for u64 {
ProgramError::MaxInstructionTraceLengthExceeded => {
MAX_INSTRUCTION_TRACE_LENGTH_EXCEEDED
}
ProgramError::BuiltinProgramsMustConsumeUnits => BUILTIN_PROGRAMS_MUST_CONSUME_UNITS,
ProgramError::BuiltinProgramsMustConsumeComputeUnits => {
BUILTIN_PROGRAMS_MUST_CONSUME_COMPUTE_UNITS
}
ProgramError::Custom(error) => {
if error == 0 {
CUSTOM_ZERO
Expand Down Expand Up @@ -210,7 +212,9 @@ impl From<u64> for ProgramError {
MAX_ACCOUNTS_DATA_ALLOCATIONS_EXCEEDED => Self::MaxAccountsDataAllocationsExceeded,
INVALID_ACCOUNT_DATA_REALLOC => Self::InvalidRealloc,
MAX_INSTRUCTION_TRACE_LENGTH_EXCEEDED => Self::MaxInstructionTraceLengthExceeded,
BUILTIN_PROGRAMS_MUST_CONSUME_UNITS => Self::BuiltinProgramsMustConsumeUnits,
BUILTIN_PROGRAMS_MUST_CONSUME_COMPUTE_UNITS => {
Self::BuiltinProgramsMustConsumeComputeUnits
}
_ => Self::Custom(error as u32),
}
}
Expand Down Expand Up @@ -246,8 +250,8 @@ impl TryFrom<InstructionError> for ProgramError {
Self::Error::MaxInstructionTraceLengthExceeded => {
Ok(Self::MaxInstructionTraceLengthExceeded)
}
Self::Error::BuiltinProgramsMustConsumeUnits => {
Ok(Self::BuiltinProgramsMustConsumeUnits)
Self::Error::BuiltinProgramsMustConsumeComputeUnits => {
Ok(Self::BuiltinProgramsMustConsumeComputeUnits)
}
_ => Err(error),
}
Expand Down Expand Up @@ -282,7 +286,9 @@ where
MAX_ACCOUNTS_DATA_ALLOCATIONS_EXCEEDED => Self::MaxAccountsDataAllocationsExceeded,
INVALID_ACCOUNT_DATA_REALLOC => Self::InvalidRealloc,
MAX_INSTRUCTION_TRACE_LENGTH_EXCEEDED => Self::MaxInstructionTraceLengthExceeded,
BUILTIN_PROGRAMS_MUST_CONSUME_UNITS => Self::BuiltinProgramsMustConsumeUnits,
BUILTIN_PROGRAMS_MUST_CONSUME_COMPUTE_UNITS => {
Self::BuiltinProgramsMustConsumeComputeUnits
}
_ => {
// A valid custom error has no bits set in the upper 32
if error >> BUILTIN_BIT_SHIFT == 0 {
Expand Down
2 changes: 1 addition & 1 deletion storage-proto/proto/transaction_by_addr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ enum InstructionErrorType {
MAX_ACCOUNTS_DATA_ALLOCATIONS_EXCEEDED = 50;
MAX_ACCOUNTS_EXCEEDED = 51;
MAX_INSTRUCTION_TRACE_LENGTH_EXCEEDED = 52;
BUILTIN_PROGRAMS_MUST_CONSUME_UNITS = 53;
BUILTIN_PROGRAMS_MUST_CONSUME_COMPUTE_UNITS = 53;
}

message UnixTimestamp {
Expand Down
6 changes: 3 additions & 3 deletions storage-proto/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ impl TryFrom<tx_by_addr::TransactionError> for TransactionError {
50 => InstructionError::MaxAccountsDataAllocationsExceeded,
51 => InstructionError::MaxAccountsExceeded,
52 => InstructionError::MaxInstructionTraceLengthExceeded,
53 => InstructionError::BuiltinProgramsMustConsumeUnits,
53 => InstructionError::BuiltinProgramsMustConsumeComputeUnits,
_ => return Err("Invalid InstructionError"),
};

Expand Down Expand Up @@ -1076,8 +1076,8 @@ impl From<TransactionError> for tx_by_addr::TransactionError {
InstructionError::MaxInstructionTraceLengthExceeded => {
tx_by_addr::InstructionErrorType::MaxInstructionTraceLengthExceeded
}
InstructionError::BuiltinProgramsMustConsumeUnits => {
tx_by_addr::InstructionErrorType::BuiltinProgramsMustConsumeUnits
InstructionError::BuiltinProgramsMustConsumeComputeUnits => {
tx_by_addr::InstructionErrorType::BuiltinProgramsMustConsumeComputeUnits
}
} as i32,
custom: match instruction_error {
Expand Down

0 comments on commit de8a840

Please sign in to comment.