From 6fabbd36a75ec2b7135d0119ba15e3194c271c87 Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Thu, 6 Jun 2024 13:19:52 -0500 Subject: [PATCH] drop `get_compute_meter` --- program-runtime/src/invoke_context.rs | 7 +---- programs/bpf_loader/src/syscalls/mod.rs | 37 ++++++------------------- 2 files changed, 10 insertions(+), 34 deletions(-) diff --git a/program-runtime/src/invoke_context.rs b/program-runtime/src/invoke_context.rs index 10b590c037edb3..28c4d82126b480 100644 --- a/program-runtime/src/invoke_context.rs +++ b/program-runtime/src/invoke_context.rs @@ -39,7 +39,7 @@ use { solana_vote::vote_account::VoteAccountsHashMap, std::{ alloc::Layout, - cell::{Ref, RefCell}, + cell::RefCell, fmt::{self, Debug}, rc::Rc, sync::{atomic::Ordering, Arc}, @@ -601,11 +601,6 @@ impl<'a> InvokeContext<'a> { &self.compute_budget } - /// Get this invocation's compute meter. - pub fn get_compute_meter(&self) -> Ref { - self.compute_meter.borrow() - } - /// Get the current feature set. pub fn get_feature_set(&self) -> &FeatureSet { &self.environment_config.feature_set diff --git a/programs/bpf_loader/src/syscalls/mod.rs b/programs/bpf_loader/src/syscalls/mod.rs index 3200f025867d03..d62decf68d4d09 100644 --- a/programs/bpf_loader/src/syscalls/mod.rs +++ b/programs/bpf_loader/src/syscalls/mod.rs @@ -4747,14 +4747,22 @@ mod tests { #[test] fn test_syscall_get_epoch_stake() { let config = Config::default(); - let compute_budget = ComputeBudget::default(); + let mut compute_budget = ComputeBudget::default(); let sysvar_cache = Arc::::default(); let expected_epoch_stake = 55_000_000_000u64; + // Compute units, as specified by SIMD-0133. + // cu = syscall_base_cost + // + floor(32/cpi_bytes_per_unit) + // + mem_op_base_cost let expected_cus = compute_budget.syscall_base_cost + (PUBKEY_BYTES as u64) / compute_budget.cpi_bytes_per_unit + compute_budget.mem_op_base_cost; + // Set the compute budget to the expected CUs to ensure the syscall + // doesn't exceed the expected usage. + compute_budget.compute_unit_limit = expected_cus; + let vote_address = Pubkey::new_unique(); let mut vote_accounts_map = HashMap::new(); vote_accounts_map.insert( @@ -4805,15 +4813,6 @@ mod tests { ); assert_access_violation!(result, vote_address_var, 32); - - // Compute units, as specified by SIMD-0133. - // cu = syscall_base_cost - // + floor(32/cpi_bytes_per_unit) - // + mem_op_base_cost - assert_eq!( - invoke_context.get_compute_meter().to_owned(), - compute_budget.compute_unit_limit - expected_cus - ); } invoke_context.mock_set_remaining(compute_budget.compute_unit_limit); @@ -4845,15 +4844,6 @@ mod tests { .unwrap(); assert_eq!(result, expected_epoch_stake); - - // Compute units, as specified by SIMD-0133. - // cu = syscall_base_cost - // + floor(32/cpi_bytes_per_unit) - // + mem_op_base_cost - assert_eq!( - invoke_context.get_compute_meter().to_owned(), - compute_budget.compute_unit_limit - expected_cus - ); } invoke_context.mock_set_remaining(compute_budget.compute_unit_limit); @@ -4886,15 +4876,6 @@ mod tests { .unwrap(); assert_eq!(result, 0); // `0` for active stake. - - // Compute units, as specified by SIMD-0133. - // cu = syscall_base_cost - // + floor(32/cpi_bytes_per_unit) - // + mem_op_base_cost - assert_eq!( - invoke_context.get_compute_meter().to_owned(), - compute_budget.compute_unit_limit - expected_cus - ); } }