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

remove solana-sdk from cost-model #4176

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 18 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 31 additions & 6 deletions cost-model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,32 @@ edition = { workspace = true }
ahash = { workspace = true }
lazy_static = { workspace = true }
log = { workspace = true }
solana-bincode = { workspace = true }
solana-borsh = { workspace = true }
solana-builtins-default-costs = { workspace = true }
solana-compute-budget = { workspace = true }
solana-compute-budget-instruction = { workspace = true }
solana-compute-budget-interface = { workspace = true }
solana-feature-set = { workspace = true }
solana-fee-structure = { workspace = true }
solana-frozen-abi = { workspace = true, optional = true, features = [
"frozen-abi",
] }
solana-frozen-abi-macro = { workspace = true, optional = true, features = [
"frozen-abi",
] }
solana-hash = { workspace = true, optional = true }
solana-message = { workspace = true, optional = true }
solana-metrics = { workspace = true }
solana-packet = { workspace = true }
solana-pubkey = { workspace = true }
solana-runtime-transaction = { workspace = true }
solana-sdk = { workspace = true }
solana-sdk-ids = { workspace = true }
solana-signature = { workspace = true, optional = true }
solana-svm-transaction = { workspace = true }
solana-system-interface = { workspace = true }
solana-transaction = { workspace = true, optional = true }
solana-transaction-error = { workspace = true }
solana-vote-program = { workspace = true }

[lib]
Expand All @@ -37,29 +49,42 @@ name = "solana_cost_model"
itertools = { workspace = true }
rand = "0.8.5"
# See order-crates-for-publishing.py for using this unusual `path = "."`
solana-compute-budget-instruction = { workspace = true, features = ["dev-context-only-utils"] }
solana-compute-budget-instruction = { workspace = true, features = [
"dev-context-only-utils",
] }
solana-compute-budget-interface = { workspace = true }
solana-compute-budget-program = { workspace = true }
solana-cost-model = { path = ".", features = ["dev-context-only-utils"] }
solana-instruction = { workspace = true }
solana-keypair = { workspace = true }
solana-logger = { workspace = true }
solana-reserved-account-keys = { workspace = true }
solana-runtime-transaction = { workspace = true, features = [
"dev-context-only-utils",
] }
solana-sdk = { workspace = true, features = ["dev-context-only-utils"] }
solana-signer = { workspace = true }
solana-system-program = { workspace = true }
solana-system-transaction = { workspace = true }
static_assertions = { workspace = true }
test-case = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[features]
dev-context-only-utils = []
dev-context-only-utils = [
"dep:solana-hash",
"dep:solana-message",
"dep:solana-signature",
"dep:solana-transaction",
"solana-compute-budget-interface/dev-context-only-utils"
]
frozen-abi = [
"dep:solana-frozen-abi",
"dep:solana-frozen-abi-macro",
"solana-compute-budget/frozen-abi",
"solana-sdk/frozen-abi",
"solana-vote-program/frozen-abi",
"solana-pubkey/frozen-abi",
"solana-vote-program/frozen-abi"
]

[[bench]]
Expand Down
20 changes: 9 additions & 11 deletions cost-model/benches/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
extern crate test;
use {
solana_cost_model::cost_model::CostModel,
solana_feature_set::FeatureSet,
solana_hash::Hash,
solana_keypair::Keypair,
solana_message::Message,
solana_pubkey::Pubkey,
solana_runtime_transaction::runtime_transaction::RuntimeTransaction,
solana_sdk::{
feature_set::FeatureSet,
hash::Hash,
message::Message,
pubkey::Pubkey,
signature::Keypair,
signer::Signer,
system_instruction,
transaction::{SanitizedTransaction, Transaction},
},
solana_signer::Signer,
solana_system_interface::instruction as system_instruction,
solana_transaction::{sanitized::SanitizedTransaction, Transaction},
test::Bencher,
};

