benches/bpf_loader: make account writable in bench_instruction_count_… (#28224)

benches/bpf_loader: make account writable in bench_instruction_count_tuner

The tuner program writes to its input account. This fixes the benchmark with
the direct_mapping branch, where we do enforce permissions before execution.
This commit is contained in:
Alessandro Decina 2022-10-04 22:44:22 +01:00 committed by GitHub
parent 7ae7a3ff0e
commit ac983b725f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 10 deletions

View File

@ -998,27 +998,26 @@ pub fn prepare_mock_invoke_context(
pub fn with_mock_invoke_context<R, F: FnMut(&mut InvokeContext) -> R>( pub fn with_mock_invoke_context<R, F: FnMut(&mut InvokeContext) -> R>(
loader_id: Pubkey, loader_id: Pubkey,
account_size: usize, account_size: usize,
is_writable: bool,
mut callback: F, mut callback: F,
) -> R { ) -> R {
let program_indices = vec![0, 1]; let program_indices = vec![0, 1];
let program_key = Pubkey::new_unique();
let transaction_accounts = vec![ let transaction_accounts = vec![
( (
loader_id, loader_id,
AccountSharedData::new(0, 0, &native_loader::id()), AccountSharedData::new(0, 0, &native_loader::id()),
), ),
(program_key, AccountSharedData::new(1, 0, &loader_id)),
( (
Pubkey::new_unique(), Pubkey::new_unique(),
AccountSharedData::new(1, 0, &loader_id), AccountSharedData::new(2, account_size, &program_key),
),
(
Pubkey::new_unique(),
AccountSharedData::new(2, account_size, &Pubkey::new_unique()),
), ),
]; ];
let instruction_accounts = vec![AccountMeta { let instruction_accounts = vec![AccountMeta {
pubkey: transaction_accounts.get(2).unwrap().0, pubkey: transaction_accounts.get(2).unwrap().0,
is_signer: false, is_signer: false,
is_writable: false, is_writable,
}]; }];
let preparation = let preparation =
prepare_mock_invoke_context(transaction_accounts, instruction_accounts, &program_indices); prepare_mock_invoke_context(transaction_accounts, instruction_accounts, &program_indices);

View File

@ -31,6 +31,7 @@ use {
instruction::{AccountMeta, Instruction}, instruction::{AccountMeta, Instruction},
message::Message, message::Message,
pubkey::Pubkey, pubkey::Pubkey,
rent::Rent,
signature::{Keypair, Signer}, signature::{Keypair, Signer},
}, },
std::{env, fs::File, io::Read, mem, path::PathBuf, sync::Arc}, std::{env, fs::File, io::Read, mem, path::PathBuf, sync::Arc},
@ -100,7 +101,7 @@ fn bench_program_alu(bencher: &mut Bencher) {
inner_iter.write_u64::<LittleEndian>(0).unwrap(); inner_iter.write_u64::<LittleEndian>(0).unwrap();
let elf = load_elf("bench_alu").unwrap(); let elf = load_elf("bench_alu").unwrap();
let loader_id = bpf_loader::id(); let loader_id = bpf_loader::id();
with_mock_invoke_context(loader_id, 10000001, |invoke_context| { with_mock_invoke_context(loader_id, 10000001, false, |invoke_context| {
invoke_context invoke_context
.get_compute_meter() .get_compute_meter()
.borrow_mut() .borrow_mut()
@ -216,7 +217,7 @@ fn bench_program_execute_noop(bencher: &mut Bencher) {
fn bench_create_vm(bencher: &mut Bencher) { fn bench_create_vm(bencher: &mut Bencher) {
let elf = load_elf("noop").unwrap(); let elf = load_elf("noop").unwrap();
let loader_id = bpf_loader::id(); let loader_id = bpf_loader::id();
with_mock_invoke_context(loader_id, 10000001, |invoke_context| { with_mock_invoke_context(loader_id, 10000001, false, |invoke_context| {
const BUDGET: u64 = 200_000; const BUDGET: u64 = 200_000;
invoke_context invoke_context
.get_compute_meter() .get_compute_meter()
@ -264,7 +265,7 @@ fn bench_create_vm(bencher: &mut Bencher) {
fn bench_instruction_count_tuner(_bencher: &mut Bencher) { fn bench_instruction_count_tuner(_bencher: &mut Bencher) {
let elf = load_elf("tuner").unwrap(); let elf = load_elf("tuner").unwrap();
let loader_id = bpf_loader::id(); let loader_id = bpf_loader::id();
with_mock_invoke_context(loader_id, 10000001, |invoke_context| { with_mock_invoke_context(loader_id, 10000001, true, |invoke_context| {
const BUDGET: u64 = 200_000; const BUDGET: u64 = 200_000;
invoke_context invoke_context
.get_compute_meter() .get_compute_meter()

View File

@ -223,7 +223,7 @@ fn run_program(name: &str) -> u64 {
let mut data = vec![]; let mut data = vec![];
file.read_to_end(&mut data).unwrap(); file.read_to_end(&mut data).unwrap();
let loader_id = bpf_loader::id(); let loader_id = bpf_loader::id();
with_mock_invoke_context(loader_id, 0, |invoke_context| { with_mock_invoke_context(loader_id, 0, false, |invoke_context| {
let (parameter_bytes, account_lengths) = serialize_parameters( let (parameter_bytes, account_lengths) = serialize_parameters(
invoke_context.transaction_context, invoke_context.transaction_context,
invoke_context invoke_context