Skip to content

Commit

Permalink
- Add feature gate, issue #2562;
Browse files Browse the repository at this point in the history
- Implement SIMD-170;
  • Loading branch information
tao-stones committed Dec 4, 2024
1 parent cfc53c7 commit 7251345
Show file tree
Hide file tree
Showing 27 changed files with 872 additions and 379 deletions.
4 changes: 4 additions & 0 deletions builtins-default-costs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ pub fn get_builtin_instruction_cost<'a>(
.map(|builtin_cost| builtin_cost.native_cost)
}

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,
)?);
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

0 comments on commit 7251345

Please sign in to comment.