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

Fix reserve minimal cus for builtins #3755

Closed
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions banks-server/src/banks_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ fn simulate_transaction(
Some(false), // is_simple_vote_tx
bank,
bank.get_reserved_account_keys(),
&bank.feature_set,
) {
Err(err) => {
return BanksTransactionResultWithSimulation {
Expand Down
3 changes: 3 additions & 0 deletions compute-budget/src/compute_budget_limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use {
/// default heap page cost = 0.5 * 15 ~= 8CU/page
pub const DEFAULT_HEAP_COST: u64 = 8;
pub const DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT: u32 = 200_000;
// SIMD-170 defines max CUs to be allocated for any builtin program instructions, that
// have not been migrated to sBPF programs.
pub const MAX_BUILTIN_ALLOCATION_COMPUTE_UNIT_LIMIT: u32 = 3_000;
pub const MAX_COMPUTE_UNIT_LIMIT: u32 = 1_400_000;
pub const MAX_HEAP_FRAME_BYTES: u32 = 256 * 1024;
pub const MIN_HEAP_FRAME_BYTES: u32 = HEAP_LENGTH as u32;
Expand Down
1 change: 1 addition & 0 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ impl Consumer {
let fee_payer = message.fee_payer();
let fee_budget_limits = FeeBudgetLimits::from(process_compute_budget_instructions(
message.program_instructions_iter(),
&bank.feature_set,
)?);
let fee = solana_fee::calculate_fee(
message,
Expand Down
12 changes: 12 additions & 0 deletions core/src/banking_stage/immutable_deserialized_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use {
solana_sanitize::SanitizeError,
solana_sdk::{
clock::Slot,
feature_set::{self, FeatureSet},
hash::Hash,
message::{v0::LoadedAddresses, AddressLoaderError, Message, SimpleAddressLoader},
pubkey::Pubkey,
Expand Down Expand Up @@ -63,6 +64,15 @@ impl ImmutableDeserializedPacket {
let message_hash = Message::hash_raw_message(message_bytes);
let is_simple_vote = packet.meta().is_simple_vote_tx();

// Make a dummy feature_set with `reserve_minimal_cus_for_builtin_instructions` enabled to
// fetch compute_unit_price and compute_unit_limit for legacy leader. It can be removed
// once this feature is activated everywhere.
let mut feature_set = FeatureSet::default();
feature_set.activate(
&feature_set::reserve_minimal_cus_for_builtin_instructions::id(),
0,
);

// drop transaction if prioritization fails.
let ComputeBudgetLimits {
mut compute_unit_price,
Expand All @@ -73,6 +83,7 @@ impl ImmutableDeserializedPacket {
.get_message()
.program_instructions_iter()
.map(|(pubkey, ix)| (pubkey, SVMInstruction::from(ix))),
&feature_set,
)
.map_err(|_| DeserializedPacketError::PrioritizationFailure)?;

Expand Down Expand Up @@ -136,6 +147,7 @@ impl ImmutableDeserializedPacket {
self.transaction.clone(),
MessageHash::Precomputed(self.message_hash),
Some(self.is_simple_vote),
&bank.feature_set,
)
.and_then(|tx| {
RuntimeTransaction::<SanitizedTransaction>::try_from(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,11 @@ mod tests {

let transfer = system_instruction::transfer(&from_keypair.pubkey(), to_pubkey, lamports);
let prioritization = ComputeBudgetInstruction::set_compute_unit_price(compute_unit_price);
let message = Message::new(&[transfer, prioritization], Some(&from_keypair.pubkey()));
let compute_unit_limit = ComputeBudgetInstruction::set_compute_unit_limit(50_000); // just enough for simple trannsfer
let message = Message::new(
&[transfer, prioritization, compute_unit_limit],
Some(&from_keypair.pubkey()),
);
Transaction::new(&vec![from_keypair], message, recent_blockhash)
}

Expand Down Expand Up @@ -844,7 +848,7 @@ mod tests {
&Keypair::new(),
&Pubkey::new_unique(),
1,
i * 10,
i * 10_000,
bank.last_blockhash(),
)
})
Expand Down
Loading
Loading