From 5de4cd28bcaa2e0a69a4d986598d1345c461b81e Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 20 Jul 2023 16:52:26 -0500 Subject: [PATCH] v1.16: Remove inappropriate use of usize. Refactor upcast. (backport of #32539) (#32561) Remove inappropriate use of usize. Refactor upcast. (#32539) * Remove inappropriate use of usize. Refactor upcast. Co-authored-by: Trent Nelson (cherry picked from commit 83ac15dd976282fc559c218d77a1c3b79c23d001) Co-authored-by: Will Hickey --- program-runtime/src/compute_budget.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/program-runtime/src/compute_budget.rs b/program-runtime/src/compute_budget.rs index 77a37c9f86a05b..f8a864a44e03da 100644 --- a/program-runtime/src/compute_budget.rs +++ b/program-runtime/src/compute_budget.rs @@ -176,7 +176,7 @@ impl ComputeBudget { enable_request_heap_frame_ix: bool, support_set_loaded_accounts_data_size_limit_ix: bool, ) -> Result { - let mut num_non_compute_budget_instructions: usize = 0; + let mut num_non_compute_budget_instructions: u32 = 0; let mut updated_compute_unit_limit = None; let mut requested_heap_size = None; let mut prioritization_fee = None; @@ -255,10 +255,10 @@ impl ComputeBudget { self.heap_size = Some(bytes as usize); } - self.compute_unit_limit = if default_units_per_instruction { + let compute_unit_limit = if default_units_per_instruction { updated_compute_unit_limit.or_else(|| { Some( - (num_non_compute_budget_instructions as u32) + num_non_compute_budget_instructions .saturating_mul(DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT), ) }) @@ -266,7 +266,8 @@ impl ComputeBudget { updated_compute_unit_limit } .unwrap_or(MAX_COMPUTE_UNIT_LIMIT) - .min(MAX_COMPUTE_UNIT_LIMIT) as u64; + .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 .unwrap_or(MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES)