Skip to content

Commit

Permalink
remove unnecessary wrapper function
Browse files Browse the repository at this point in the history
  • Loading branch information
tao-stones committed Dec 12, 2023
1 parent 337c233 commit 8856289
Showing 1 changed file with 4 additions and 56 deletions.
60 changes: 4 additions & 56 deletions cost-model/src/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,6 @@ impl CostModel {
}
}

// Calculate cost of loaded accounts size in the same way heap cost is charged at
// rate of 8cu per 32K. Citing `program_runtime\src\compute_budget.rs`: "(cost of
// heap is about) 0.5us per 32k at 15 units/us rounded up"
//
// Before feature `support_set_loaded_accounts_data_size_limit_ix` is enabled, or
// if user doesn't use compute budget ix `set_loaded_accounts_data_size_limit_ix`
// to set limit, `compute_budget.loaded_accounts_data_size_limit` is set to default
// limit of 64MB; which will convert to (64M/32K)*8CU = 16_000 CUs
//
pub fn calculate_loaded_accounts_data_size_cost(
compute_budget_limits: &ComputeBudgetLimits,
) -> u64 {
FeeStructure::calculate_memory_usage_cost(
usize::try_from(compute_budget_limits.loaded_accounts_bytes).unwrap(),
DEFAULT_HEAP_COST,
)
}

fn get_signature_cost(transaction: &SanitizedTransaction) -> u64 {
transaction.signatures().len() as u64 * SIGNATURE_COST
}
Expand Down Expand Up @@ -150,8 +132,10 @@ impl CostModel {
if feature_set
.is_active(&include_loaded_accounts_data_size_in_fee_calculation::id())
{
loaded_accounts_data_size_cost =
Self::calculate_loaded_accounts_data_size_cost(&compute_budget_limits);
loaded_accounts_data_size_cost = FeeStructure::calculate_memory_usage_cost(
usize::try_from(compute_budget_limits.loaded_accounts_bytes).unwrap(),
DEFAULT_HEAP_COST,
)
}
}
Err(_) => {
Expand Down Expand Up @@ -659,42 +643,6 @@ mod tests {
);
}

#[allow(clippy::field_reassign_with_default)]
#[test]
fn test_calculate_loaded_accounts_data_size_cost() {
let mut compute_budget_limits = ComputeBudgetLimits::default();

// accounts data size are priced in block of 32K, ...

// ... requesting less than 32K should still be charged as one block
compute_budget_limits.loaded_accounts_bytes = 31 * 1024;
assert_eq!(
DEFAULT_HEAP_COST,
CostModel::calculate_loaded_accounts_data_size_cost(&compute_budget_limits)
);

// ... requesting exact 32K should be charged as one block
compute_budget_limits.loaded_accounts_bytes = 32 * 1024;
assert_eq!(
DEFAULT_HEAP_COST,
CostModel::calculate_loaded_accounts_data_size_cost(&compute_budget_limits)
);

// ... requesting slightly above 32K should be charged as 2 block
compute_budget_limits.loaded_accounts_bytes = 33 * 1024;
assert_eq!(
DEFAULT_HEAP_COST * 2,
CostModel::calculate_loaded_accounts_data_size_cost(&compute_budget_limits)
);

// ... requesting exact 64K should be charged as 2 block
compute_budget_limits.loaded_accounts_bytes = 64 * 1024;
assert_eq!(
DEFAULT_HEAP_COST * 2,
CostModel::calculate_loaded_accounts_data_size_cost(&compute_budget_limits)
);
}

#[test]
fn test_transaction_cost_with_mix_instruction_without_compute_budget() {
let (mint_keypair, start_hash) = test_setup();
Expand Down

0 comments on commit 8856289

Please sign in to comment.