Add Bank::set_bpf_compute_budget()

This commit is contained in:
Michael Vines
2020-10-28 13:16:13 -07:00
parent 66e51a7363
commit 7d686b72a0
7 changed files with 77 additions and 59 deletions

View File

@ -21,7 +21,7 @@ use solana_sdk::{
bpf_loader, bpf_loader_deprecated,
decode_error::DecodeError,
entrypoint::SUCCESS,
feature_set::{bpf_just_in_time_compilation, compute_budget_balancing},
feature_set::{bpf_compute_budget_balancing, bpf_just_in_time_compilation},
instruction::InstructionError,
keyed_account::{is_executable, next_keyed_account, KeyedAccount},
loader_instruction::LoaderInstruction,
@ -100,7 +100,7 @@ pub fn create_and_cache_executor(
.map_err(|e| map_ebpf_error(invoke_context, e))?;
bpf_verifier::check(
elf_bytes,
!invoke_context.is_feature_active(&compute_budget_balancing::id()),
!invoke_context.is_feature_active(&bpf_compute_budget_balancing::id()),
)
.map_err(|e| map_ebpf_error(invoke_context, EbpfError::UserError(e)))?;
let executor = Arc::new(BPFExecutor { executable });
@ -122,12 +122,12 @@ pub fn create_vm<'a>(
) -> Result<EbpfVm<'a, BPFError, ThisInstructionMeter>, EbpfError<BPFError>> {
let heap = vec![0_u8; DEFAULT_HEAP_SIZE];
let heap_region = MemoryRegion::new_from_slice(&heap, MM_HEAP_START, true);
let compute_budget = invoke_context.get_compute_budget();
let bpf_compute_budget = invoke_context.get_bpf_compute_budget();
let mut vm = EbpfVm::new(
executable,
Config {
max_call_depth: compute_budget.max_call_depth,
stack_frame_size: compute_budget.stack_frame_size,
max_call_depth: bpf_compute_budget.max_call_depth,
stack_frame_size: bpf_compute_budget.stack_frame_size,
},
parameter_bytes,
&[heap_region],
@ -329,7 +329,7 @@ mod tests {
account::Account,
feature_set::FeatureSet,
instruction::InstructionError,
process_instruction::{ComputeBudget, MockInvokeContext},
process_instruction::{BpfComputeBudget, MockInvokeContext},
rent::Rent,
};
use std::{cell::RefCell, fs::File, io::Read, ops::Range, rc::Rc};
@ -554,7 +554,7 @@ mod tests {
vec![],
&[],
None,
ComputeBudget {
BpfComputeBudget {
max_units: 1,
log_units: 100,
log_64_units: 100,

View File

@ -94,7 +94,7 @@ pub fn register_syscalls<'a>(
invoke_context: &'a mut dyn InvokeContext,
heap: Vec<u8>,
) -> Result<(), EbpfError<BPFError>> {
let compute_budget = invoke_context.get_compute_budget();
let bpf_compute_budget = invoke_context.get_bpf_compute_budget();
// Syscall functions common across languages
@ -106,7 +106,7 @@ pub fn register_syscalls<'a>(
vm.register_syscall(
hash_symbol_name(b"sol_log_"),
Syscall::Object(Box::new(SyscallLog {
cost: compute_budget.log_units,
cost: bpf_compute_budget.log_units,
compute_meter: invoke_context.get_compute_meter(),
logger: invoke_context.get_logger(),
loader_id,
@ -115,7 +115,7 @@ pub fn register_syscalls<'a>(
vm.register_syscall(
hash_symbol_name(b"sol_log_64_"),
Syscall::Object(Box::new(SyscallLogU64 {
cost: compute_budget.log_64_units,
cost: bpf_compute_budget.log_64_units,
compute_meter: invoke_context.get_compute_meter(),
logger: invoke_context.get_logger(),
})),
@ -135,7 +135,7 @@ pub fn register_syscalls<'a>(
vm.register_syscall(
hash_symbol_name(b"sol_log_pubkey"),
Syscall::Object(Box::new(SyscallLogPubkey {
cost: compute_budget.log_pubkey_units,
cost: bpf_compute_budget.log_pubkey_units,
compute_meter: invoke_context.get_compute_meter(),
logger: invoke_context.get_logger(),
loader_id,
@ -147,8 +147,8 @@ pub fn register_syscalls<'a>(
vm.register_syscall(
hash_symbol_name(b"sol_sha256"),
Syscall::Object(Box::new(SyscallSha256 {
sha256_base_cost: compute_budget.sha256_base_cost,
sha256_byte_cost: compute_budget.sha256_byte_cost,
sha256_base_cost: bpf_compute_budget.sha256_base_cost,
sha256_byte_cost: bpf_compute_budget.sha256_byte_cost,
compute_meter: invoke_context.get_compute_meter(),
loader_id,
})),
@ -169,7 +169,7 @@ pub fn register_syscalls<'a>(
vm.register_syscall(
hash_symbol_name(b"sol_create_program_address"),
Syscall::Object(Box::new(SyscallCreateProgramAddress {
cost: compute_budget.create_program_address_units,
cost: bpf_compute_budget.create_program_address_units,
compute_meter: invoke_context.get_compute_meter(),
loader_id,
})),
@ -1301,7 +1301,7 @@ fn call<'a>(
let mut invoke_context = syscall.get_context_mut()?;
invoke_context
.get_compute_meter()
.consume(invoke_context.get_compute_budget().invoke_units)?;
.consume(invoke_context.get_bpf_compute_budget().invoke_units)?;
// Translate data passed from the VM