compute_budget heap_size does not have to be optional (#33313)
This commit is contained in:
parent
1fc4264a1c
commit
a2ad820309
|
@ -101,8 +101,8 @@ pub struct ComputeBudget {
|
||||||
/// Number of compute units consumed for a multiscalar multiplication (msm) of ristretto points.
|
/// Number of compute units consumed for a multiscalar multiplication (msm) of ristretto points.
|
||||||
/// The total cost is calculated as `msm_base_cost + (length - 1) * msm_incremental_cost`.
|
/// The total cost is calculated as `msm_base_cost + (length - 1) * msm_incremental_cost`.
|
||||||
pub curve25519_ristretto_msm_incremental_cost: u64,
|
pub curve25519_ristretto_msm_incremental_cost: u64,
|
||||||
/// Optional program heap region size, if `None` then loader default
|
/// program heap region size, default: solana_sdk::entrypoint::HEAP_LENGTH
|
||||||
pub heap_size: Option<usize>,
|
pub heap_size: usize,
|
||||||
/// Number of compute units per additional 32k heap above the default (~.5
|
/// Number of compute units per additional 32k heap above the default (~.5
|
||||||
/// us per 32k at 15 units/us rounded up)
|
/// us per 32k at 15 units/us rounded up)
|
||||||
pub heap_cost: u64,
|
pub heap_cost: u64,
|
||||||
|
@ -171,7 +171,7 @@ impl ComputeBudget {
|
||||||
curve25519_ristretto_multiply_cost: 2_208,
|
curve25519_ristretto_multiply_cost: 2_208,
|
||||||
curve25519_ristretto_msm_base_cost: 2303,
|
curve25519_ristretto_msm_base_cost: 2303,
|
||||||
curve25519_ristretto_msm_incremental_cost: 788,
|
curve25519_ristretto_msm_incremental_cost: 788,
|
||||||
heap_size: None,
|
heap_size: solana_sdk::entrypoint::HEAP_LENGTH,
|
||||||
heap_cost: 8,
|
heap_cost: 8,
|
||||||
mem_op_base_cost: 10,
|
mem_op_base_cost: 10,
|
||||||
alt_bn128_addition_cost: 334,
|
alt_bn128_addition_cost: 334,
|
||||||
|
@ -267,7 +267,7 @@ impl ComputeBudget {
|
||||||
InstructionError::InvalidInstructionData,
|
InstructionError::InvalidInstructionData,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
self.heap_size = Some(bytes as usize);
|
self.heap_size = bytes as usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
let compute_unit_limit = updated_compute_unit_limit
|
let compute_unit_limit = updated_compute_unit_limit
|
||||||
|
@ -467,7 +467,7 @@ mod tests {
|
||||||
Ok(PrioritizationFeeDetails::default()),
|
Ok(PrioritizationFeeDetails::default()),
|
||||||
ComputeBudget {
|
ComputeBudget {
|
||||||
compute_unit_limit: DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT as u64,
|
compute_unit_limit: DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT as u64,
|
||||||
heap_size: Some(40 * 1024),
|
heap_size: 40 * 1024,
|
||||||
..ComputeBudget::default()
|
..ComputeBudget::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -512,7 +512,7 @@ mod tests {
|
||||||
Ok(PrioritizationFeeDetails::default()),
|
Ok(PrioritizationFeeDetails::default()),
|
||||||
ComputeBudget {
|
ComputeBudget {
|
||||||
compute_unit_limit: DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT as u64,
|
compute_unit_limit: DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT as u64,
|
||||||
heap_size: Some(MAX_HEAP_FRAME_BYTES as usize),
|
heap_size: MAX_HEAP_FRAME_BYTES as usize,
|
||||||
..ComputeBudget::default()
|
..ComputeBudget::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -562,7 +562,7 @@ mod tests {
|
||||||
)),
|
)),
|
||||||
ComputeBudget {
|
ComputeBudget {
|
||||||
compute_unit_limit: MAX_COMPUTE_UNIT_LIMIT as u64,
|
compute_unit_limit: MAX_COMPUTE_UNIT_LIMIT as u64,
|
||||||
heap_size: Some(MAX_HEAP_FRAME_BYTES as usize),
|
heap_size: MAX_HEAP_FRAME_BYTES as usize,
|
||||||
..ComputeBudget::default()
|
..ComputeBudget::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -580,7 +580,7 @@ mod tests {
|
||||||
)),
|
)),
|
||||||
ComputeBudget {
|
ComputeBudget {
|
||||||
compute_unit_limit: 1,
|
compute_unit_limit: 1,
|
||||||
heap_size: Some(MAX_HEAP_FRAME_BYTES as usize),
|
heap_size: MAX_HEAP_FRAME_BYTES as usize,
|
||||||
..ComputeBudget::default()
|
..ComputeBudget::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -262,10 +262,7 @@ macro_rules! create_vm {
|
||||||
($vm:ident, $program:expr, $regions:expr, $accounts_metadata:expr, $invoke_context:expr $(,)?) => {
|
($vm:ident, $program:expr, $regions:expr, $accounts_metadata:expr, $invoke_context:expr $(,)?) => {
|
||||||
let invoke_context = &*$invoke_context;
|
let invoke_context = &*$invoke_context;
|
||||||
let stack_size = $program.get_config().stack_size();
|
let stack_size = $program.get_config().stack_size();
|
||||||
let heap_size = invoke_context
|
let heap_size = invoke_context.get_compute_budget().heap_size;
|
||||||
.get_compute_budget()
|
|
||||||
.heap_size
|
|
||||||
.unwrap_or(solana_sdk::entrypoint::HEAP_LENGTH);
|
|
||||||
let round_up_heap_size = invoke_context
|
let round_up_heap_size = invoke_context
|
||||||
.feature_set
|
.feature_set
|
||||||
.is_active(&solana_sdk::feature_set::round_up_heap_size::id());
|
.is_active(&solana_sdk::feature_set::round_up_heap_size::id());
|
||||||
|
|
|
@ -18,7 +18,7 @@ use {
|
||||||
vm::{BuiltinProgram, Config, ContextObject, EbpfVm, ProgramResult},
|
vm::{BuiltinProgram, Config, ContextObject, EbpfVm, ProgramResult},
|
||||||
},
|
},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
entrypoint::{HEAP_LENGTH, SUCCESS},
|
entrypoint::SUCCESS,
|
||||||
feature_set,
|
feature_set,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
loader_v4::{self, LoaderV4State, LoaderV4Status, DEPLOYMENT_COOLDOWN_IN_SLOTS},
|
loader_v4::{self, LoaderV4State, LoaderV4Status, DEPLOYMENT_COOLDOWN_IN_SLOTS},
|
||||||
|
@ -113,15 +113,13 @@ pub fn create_vm<'a, 'b>(
|
||||||
let config = program.get_config();
|
let config = program.get_config();
|
||||||
let sbpf_version = program.get_sbpf_version();
|
let sbpf_version = program.get_sbpf_version();
|
||||||
let compute_budget = invoke_context.get_compute_budget();
|
let compute_budget = invoke_context.get_compute_budget();
|
||||||
let heap_size = compute_budget.heap_size.unwrap_or(HEAP_LENGTH);
|
let heap_size = compute_budget.heap_size;
|
||||||
invoke_context.consume_checked(calculate_heap_cost(
|
invoke_context.consume_checked(calculate_heap_cost(
|
||||||
heap_size as u64,
|
heap_size as u64,
|
||||||
compute_budget.heap_cost,
|
compute_budget.heap_cost,
|
||||||
))?;
|
))?;
|
||||||
let mut stack = AlignedMemory::<{ ebpf::HOST_ALIGN }>::zero_filled(config.stack_size());
|
let mut stack = AlignedMemory::<{ ebpf::HOST_ALIGN }>::zero_filled(config.stack_size());
|
||||||
let mut heap = AlignedMemory::<{ ebpf::HOST_ALIGN }>::zero_filled(
|
let mut heap = AlignedMemory::<{ ebpf::HOST_ALIGN }>::zero_filled(compute_budget.heap_size);
|
||||||
compute_budget.heap_size.unwrap_or(HEAP_LENGTH),
|
|
||||||
);
|
|
||||||
let stack_len = stack.len();
|
let stack_len = stack.len();
|
||||||
let regions: Vec<MemoryRegion> = vec![
|
let regions: Vec<MemoryRegion> = vec![
|
||||||
program.get_ro_region(),
|
program.get_ro_region(),
|
||||||
|
|
|
@ -9750,7 +9750,7 @@ fn test_compute_budget_program_noop() {
|
||||||
*compute_budget,
|
*compute_budget,
|
||||||
ComputeBudget {
|
ComputeBudget {
|
||||||
compute_unit_limit: compute_budget::DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT as u64,
|
compute_unit_limit: compute_budget::DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT as u64,
|
||||||
heap_size: Some(48 * 1024),
|
heap_size: 48 * 1024,
|
||||||
..ComputeBudget::default()
|
..ComputeBudget::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -9793,7 +9793,7 @@ fn test_compute_request_instruction() {
|
||||||
*compute_budget,
|
*compute_budget,
|
||||||
ComputeBudget {
|
ComputeBudget {
|
||||||
compute_unit_limit: compute_budget::DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT as u64,
|
compute_unit_limit: compute_budget::DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT as u64,
|
||||||
heap_size: Some(48 * 1024),
|
heap_size: 48 * 1024,
|
||||||
..ComputeBudget::default()
|
..ComputeBudget::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -9843,7 +9843,7 @@ fn test_failed_compute_request_instruction() {
|
||||||
*compute_budget,
|
*compute_budget,
|
||||||
ComputeBudget {
|
ComputeBudget {
|
||||||
compute_unit_limit: compute_budget::DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT as u64,
|
compute_unit_limit: compute_budget::DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT as u64,
|
||||||
heap_size: Some(48 * 1024),
|
heap_size: 48 * 1024,
|
||||||
..ComputeBudget::default()
|
..ComputeBudget::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue