Skip to content

Commit

Permalink
drop get_compute_meter
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Jun 6, 2024
1 parent 946bc79 commit 6fabbd3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 34 deletions.
7 changes: 1 addition & 6 deletions program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -601,11 +601,6 @@ impl<'a> InvokeContext<'a> {
&self.compute_budget
}

/// Get this invocation's compute meter.
pub fn get_compute_meter(&self) -> Ref<u64> {
self.compute_meter.borrow()
}

/// Get the current feature set.
pub fn get_feature_set(&self) -> &FeatureSet {
&self.environment_config.feature_set
Expand Down
37 changes: 9 additions & 28 deletions programs/bpf_loader/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<SysvarCache>::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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
);
}
}

Expand Down

0 comments on commit 6fabbd3

Please sign in to comment.