Refactoring: Move KeyedAccounts to InvokeContext (#15410)

Collects all parametric occurrences and the construction of keyed_accounts and puts them into InvokeContext.
This commit is contained in:
Alexander Meißner
2021-04-19 18:48:48 +02:00
committed by GitHub
parent 015bc034a5
commit 9dfcb921cf
27 changed files with 1508 additions and 1408 deletions

View File

@ -76,7 +76,7 @@ fn bench_program_create_executable(bencher: &mut Bencher) {
bencher.iter(|| {
let _ =
Executable::<BpfError, ThisInstructionMeter>::from_elf(&elf, None, Config::default())
<dyn Executable::<BpfError, ThisInstructionMeter>>::from_elf(&elf, None, Config::default())
.unwrap();
});
}
@ -91,11 +91,11 @@ fn bench_program_alu(bencher: &mut Bencher) {
.unwrap();
inner_iter.write_u64::<LittleEndian>(0).unwrap();
let loader_id = bpf_loader::id();
let mut invoke_context = MockInvokeContext::default();
let mut invoke_context = MockInvokeContext::new(vec![]);
let elf = load_elf("bench_alu").unwrap();
let mut executable =
Executable::<BpfError, ThisInstructionMeter>::from_elf(&elf, None, Config::default())
<dyn Executable::<BpfError, ThisInstructionMeter>>::from_elf(&elf, None, Config::default())
.unwrap();
executable.set_syscall_registry(register_syscalls(&mut invoke_context).unwrap());
executable.jit_compile().unwrap();
@ -105,7 +105,6 @@ fn bench_program_alu(bencher: &mut Bencher) {
&loader_id,
executable.as_ref(),
&mut inner_iter,
&[],
&mut invoke_context,
)
.unwrap();
@ -195,8 +194,6 @@ fn bench_program_execute_noop(bencher: &mut Bencher) {
fn bench_instruction_count_tuner(_bencher: &mut Bencher) {
const BUDGET: u64 = 200_000;
let loader_id = bpf_loader::id();
let mut invoke_context = MockInvokeContext::default();
invoke_context.compute_meter.remaining = BUDGET;
let accounts = [RefCell::new(AccountSharedData::new(
1,
@ -211,18 +208,22 @@ fn bench_instruction_count_tuner(_bencher: &mut Bencher) {
.collect();
let instruction_data = vec![0u8];
let mut invoke_context = MockInvokeContext::new(keyed_accounts);
invoke_context.compute_meter.remaining = BUDGET;
// Serialize account data
let keyed_accounts = invoke_context.get_keyed_accounts().unwrap();
let mut serialized = serialize_parameters(
&bpf_loader::id(),
&solana_sdk::pubkey::new_rand(),
&keyed_accounts,
keyed_accounts,
&instruction_data,
)
.unwrap();
let elf = load_elf("tuner").unwrap();
let mut executable =
Executable::<BpfError, ThisInstructionMeter>::from_elf(&elf, None, Config::default())
<dyn Executable::<BpfError, ThisInstructionMeter>>::from_elf(&elf, None, Config::default())
.unwrap();
executable.set_syscall_registry(register_syscalls(&mut invoke_context).unwrap());
let compute_meter = invoke_context.get_compute_meter();
@ -231,7 +232,6 @@ fn bench_instruction_count_tuner(_bencher: &mut Bencher) {
&loader_id,
executable.as_ref(),
&mut serialized,
&[],
&mut invoke_context,
)
.unwrap();