Expand Down Expand Up @@ -66,7 +64,7 @@ fn bench_cost_model_requested_write_locks(bencher: &mut Bencher) {
mut feature_set,
} = setup(NUM_TRANSACTIONS_PER_ITER);
feature_set.activate(
&solana_sdk::feature_set::cost_model_requested_write_lock_cost::id(),
&solana_feature_set::cost_model_requested_write_lock_cost::id(),
0,
);

Expand Down
2 changes: 1 addition & 1 deletion cost-model/benches/cost_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
cost_tracker::CostTracker,
transaction_cost::{TransactionCost, UsageCostDetails, WritableKeysTransaction},
},
solana_sdk::pubkey::Pubkey,
solana_pubkey::Pubkey,
test::Bencher,
};

Expand Down
93 changes: 42 additions & 51 deletions cost-model/src/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,26 @@

use {
crate::{block_cost_limits::*, transaction_cost::*},
solana_bincode::limited_deserialize,
solana_borsh::v1::try_from_slice_unchecked,
solana_builtins_default_costs::get_builtin_instruction_cost,
solana_compute_budget::compute_budget_limits::{
DEFAULT_HEAP_COST, DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT, MAX_COMPUTE_UNIT_LIMIT,
},
solana_compute_budget_interface::ComputeBudgetInstruction,
solana_feature_set::{self as feature_set, FeatureSet},
solana_fee_structure::FeeStructure,
solana_pubkey::Pubkey,
solana_runtime_transaction::{
transaction_meta::StaticMeta, transaction_with_meta::TransactionWithMeta,
},
solana_sdk::{
borsh1::try_from_slice_unchecked,
compute_budget::{self, ComputeBudgetInstruction},
fee::FeeStructure,
program_utils::limited_deserialize,
pubkey::Pubkey,
saturating_add_assign,
system_instruction::{
SystemInstruction, MAX_PERMITTED_ACCOUNTS_DATA_ALLOCATIONS_PER_TRANSACTION,
MAX_PERMITTED_DATA_LENGTH,
},
system_program,
},
solana_sdk_ids::{compute_budget, system_program},
solana_svm_transaction::{instruction::SVMInstruction, svm_message::SVMMessage},
solana_system_interface::{
instruction::SystemInstruction, MAX_PERMITTED_ACCOUNTS_DATA_ALLOCATIONS_PER_TRANSACTION,
MAX_PERMITTED_DATA_LENGTH,
},
std::num::Saturating,
};

