Skip to content

Commit 6ea38fc

Browse files
v2.1: Fix reserve minimal compute units for builtins (backport of #3799) (#3931)
* Fix reserve minimal compute units for builtins (#3799) - Add feature gate, issue #2562; - Implement SIMD-170; --------- Co-authored-by: Justin Starry <[email protected]> (cherry picked from commit 3e9af14) * Fix conflicts manually * avoid getting program_ids that are not used after all --------- Co-authored-by: Tao Zhu <[email protected]> Co-authored-by: Tao Zhu <[email protected]>
1 parent df063a8 commit 6ea38fc

File tree

29 files changed

+831
-375
lines changed

29 files changed

+831
-375
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builtins-default-costs/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,8 @@ lazy_static! {
5454
temp_table
5555
};
5656
}
57+
58+
#[inline]
59+
pub fn is_builtin_program(program_id: &Pubkey) -> bool {
60+
BUILTIN_INSTRUCTION_COSTS.contains_key(program_id)
61+
}

compute-budget/src/compute_budget_limits.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use {
88
/// default heap page cost = 0.5 * 15 ~= 8CU/page
99
pub const DEFAULT_HEAP_COST: u64 = 8;
1010
pub const DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT: u32 = 200_000;
11+
// SIMD-170 defines max CUs to be allocated for any builtin program instructions, that
12+
// have not been migrated to sBPF programs.
13+
pub const MAX_BUILTIN_ALLOCATION_COMPUTE_UNIT_LIMIT: u32 = 3_000;
1114
pub const MAX_COMPUTE_UNIT_LIMIT: u32 = 1_400_000;
1215
pub const MAX_HEAP_FRAME_BYTES: u32 = 256 * 1024;
1316
pub const MIN_HEAP_FRAME_BYTES: u32 = HEAP_LENGTH as u32;

core/src/banking_stage/consumer.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,10 @@ impl Consumer {
574574
.sanitized_transactions()
575575
.iter()
576576
.filter_map(|transaction| {
577-
process_compute_budget_instructions(SVMMessage::program_instructions_iter(
578-
transaction,
579-
))
577+
process_compute_budget_instructions(
578+
SVMMessage::program_instructions_iter(transaction),
579+
&bank.feature_set,
580+
)
580581
.ok()
581582
.map(|limits| limits.compute_unit_price)
582583
})
@@ -758,6 +759,7 @@ impl Consumer {
758759
let fee_payer = message.fee_payer();
759760
let fee_budget_limits = FeeBudgetLimits::from(process_compute_budget_instructions(
760761
SVMMessage::program_instructions_iter(message),
762+
&bank.feature_set,
761763
)?);
762764
let fee = solana_fee::calculate_fee(
763765
message,

core/src/banking_stage/immutable_deserialized_packet.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use {
77
solana_sanitize::SanitizeError,
88
solana_sdk::{
99
clock::Slot,
10+
feature_set::FeatureSet,
1011
hash::Hash,
1112
message::{v0::LoadedAddresses, AddressLoaderError, Message, SimpleAddressLoader},
1213
pubkey::Pubkey,
@@ -40,6 +41,12 @@ pub enum DeserializedPacketError {
4041
FailedFilter(#[from] PacketFilterFailure),
4142
}
4243

44+
lazy_static::lazy_static! {
45+
// Make a dummy feature_set with all features enabled to
46+
// fetch compute_unit_price and compute_unit_limit for legacy leader.
47+
static ref FEATURE_SET: FeatureSet = FeatureSet::all_enabled();
48+
}
49+
4350
#[derive(Debug, Eq)]
4451
pub struct ImmutableDeserializedPacket {
4552
original_packet: Packet,
@@ -68,6 +75,7 @@ impl ImmutableDeserializedPacket {
6875
.get_message()
6976
.program_instructions_iter()
7077
.map(|(pubkey, ix)| (pubkey, SVMInstruction::from(ix))),
78+
&FEATURE_SET,
7179
)
7280
.map_err(|_| DeserializedPacketError::PrioritizationFailure)?;
7381

core/src/banking_stage/transaction_scheduler/scheduler_controller.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,12 @@ impl<T: LikeClusterInfo> SchedulerController<T> {
544544
.is_ok()
545545
})
546546
.filter_map(|(packet, tx, deactivation_slot)| {
547-
process_compute_budget_instructions(SVMMessage::program_instructions_iter(&tx))
548-
.map(|compute_budget| {
549-
(packet, tx, deactivation_slot, compute_budget.into())
550-
})
551-
.ok()
547+
process_compute_budget_instructions(
548+
SVMMessage::program_instructions_iter(&tx),
549+
&working_bank.feature_set,
550+
)
551+
.map(|compute_budget| (packet, tx, deactivation_slot, compute_budget.into()))
552+
.ok()
552553
})
553554
.for_each(|(packet, tx, deactivation_slot, fee_budget_limits)| {
554555
arc_packets.push(packet);
@@ -1094,7 +1095,7 @@ mod tests {
10941095
&Keypair::new(),
10951096
&Pubkey::new_unique(),
10961097
1,
1097-
i * 10,
1098+
i * 10_000,
10981099
bank.last_blockhash(),
10991100
)
11001101
})

cost-model/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ name = "solana_cost_model"
3636
itertools = { workspace = true }
3737
rand = "0.8.5"
3838
# See order-crates-for-publishing.py for using this unusual `path = "."`
39+
solana-compute-budget-program = { workspace = true }
3940
solana-cost-model = { path = ".", features = ["dev-context-only-utils"] }
4041
solana-logger = { workspace = true }
4142
solana-sdk = { workspace = true, features = ["dev-context-only-utils"] }

0 commit comments

Comments
 (0)