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

clean up cost_model_requested_write_lock_cost #4353

Merged
Merged
Show file tree
Hide file tree
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
18 changes: 0 additions & 18 deletions cost-model/benches/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,3 @@ fn bench_cost_model(bencher: &mut Bencher) {
}
});
}

#[bench]
fn bench_cost_model_requested_write_locks(bencher: &mut Bencher) {
let BenchSetup {
transactions,
mut feature_set,
} = setup(NUM_TRANSACTIONS_PER_ITER);
feature_set.activate(
&solana_feature_set::cost_model_requested_write_lock_cost::id(),
0,
);

bencher.iter(|| {
for transaction in &transactions {
let _ = CostModel::calculate_cost(test::black_box(transaction), &feature_set);
}
});
}
46 changes: 9 additions & 37 deletions cost-model/src/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use {
transaction_meta::StaticMeta, transaction_with_meta::TransactionWithMeta,
},
solana_sdk_ids::{compute_budget, system_program},
solana_svm_transaction::{instruction::SVMInstruction, svm_message::SVMMessage},
solana_svm_transaction::instruction::SVMInstruction,
solana_system_interface::{
instruction::SystemInstruction, MAX_PERMITTED_ACCOUNTS_DATA_ALLOCATIONS_PER_TRANSACTION,
MAX_PERMITTED_DATA_LENGTH,
Expand All @@ -46,7 +46,6 @@ impl CostModel {
if transaction.is_simple_vote_transaction() {
TransactionCost::SimpleVote { transaction }
} else {
let num_write_locks = Self::num_write_locks(transaction, feature_set);
let (programs_execution_cost, loaded_accounts_data_size_cost, data_bytes_cost) =
Self::get_transaction_cost(
transaction,
Expand All @@ -56,7 +55,7 @@ impl CostModel {
Self::calculate_non_vote_transaction_cost(
transaction,
transaction.program_instructions_iter(),
num_write_locks,
transaction.num_write_locks(),
programs_execution_cost,
loaded_accounts_data_size_cost,
data_bytes_cost,
Expand All @@ -76,7 +75,6 @@ impl CostModel {
if transaction.is_simple_vote_transaction() {
TransactionCost::SimpleVote { transaction }
} else {
let num_write_locks = Self::num_write_locks(transaction, feature_set);
let loaded_accounts_data_size_cost = Self::calculate_loaded_accounts_data_size_cost(
actual_loaded_accounts_data_size_bytes,
feature_set,
Expand All @@ -87,7 +85,7 @@ impl CostModel {
Self::calculate_non_vote_transaction_cost(
transaction,
transaction.program_instructions_iter(),
num_write_locks,
transaction.num_write_locks(),
actual_programs_execution_cost,
loaded_accounts_data_size_cost,
instructions_data_cost,
Expand Down Expand Up @@ -188,23 +186,6 @@ impl CostModel {
)
}

fn get_writable_accounts(message: &impl SVMMessage) -> impl Iterator<Item = &Pubkey> {
message
.account_keys()
.iter()
.enumerate()
.filter_map(|(i, k)| message.is_writable(i).then_some(k))
}

/// Return the number of write-locks for a transaction.
fn num_write_locks(transaction: &impl SVMMessage, feature_set: &FeatureSet) -> u64 {
if feature_set.is_active(&feature_set::cost_model_requested_write_lock_cost::id()) {
transaction.num_write_locks()
} else {
Self::get_writable_accounts(transaction).count() as u64
}
}

/// Returns the total write-lock cost.
fn get_write_lock_cost(num_write_locks: u64) -> u64 {
WRITE_LOCK_UNITS.saturating_mul(num_write_locks)
Expand Down Expand Up @@ -423,10 +404,10 @@ mod tests {
super::*,
itertools::Itertools,
solana_compute_budget::{
self,
compute_budget_limits::{
DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT, MAX_BUILTIN_ALLOCATION_COMPUTE_UNIT_LIMIT,
},
{self},
},
solana_compute_budget_interface::ComputeBudgetInstruction,
solana_fee_structure::ACCOUNT_DATA_COST_PAGE_SIZE,
Expand All @@ -437,6 +418,7 @@ mod tests {
solana_runtime_transaction::runtime_transaction::RuntimeTransaction,
solana_sdk_ids::system_program,
solana_signer::Signer,
solana_svm_transaction::svm_message::SVMMessage,
solana_system_interface::instruction::{self as system_instruction},
solana_system_transaction as system_transaction,
solana_transaction::Transaction,
Expand Down Expand Up @@ -704,20 +686,10 @@ mod tests {
system_transaction::transfer(&mint_keypair, &system_program::id(), 2, start_hash),
);

// Feature not enabled - write lock is demoted and does not count towards cost
{
let tx_cost = CostModel::calculate_cost(&simple_transaction, &FeatureSet::default());
assert_eq!(WRITE_LOCK_UNITS, tx_cost.write_lock_cost());
assert_eq!(1, tx_cost.writable_accounts().count());
}

// Feature enabled - write lock is demoted but still counts towards cost
{
let tx_cost =
CostModel::calculate_cost(&simple_transaction, &FeatureSet::all_enabled());
assert_eq!(2 * WRITE_LOCK_UNITS, tx_cost.write_lock_cost());
assert_eq!(1, tx_cost.writable_accounts().count());
}
// write-lock counts towards cost, even if it is demoted.
let tx_cost = CostModel::calculate_cost(&simple_transaction, &FeatureSet::default());
assert_eq!(2 * WRITE_LOCK_UNITS, tx_cost.write_lock_cost());
assert_eq!(1, tx_cost.writable_accounts().count());
}

#[test]
Expand Down
Loading