2022-12-22 00:58:06 -08:00
|
|
|
//! The compute budget native program.
|
|
|
|
|
2021-07-16 00:31:22 -07:00
|
|
|
#![cfg(feature = "full")]
|
|
|
|
|
2021-08-17 15:17:56 -07:00
|
|
|
use {
|
2022-01-17 04:48:00 -08:00
|
|
|
crate::instruction::Instruction,
|
2022-02-11 16:23:16 -08:00
|
|
|
borsh::{BorshDeserialize, BorshSerialize},
|
2021-07-16 00:31:22 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
crate::declare_id!("ComputeBudget111111111111111111111111111111");
|
|
|
|
|
|
|
|
/// Compute Budget Instructions
|
|
|
|
#[derive(
|
2022-02-11 16:23:16 -08:00
|
|
|
AbiExample,
|
|
|
|
AbiEnumVisitor,
|
2021-07-16 00:31:22 -07:00
|
|
|
BorshDeserialize,
|
2022-02-11 16:23:16 -08:00
|
|
|
BorshSerialize,
|
2021-07-16 00:31:22 -07:00
|
|
|
Clone,
|
2022-02-11 16:23:16 -08:00
|
|
|
Debug,
|
|
|
|
Deserialize,
|
2021-07-16 00:31:22 -07:00
|
|
|
PartialEq,
|
2022-05-22 18:00:42 -07:00
|
|
|
Eq,
|
2022-02-11 16:23:16 -08:00
|
|
|
Serialize,
|
2021-07-16 00:31:22 -07:00
|
|
|
)]
|
|
|
|
pub enum ComputeBudgetInstruction {
|
2022-05-12 11:07:36 -07:00
|
|
|
/// Deprecated
|
2022-09-09 15:24:21 -07:00
|
|
|
// TODO: after feature remove_deprecated_request_unit_ix::id() is activated, replace it with 'unused'
|
2022-05-12 11:07:36 -07:00
|
|
|
RequestUnitsDeprecated {
|
2022-02-11 16:23:16 -08:00
|
|
|
/// Units to request
|
|
|
|
units: u32,
|
|
|
|
/// Additional fee to add
|
|
|
|
additional_fee: u32,
|
|
|
|
},
|
|
|
|
/// Request a specific transaction-wide program heap region size in bytes.
|
|
|
|
/// The value requested must be a multiple of 1024. This new heap region
|
2022-05-12 11:07:36 -07:00
|
|
|
/// size applies to each program executed in the transaction, including all
|
|
|
|
/// calls to CPIs.
|
2021-10-19 21:01:39 -07:00
|
|
|
RequestHeapFrame(u32),
|
2022-05-17 22:14:31 -07:00
|
|
|
/// Set a specific compute unit limit that the transaction is allowed to consume.
|
|
|
|
SetComputeUnitLimit(u32),
|
2022-05-15 21:06:33 -07:00
|
|
|
/// Set a compute unit price in "micro-lamports" to pay a higher transaction
|
|
|
|
/// fee for higher transaction prioritization.
|
|
|
|
SetComputeUnitPrice(u64),
|
2023-02-24 07:27:49 -08:00
|
|
|
/// Set a specific transaction-wide account data size limit, in bytes, is allowed to load.
|
|
|
|
SetLoadedAccountsDataSizeLimit(u32),
|
2021-07-16 00:31:22 -07:00
|
|
|
}
|
2022-01-17 04:48:00 -08:00
|
|
|
|
2021-07-22 10:18:51 -07:00
|
|
|
impl ComputeBudgetInstruction {
|
2022-05-12 11:07:36 -07:00
|
|
|
/// Create a `ComputeBudgetInstruction::RequestHeapFrame` `Instruction`
|
|
|
|
pub fn request_heap_frame(bytes: u32) -> Instruction {
|
|
|
|
Instruction::new_with_borsh(id(), &Self::RequestHeapFrame(bytes), vec![])
|
|
|
|
}
|
|
|
|
|
2022-05-17 22:14:31 -07:00
|
|
|
/// Create a `ComputeBudgetInstruction::SetComputeUnitLimit` `Instruction`
|
|
|
|
pub fn set_compute_unit_limit(units: u32) -> Instruction {
|
|
|
|
Instruction::new_with_borsh(id(), &Self::SetComputeUnitLimit(units), vec![])
|
2021-07-22 10:18:51 -07:00
|
|
|
}
|
2022-01-17 04:48:00 -08:00
|
|
|
|
2022-05-15 21:06:33 -07:00
|
|
|
/// Create a `ComputeBudgetInstruction::SetComputeUnitPrice` `Instruction`
|
|
|
|
pub fn set_compute_unit_price(micro_lamports: u64) -> Instruction {
|
|
|
|
Instruction::new_with_borsh(id(), &Self::SetComputeUnitPrice(micro_lamports), vec![])
|
2021-10-19 21:01:39 -07:00
|
|
|
}
|
2022-11-14 08:29:35 -08:00
|
|
|
|
2022-11-22 09:55:56 -08:00
|
|
|
/// Serialize Instruction using borsh, this is only used in runtime::cost_model::tests but compilation
|
|
|
|
/// can't be restricted as it's used across packages
|
|
|
|
// #[cfg(test)]
|
|
|
|
pub fn pack(self) -> Result<Vec<u8>, std::io::Error> {
|
|
|
|
self.try_to_vec()
|
|
|
|
}
|
2023-02-24 07:27:49 -08:00
|
|
|
|
|
|
|
/// Create a `ComputeBudgetInstruction::SetLoadedAccountsDataSizeLimit` `Instruction`
|
|
|
|
pub fn set_loaded_accounts_data_size_limit(bytes: u32) -> Instruction {
|
|
|
|
Instruction::new_with_borsh(id(), &Self::SetLoadedAccountsDataSizeLimit(bytes), vec![])
|
|
|
|
}
|
2021-07-16 00:31:22 -07:00
|
|
|
}
|