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

Refactor ComputeBudget and ComputeBudgetLimits #5127

Open
wants to merge 1 commit 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
12 changes: 7 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion cli/src/compute_budget.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use {
solana_borsh::v1::try_from_slice_unchecked,
solana_clap_utils::compute_budget::ComputeUnitLimit,
solana_compute_budget::compute_budget_limits::MAX_COMPUTE_UNIT_LIMIT,
solana_compute_budget_interface::{self as compute_budget, ComputeBudgetInstruction},
solana_instruction::Instruction,
solana_message::Message,
solana_program_runtime::execution_budget::MAX_COMPUTE_UNIT_LIMIT,
solana_rpc_client::rpc_client::RpcClient,
solana_rpc_client_api::config::RpcSimulateTransactionConfig,
solana_transaction::Transaction,
Expand Down
2 changes: 2 additions & 0 deletions compute-budget-instruction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ solana-compute-budget-interface = { workspace = true, features = ["borsh"] }
solana-feature-set = { workspace = true }
solana-instruction = { workspace = true }
solana-packet = { workspace = true }
solana-program-runtime = { workspace = true }
solana-pubkey = { workspace = true }
solana-sdk-ids = { workspace = true }
solana-svm-transaction = { workspace = true }
Expand All @@ -33,6 +34,7 @@ bincode = { workspace = true }
criterion = { workspace = true }
rand = { workspace = true }
solana-builtins-default-costs = { workspace = true, features = ["dev-context-only-utils", "svm-internal"] }
solana-compute-budget-program = { workspace = true }
solana-hash = { workspace = true }
solana-keypair = { workspace = true }
solana-message = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use {
solana_compute_budget_interface::ComputeBudgetInstruction,
solana_feature_set::{self as feature_set, FeatureSet},
solana_instruction::error::InstructionError,
solana_program_runtime::execution_budget::{
DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT, MAX_BUILTIN_ALLOCATION_COMPUTE_UNIT_LIMIT,
MAX_COMPUTE_UNIT_LIMIT, MAX_HEAP_FRAME_BYTES, MIN_HEAP_FRAME_BYTES,
},
solana_pubkey::Pubkey,
solana_svm_transaction::instruction::SVMInstruction,
solana_transaction_error::{TransactionError, TransactionResult as Result},
Expand Down Expand Up @@ -232,6 +236,10 @@ mod test {
solana_instruction::Instruction,
solana_keypair::Keypair,
solana_message::Message,
solana_program_runtime::execution_budget::{
DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT, MAX_BUILTIN_ALLOCATION_COMPUTE_UNIT_LIMIT,
MAX_COMPUTE_UNIT_LIMIT, MAX_HEAP_FRAME_BYTES, MIN_HEAP_FRAME_BYTES,
},
solana_pubkey::Pubkey,
solana_signer::Signer,
solana_svm_transaction::svm_message::SVMMessage,
Expand Down
37 changes: 37 additions & 0 deletions compute-budget-instruction/src/instructions_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ pub fn process_compute_budget_instructions<'a>(
mod tests {
use {
super::*,
solana_compute_budget::compute_budget_limits::ComputeBudgetLimits,
solana_compute_budget_interface::ComputeBudgetInstruction,
solana_hash::Hash,
solana_instruction::{error::InstructionError, Instruction},
solana_keypair::Keypair,
solana_message::Message,
solana_program_runtime::execution_budget::{
DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT, MAX_BUILTIN_ALLOCATION_COMPUTE_UNIT_LIMIT,
MAX_COMPUTE_UNIT_LIMIT, MAX_HEAP_FRAME_BYTES, MIN_HEAP_FRAME_BYTES,
},
solana_pubkey::Pubkey,
solana_signer::Signer,
solana_svm_transaction::svm_message::SVMMessage,
Expand Down Expand Up @@ -78,6 +83,30 @@ mod tests {
..ComputeBudgetLimits::default()
})
);
test!(
&[
ComputeBudgetInstruction::set_compute_unit_limit(2000u32),
ComputeBudgetInstruction::set_compute_unit_price(1_000_000_000),
],
Ok(ComputeBudgetLimits {
compute_unit_limit: 2000u32,
compute_unit_price: 1_000_000_000u64,
..ComputeBudgetLimits::default()
})
);
test!(
&[
ComputeBudgetInstruction::set_compute_unit_limit(
2 * solana_compute_budget_program::DEFAULT_COMPUTE_UNITS as u32
),
ComputeBudgetInstruction::set_compute_unit_price(1_000_000),
],
Ok(ComputeBudgetLimits {
compute_unit_limit: 2 * solana_compute_budget_program::DEFAULT_COMPUTE_UNITS as u32,
compute_unit_price: 1_000_000u64,
..ComputeBudgetLimits::default()
})
);
test!(
&[
ComputeBudgetInstruction::set_compute_unit_limit(MAX_COMPUTE_UNIT_LIMIT + 1),
Expand Down Expand Up @@ -279,6 +308,14 @@ mod tests {
Err(TransactionError::DuplicateInstruction(2))
);

test!(
&[
ComputeBudgetInstruction::set_compute_unit_limit(2000u32),
ComputeBudgetInstruction::set_compute_unit_limit(42u32),
],
Err(TransactionError::DuplicateInstruction(1))
);

test!(
&[
Instruction::new_with_bincode(Pubkey::new_unique(), &0_u8, vec![]),
Expand Down
2 changes: 1 addition & 1 deletion compute-budget/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ solana-fee-structure = { workspace = true }
solana-frozen-abi = { workspace = true, optional = true, features = [
"frozen-abi",
] }
solana-program-entrypoint = { workspace = true }
solana-program-runtime = { workspace = true }

[features]
dev-context-only-utils = ["dep:qualifier_attr"]
Expand Down
Loading
Loading