Reduce budget request instruction length (#20636)
This commit is contained in:
@ -293,20 +293,17 @@ impl SanitizedMessage {
|
|||||||
|
|
||||||
/// Calculate the total fees for a transaction given a fee calculator
|
/// Calculate the total fees for a transaction given a fee calculator
|
||||||
pub fn calculate_fee(&self, fee_calculator: &FeeCalculator) -> u64 {
|
pub fn calculate_fee(&self, fee_calculator: &FeeCalculator) -> u64 {
|
||||||
let mut num_secp256k1_signatures: u64 = 0;
|
let mut num_signatures = u64::from(self.header().num_required_signatures);
|
||||||
for (program_id, instruction) in self.program_instructions_iter() {
|
for (program_id, instruction) in self.program_instructions_iter() {
|
||||||
if secp256k1_program::check_id(program_id) {
|
if secp256k1_program::check_id(program_id) {
|
||||||
if let Some(num_signatures) = instruction.data.get(0) {
|
if let Some(num_verifies) = instruction.data.get(0) {
|
||||||
num_secp256k1_signatures =
|
num_signatures =
|
||||||
num_secp256k1_signatures.saturating_add(u64::from(*num_signatures));
|
num_signatures.saturating_add(u64::from(*num_verifies));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fee_calculator.lamports_per_signature.saturating_mul(
|
fee_calculator.lamports_per_signature.saturating_mul(num_signatures)
|
||||||
u64::from(self.header().num_required_signatures)
|
|
||||||
.saturating_add(num_secp256k1_signatures),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inspect all message keys for the bpf upgradeable loader
|
/// Inspect all message keys for the bpf upgradeable loader
|
||||||
|
@ -11,7 +11,7 @@ use {
|
|||||||
|
|
||||||
crate::declare_id!("ComputeBudget111111111111111111111111111111");
|
crate::declare_id!("ComputeBudget111111111111111111111111111111");
|
||||||
|
|
||||||
const MAX_UNITS: u64 = 1_000_000;
|
const MAX_UNITS: u32 = 1_000_000;
|
||||||
|
|
||||||
/// Compute Budget Instructions
|
/// Compute Budget Instructions
|
||||||
#[derive(
|
#[derive(
|
||||||
@ -29,11 +29,11 @@ const MAX_UNITS: u64 = 1_000_000;
|
|||||||
pub enum ComputeBudgetInstruction {
|
pub enum ComputeBudgetInstruction {
|
||||||
/// Request a specific maximum number of compute units the transaction is
|
/// Request a specific maximum number of compute units the transaction is
|
||||||
/// allowed to consume.
|
/// allowed to consume.
|
||||||
RequestUnits(u64),
|
RequestUnits(u32),
|
||||||
}
|
}
|
||||||
impl ComputeBudgetInstruction {
|
impl ComputeBudgetInstruction {
|
||||||
/// Create a `ComputeBudgetInstruction::RequestUnits` `Instruction`
|
/// Create a `ComputeBudgetInstruction::RequestUnits` `Instruction`
|
||||||
pub fn request_units(units: u64) -> Instruction {
|
pub fn request_units(units: u32) -> Instruction {
|
||||||
Instruction::new_with_borsh(id(), &ComputeBudgetInstruction::RequestUnits(units), vec![])
|
Instruction::new_with_borsh(id(), &ComputeBudgetInstruction::RequestUnits(units), vec![])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ impl ComputeBudget {
|
|||||||
if units > MAX_UNITS {
|
if units > MAX_UNITS {
|
||||||
return Err(error);
|
return Err(error);
|
||||||
}
|
}
|
||||||
self.max_units = units;
|
self.max_units = units as u64;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -203,7 +203,7 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
compute_budget,
|
compute_budget,
|
||||||
ComputeBudget {
|
ComputeBudget {
|
||||||
max_units: MAX_UNITS,
|
max_units: MAX_UNITS as u64,
|
||||||
..ComputeBudget::default()
|
..ComputeBudget::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user