Revert "cleanup feature: default units per instruction (#26684)" (#26750)

This reverts commit 39a34db52a.
This commit is contained in:
Jeff Washington (jwash) 2022-07-23 11:03:46 -05:00 committed by GitHub
parent 4308db74e4
commit d9c7bc7e78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 8 deletions

View File

@ -23,6 +23,7 @@ pub trait GetTransactionPriorityDetails {
let prioritization_fee_details = compute_budget
.process_instructions(
instructions,
true, // use default units per instruction
true, // don't reject txs that use set compute unit price ix
)
.ok()?;

View File

@ -126,6 +126,7 @@ impl ComputeBudget {
pub fn process_instructions<'a>(
&mut self,
instructions: impl Iterator<Item = (&'a Pubkey, &'a CompiledInstruction)>,
default_units_per_instruction: bool,
support_set_compute_unit_price_ix: bool,
) -> Result<PrioritizationFeeDetails, TransactionError> {
let mut num_non_compute_budget_instructions: usize = 0;
@ -220,15 +221,18 @@ impl ComputeBudget {
self.heap_size = Some(bytes as usize);
}
self.compute_unit_limit = updated_compute_unit_limit
.or_else(|| {
self.compute_unit_limit = if default_units_per_instruction {
updated_compute_unit_limit.or_else(|| {
Some(
(num_non_compute_budget_instructions as u32)
.saturating_mul(DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT),
)
})
.unwrap_or(MAX_COMPUTE_UNIT_LIMIT)
.min(MAX_COMPUTE_UNIT_LIMIT) as u64;
} else {
updated_compute_unit_limit
}
.unwrap_or(MAX_COMPUTE_UNIT_LIMIT)
.min(MAX_COMPUTE_UNIT_LIMIT) as u64;
Ok(prioritization_fee
.map(|fee_type| PrioritizationFeeDetails::new(fee_type, self.compute_unit_limit))
@ -271,8 +275,11 @@ mod tests {
Hash::default(),
));
let mut compute_budget = ComputeBudget::default();
let result = compute_budget
.process_instructions(tx.message().program_instructions_iter(), $type_change);
let result = compute_budget.process_instructions(
tx.message().program_instructions_iter(),
true,
$type_change,
);
assert_eq!($expected_result, result);
assert_eq!(compute_budget, $expected_budget);
};

View File

@ -108,8 +108,8 @@ use {
epoch_schedule::EpochSchedule,
feature,
feature_set::{
self, add_set_compute_unit_price_ix, disable_fee_calculator,
enable_early_verification_of_account_modifications, FeatureSet,
self, add_set_compute_unit_price_ix, default_units_per_instruction,
disable_fee_calculator, enable_early_verification_of_account_modifications, FeatureSet,
},
fee::FeeStructure,
fee_calculator::{FeeCalculator, FeeRateGovernor},
@ -4542,6 +4542,7 @@ impl Bank {
Measure::start("compute_budget_process_transaction_time");
let process_transaction_result = compute_budget.process_instructions(
tx.message().program_instructions_iter(),
feature_set.is_active(&default_units_per_instruction::id()),
feature_set.is_active(&add_set_compute_unit_price_ix::id()),
);
compute_budget_process_transaction_time.stop();
@ -4836,6 +4837,7 @@ impl Bank {
let prioritization_fee_details = compute_budget
.process_instructions(
message.program_instructions_iter(),
false,
support_set_compute_unit_price_ix,
)
.unwrap_or_default();