Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

charging CU for loaded accounts data size #1356

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 3 additions & 41 deletions cost-model/src/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use {
solana_sdk::{
borsh1::try_from_slice_unchecked,
compute_budget::{self, ComputeBudgetInstruction},
feature_set::{self, include_loaded_accounts_data_size_in_fee_calculation, FeatureSet},
feature_set::{self, FeatureSet},
fee::FeeStructure,
instruction::CompiledInstruction,
program_utils::limited_deserialize,
Expand Down Expand Up @@ -170,13 +170,9 @@ impl CostModel {

pub fn calculate_loaded_accounts_data_size_cost(
loaded_accounts_data_size: usize,
feature_set: &FeatureSet,
_feature_set: &FeatureSet,
) -> u64 {
if feature_set.is_active(&include_loaded_accounts_data_size_in_fee_calculation::id()) {
FeeStructure::calculate_memory_usage_cost(loaded_accounts_data_size, DEFAULT_HEAP_COST)
} else {
0
}
FeeStructure::calculate_memory_usage_cost(loaded_accounts_data_size, DEFAULT_HEAP_COST)
}

fn calculate_account_data_size_on_deserialized_system_instruction(
Expand Down Expand Up @@ -571,8 +567,6 @@ mod tests {
let expected_execution_cost = BUILT_IN_INSTRUCTION_COSTS
.get(&system_program::id())
.unwrap();
// feature `include_loaded_accounts_data_size_in_fee_calculation` enabled, using
// default loaded_accounts_data_size_limit
const DEFAULT_PAGE_COST: u64 = 8;
let expected_loaded_accounts_data_size_cost =
solana_compute_budget::compute_budget_processor::MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES
Expand All @@ -590,35 +584,6 @@ mod tests {
);
}

#[test]
fn test_cost_model_calculate_cost_disabled_feature() {
let (mint_keypair, start_hash) = test_setup();
let tx = SanitizedTransaction::from_transaction_for_tests(system_transaction::transfer(
&mint_keypair,
&Keypair::new().pubkey(),
2,
start_hash,
));

let feature_set = FeatureSet::default();
assert!(!feature_set.is_active(&include_loaded_accounts_data_size_in_fee_calculation::id()));
let expected_account_cost = WRITE_LOCK_UNITS * 2;
let expected_execution_cost = BUILT_IN_INSTRUCTION_COSTS
.get(&system_program::id())
.unwrap();
// feature `include_loaded_accounts_data_size_in_fee_calculation` not enabled
let expected_loaded_accounts_data_size_cost = 0;

let tx_cost = CostModel::calculate_cost(&tx, &feature_set);
assert_eq!(expected_account_cost, tx_cost.write_lock_cost());
assert_eq!(*expected_execution_cost, tx_cost.programs_execution_cost());
assert_eq!(2, tx_cost.writable_accounts().len());
assert_eq!(
expected_loaded_accounts_data_size_cost,
tx_cost.loaded_accounts_data_size_cost()
);
}

#[test]
fn test_cost_model_calculate_cost_with_limit() {
let (mint_keypair, start_hash) = test_setup();
Expand All @@ -636,16 +601,13 @@ mod tests {
));

let feature_set = FeatureSet::all_enabled();
assert!(feature_set.is_active(&include_loaded_accounts_data_size_in_fee_calculation::id()));
let expected_account_cost = WRITE_LOCK_UNITS * 2;
let expected_execution_cost = BUILT_IN_INSTRUCTION_COSTS
.get(&system_program::id())
.unwrap()
+ BUILT_IN_INSTRUCTION_COSTS
.get(&compute_budget::id())
.unwrap();
// feature `include_loaded_accounts_data_size_in_fee_calculation` is enabled, accounts data
// size limit is set.
let expected_loaded_accounts_data_size_cost = (data_limit as u64) / (32 * 1024) * 8;

let tx_cost = CostModel::calculate_cost(&tx, &feature_set);
Expand Down