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 compute units for builtins #3799

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
5 changes: 5 additions & 0 deletions builtins-default-costs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ pub fn get_builtin_instruction_cost<'a>(
.map(|builtin_cost| builtin_cost.native_cost)
}

#[inline]
pub fn is_builtin_program(program_id: &Pubkey) -> bool {
BUILTIN_INSTRUCTION_COSTS.contains_key(program_id)
}

#[cfg(test)]
mod test {
use super::*;
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
3 changes: 2 additions & 1 deletion core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ impl Consumer {
.filter_map(|transaction| {
transaction
.compute_budget_instruction_details()
.sanitize_and_convert_to_compute_budget_limits()
.sanitize_and_convert_to_compute_budget_limits(&bank.feature_set)
.ok()
.map(|limits| limits.compute_unit_price)
})
Expand Down Expand Up @@ -760,6 +760,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,
Comment on lines 761 to +763
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split out #3922 - we can use cached value here.

Will wait on merge/review of that until this PR is merged.

)?);
let fee = solana_fee::calculate_fee(
message,
Expand Down
8 changes: 8 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::FeatureSet,
hash::Hash,
message::{v0::LoadedAddresses, AddressLoaderError, Message, SimpleAddressLoader},
pubkey::Pubkey,
Expand Down Expand Up @@ -45,6 +46,12 @@ pub enum DeserializedPacketError {
FailedFilter(#[from] PacketFilterFailure),
}

lazy_static::lazy_static! {
// Make a dummy feature_set with all features enabled to
// fetch compute_unit_price and compute_unit_limit for legacy leader.
static ref FEATURE_SET: FeatureSet = FeatureSet::all_enabled();
}

#[derive(Debug)]
pub struct ImmutableDeserializedPacket {
original_packet: Packet,
Expand Down Expand Up @@ -73,6 +80,7 @@ impl ImmutableDeserializedPacket {
.get_message()
.program_instructions_iter()
.map(|(pubkey, ix)| (pubkey, SVMInstruction::from(ix))),
&FEATURE_SET,
)
.map_err(|_| DeserializedPacketError::PrioritizationFailure)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl SanitizedTransactionReceiveAndBuffer {
})
.filter_map(|(packet, tx, deactivation_slot)| {
tx.compute_budget_instruction_details()
.sanitize_and_convert_to_compute_budget_limits()
.sanitize_and_convert_to_compute_budget_limits(&working_bank.feature_set)
.map(|compute_budget| {
(packet, tx, deactivation_slot, compute_budget.into())
})
Expand Down
Loading
Loading