Skip to content

Commit

Permalink
add set_authority_checked
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillLykov committed Dec 13, 2024
1 parent bd3480a commit d6cb826
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions programs/bpf_loader/benches/bpf_loader_upgradeable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl TestSetup {
.unwrap();
}

fn prep_set_authority(&mut self) {
fn prep_set_authority(&mut self, checked: bool) {
let new_authority_address = Pubkey::new_unique();
self.instruction_accounts = vec![
AccountMeta {
Expand All @@ -121,7 +121,7 @@ impl TestSetup {
},
AccountMeta {
pubkey: new_authority_address,
is_signer: false,
is_signer: checked,
is_writable: false,
},
];
Expand All @@ -137,8 +137,12 @@ impl TestSetup {
new_authority_address,
AccountSharedData::new(ACCOUNT_BALANCE, 0, &self.loader_address),
));
self.instruction_data =
bincode::serialize(&UpgradeableLoaderInstruction::SetAuthority).unwrap();
let instruction = if checked {
UpgradeableLoaderInstruction::SetAuthorityChecked
} else {
UpgradeableLoaderInstruction::SetAuthority
};
self.instruction_data = bincode::serialize(&instruction).unwrap();
}

fn prep_close(&mut self) {
Expand Down Expand Up @@ -353,7 +357,7 @@ fn bench_upgradeable_upgrade(c: &mut Criterion) {

fn bench_set_authority(c: &mut Criterion) {
let mut test_setup = TestSetup::new();
test_setup.prep_set_authority();
test_setup.prep_set_authority(false);

c.bench_function("set_authority", |bencher| {
bencher.iter(|| {
Expand All @@ -373,12 +377,24 @@ fn bench_close(c: &mut Criterion) {
});
}

fn bench_set_authority_checked(c: &mut Criterion) {
let mut test_setup = TestSetup::new();
test_setup.prep_set_authority(true);

c.bench_function("set_authority_checked", |bencher| {
bencher.iter(|| {
test_setup.run();
})
});
}

criterion_group!(
benches,
bench_initialize_buffer,
bench_write,
bench_upgradeable_upgrade,
bench_set_authority,
bench_close
bench_close,
bench_set_authority_checked
);
criterion_main!(benches);

0 comments on commit d6cb826

Please sign in to comment.