pub struct CostModel;
Expand Down Expand Up @@ -359,7 +357,9 @@ impl CostModel {
instruction: SVMInstruction,
) -> SystemProgramAccountAllocation {
if program_id == &system_program::id() {
if let Ok(instruction) = limited_deserialize(instruction.data) {
if let Ok(instruction) =
limited_deserialize(instruction.data, solana_packet::PACKET_DATA_SIZE as u64)
{
Self::calculate_account_data_size_on_deserialized_system_instruction(instruction)
} else {
SystemProgramAccountAllocation::Failed
Expand All @@ -374,7 +374,7 @@ impl CostModel {
fn calculate_allocated_accounts_data_size<'a>(
instructions: impl Iterator<Item = (&'a Pubkey, SVMInstruction<'a>)>,
) -> u64 {
let mut tx_attempted_allocation_size: u64 = 0;
let mut tx_attempted_allocation_size = Saturating(0u64);
for (program_id, instruction) in instructions {
match Self::calculate_account_data_size_on_instruction(program_id, instruction) {
SystemProgramAccountAllocation::Failed => {
Expand All @@ -387,10 +387,7 @@ impl CostModel {
}
SystemProgramAccountAllocation::None => continue,
SystemProgramAccountAllocation::Some(ix_attempted_allocation_size) => {
saturating_add_assign!(
tx_attempted_allocation_size,
ix_attempted_allocation_size
);
tx_attempted_allocation_size += ix_attempted_allocation_size;
}
}
}
Expand All @@ -404,7 +401,7 @@ impl CostModel {
// shouldn't assume that a large sum of allocations will necessarily
// lead to transaction failure.
(MAX_PERMITTED_ACCOUNTS_DATA_ALLOCATIONS_PER_TRANSACTION as u64)
.min(tx_attempted_allocation_size)
.min(tx_attempted_allocation_size.0)
}
}

Expand All @@ -413,21 +410,24 @@ mod tests {
use {
super::*,
itertools::Itertools,
solana_compute_budget::compute_budget_limits::{
DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT, MAX_BUILTIN_ALLOCATION_COMPUTE_UNIT_LIMIT,
solana_compute_budget::{
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,
solana_hash::Hash,
solana_instruction::Instruction,
solana_keypair::Keypair,
solana_message::{compiled_instruction::CompiledInstruction, Message},
solana_runtime_transaction::runtime_transaction::RuntimeTransaction,
solana_sdk::{
compute_budget::{self, ComputeBudgetInstruction},
fee::ACCOUNT_DATA_COST_PAGE_SIZE,
hash::Hash,
instruction::{CompiledInstruction, Instruction},
message::Message,
signature::{Keypair, Signer},
system_instruction::{self},
system_program, system_transaction,
transaction::Transaction,
},
solana_sdk_ids::system_program,
solana_signer::Signer,
solana_system_interface::instruction::{self as system_instruction},
solana_system_transaction as system_transaction,
solana_transaction::Transaction,
};

fn test_setup() -> (Keypair, Hash) {
Expand Down Expand Up @@ -653,10 +653,7 @@ mod tests {
let instructions = vec![CompiledInstruction::new(3, &(), vec![1, 2, 0])];
let tx = Transaction::new_with_compiled_instructions(
&[&mint_keypair],
&[
solana_sdk::pubkey::new_rand(),
solana_sdk::pubkey::new_rand(),
],
&[solana_pubkey::new_rand(), solana_pubkey::new_rand()],
start_hash,
vec![Pubkey::new_unique()],
instructions,
Expand Down Expand Up @@ -728,10 +725,7 @@ mod tests {
];
let tx = Transaction::new_with_compiled_instructions(
&[&mint_keypair],
&[
solana_sdk::pubkey::new_rand(),
solana_sdk::pubkey::new_rand(),
],
&[solana_pubkey::new_rand(), solana_pubkey::new_rand()],
start_hash,
vec![Pubkey::new_unique(), compute_budget::id()],
instructions,
Expand Down Expand Up @@ -779,10 +773,7 @@ mod tests {
];
let tx = Transaction::new_with_compiled_instructions(
&[&mint_keypair],
&[
solana_sdk::pubkey::new_rand(),
solana_sdk::pubkey::new_rand(),
],
&[solana_pubkey::new_rand(), solana_pubkey::new_rand()],
start_hash,
vec![Pubkey::new_unique(), compute_budget::id()],
instructions,
Expand All @@ -804,8 +795,8 @@ mod tests {
fn test_cost_model_transaction_many_transfer_instructions() {
let (mint_keypair, start_hash) = test_setup();

let key1 = solana_sdk::pubkey::new_rand();
let key2 = solana_sdk::pubkey::new_rand();
let key1 = solana_pubkey::new_rand();
let key2 = solana_pubkey::new_rand();
let instructions =
system_instruction::transfer_many(&mint_keypair.pubkey(), &[(key1, 1), (key2, 1)]);
let message = Message::new(&instructions, Some(&mint_keypair.pubkey()));
Expand Down Expand Up @@ -838,10 +829,10 @@ mod tests {
let (mint_keypair, start_hash) = test_setup();

// construct a transaction with multiple random instructions
let key1 = solana_sdk::pubkey::new_rand();
let key2 = solana_sdk::pubkey::new_rand();
let prog1 = solana_sdk::pubkey::new_rand();
let prog2 = solana_sdk::pubkey::new_rand();
let key1 = solana_pubkey::new_rand();
let key2 = solana_pubkey::new_rand();
let prog1 = solana_pubkey::new_rand();
let prog2 = solana_pubkey::new_rand();
let instructions = vec![
CompiledInstruction::new(3, &(), vec![0, 1]),
CompiledInstruction::new(4, &(), vec![0, 2]),
Expand Down
Loading
Loading