Skip to content

Commit

Permalink
cleanup feature: Use default units per instruction in fee calculation (
Browse files Browse the repository at this point in the history
…#32570)

* cleanup feature: Use default units per instruction in fee calculation
  • Loading branch information
tao-stones authored Jul 21, 2023
1 parent fad52df commit 62b9fcf
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 20 deletions.
1 change: 0 additions & 1 deletion cost-model/src/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ impl CostModel {
let enable_request_heap_frame_ix = true;
let result = compute_budget.process_instructions(
transaction.message().program_instructions_iter(),
true, // default_units_per_instruction has enabled in MNB
!feature_set.is_active(&remove_deprecated_request_unit_ix::id()),
enable_request_heap_frame_ix,
feature_set.is_active(&add_set_tx_loaded_accounts_data_size_instruction::id()),
Expand Down
22 changes: 6 additions & 16 deletions program-runtime/src/compute_budget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
entrypoint::HEAP_LENGTH as MIN_HEAP_FRAME_BYTES,
feature_set::{
add_set_tx_loaded_accounts_data_size_instruction, enable_request_heap_frame_ix,
remove_deprecated_request_unit_ix, use_default_units_in_fee_calculation, FeatureSet,
remove_deprecated_request_unit_ix, FeatureSet,
},
fee::FeeBudgetLimits,
genesis_config::ClusterType,
Expand Down Expand Up @@ -177,7 +177,6 @@ impl ComputeBudget {
pub fn process_instructions<'a>(
&mut self,
instructions: impl Iterator<Item = (&'a Pubkey, &'a CompiledInstruction)>,
default_units_per_instruction: bool,
support_request_units_deprecated: bool,
enable_request_heap_frame_ix: bool,
support_set_loaded_accounts_data_size_limit_ix: bool,
Expand Down Expand Up @@ -261,18 +260,12 @@ impl ComputeBudget {
self.heap_size = Some(bytes as usize);
}

let compute_unit_limit = if default_units_per_instruction {
updated_compute_unit_limit.or_else(|| {
Some(
num_non_compute_budget_instructions
.saturating_mul(DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT),
)
let compute_unit_limit = updated_compute_unit_limit
.unwrap_or_else(|| {
num_non_compute_budget_instructions
.saturating_mul(DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT)
})
} else {
updated_compute_unit_limit
}
.unwrap_or(MAX_COMPUTE_UNIT_LIMIT)
.min(MAX_COMPUTE_UNIT_LIMIT);
.min(MAX_COMPUTE_UNIT_LIMIT);
self.compute_unit_limit = u64::from(compute_unit_limit);

self.loaded_accounts_data_size_limit = updated_loaded_accounts_data_size_limit
Expand Down Expand Up @@ -302,7 +295,6 @@ impl ComputeBudget {
let prioritization_fee_details = compute_budget
.process_instructions(
instructions,
feature_set.is_active(&use_default_units_in_fee_calculation::id()),
!feature_set.is_active(&remove_deprecated_request_unit_ix::id()),
enable_request_heap_frame_ix,
feature_set.is_active(&add_set_tx_loaded_accounts_data_size_instruction::id()),
Expand Down Expand Up @@ -345,7 +337,6 @@ mod tests {
let mut compute_budget = ComputeBudget::default();
let result = compute_budget.process_instructions(
tx.message().program_instructions_iter(),
true,
false, /*not support request_units_deprecated*/
$enable_request_heap_frame_ix,
$support_set_loaded_accounts_data_size_limit_ix,
Expand Down Expand Up @@ -895,7 +886,6 @@ mod tests {
let mut compute_budget = ComputeBudget::default();
let result = compute_budget.process_instructions(
transaction.message().program_instructions_iter(),
true,
false, //not support request_units_deprecated
true, //enable_request_heap_frame_ix,
true, //support_set_loaded_accounts_data_size_limit_ix,
Expand Down
1 change: 0 additions & 1 deletion runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ impl Accounts {
ComputeBudget::new(compute_budget::MAX_COMPUTE_UNIT_LIMIT as u64);
let _process_transaction_result = compute_budget.process_instructions(
tx.message().program_instructions_iter(),
true, // default_units_per_instruction has enabled in MNB
!feature_set.is_active(&remove_deprecated_request_unit_ix::id()),
true, // don't reject txs that use request heap size ix
feature_set.is_active(&add_set_tx_loaded_accounts_data_size_instruction::id()),
Expand Down
1 change: 0 additions & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5084,7 +5084,6 @@ impl Bank {
Measure::start("compute_budget_process_transaction_time");
let process_transaction_result = compute_budget.process_instructions(
tx.message().program_instructions_iter(),
true,
!self
.feature_set
.is_active(&remove_deprecated_request_unit_ix::id()),
Expand Down
1 change: 0 additions & 1 deletion runtime/src/transaction_priority_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub trait GetTransactionPriorityDetails {
let prioritization_fee_details = compute_budget
.process_instructions(
instructions,
true, // use default units per instruction
true, // supports prioritization by request_units_deprecated instruction
true, // enable request heap frame instruction
true, // enable support set accounts data size instruction
Expand Down

0 comments on commit 62b9fcf

Please sign in to comment.