From edca61194c49fb47ebf27cdaecf62a6aedde7db2 Mon Sep 17 00:00:00 2001 From: ksolana <110843012+ksolana@users.noreply.github.com> Date: Tue, 7 Jan 2025 08:58:56 -0800 Subject: [PATCH] Vote cu --- Cargo.lock | 1 + cli/Cargo.toml | 5 +++ cli/benches/vote.rs | 79 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 cli/benches/vote.rs diff --git a/Cargo.lock b/Cargo.lock index 906564f8316908..19e6c4cc4a62c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6514,6 +6514,7 @@ dependencies = [ "clap 2.33.3", "console", "const_format", + "criterion", "criterion-stats", "crossbeam-channel", "ctrlc", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 25582e542a6bd7..277dbad770a113 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -66,6 +66,7 @@ tiny-bip39 = { workspace = true } [dev-dependencies] assert_matches = { workspace = true } +criterion = { workspace = true } solana-faucet = { workspace = true } solana-rpc = { workspace = true } solana-streamer = { workspace = true } @@ -73,6 +74,10 @@ solana-test-validator = { workspace = true } tempfile = { workspace = true } test-case = { workspace = true } +[[bench]] +name = "vote" +harness = false + [[bin]] name = "solana" path = "src/main.rs" diff --git a/cli/benches/vote.rs b/cli/benches/vote.rs new file mode 100644 index 00000000000000..488b4033f2392d --- /dev/null +++ b/cli/benches/vote.rs @@ -0,0 +1,79 @@ +use { + criterion::{criterion_group, criterion_main, Criterion}, + solana_cli::cli::{ + process_command, request_and_confirm_airdrop, CliCommand, CliConfig, + }, + solana_commitment_config::CommitmentConfig, + solana_faucet::faucet::run_local_faucet, + solana_rpc_client::rpc_client::RpcClient, + solana_rpc_client_nonce_utils::blockhash_query, + solana_rpc_client_nonce_utils::blockhash_query::BlockhashQuery, + solana_sdk::signature::{Keypair, Signer}, + solana_streamer::socket::SocketAddrSpace, + solana_test_validator::TestValidator, +}; + +struct TestSetup { + compute_unit_price: Option, +} + +impl TestSetup { + fn new(p: u64) -> TestSetup { + Self { + compute_unit_price: Some(p), + } + } + + pub fn run(&self) { + let mint_keypair = Keypair::new(); + let mint_pubkey = mint_keypair.pubkey(); + let faucet_addr = run_local_faucet(mint_keypair, None); + let test_validator = TestValidator::with_no_fees( + mint_pubkey, + Some(faucet_addr), + SocketAddrSpace::Unspecified, + ); + + let rpc_client = + RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); + let default_signer = Keypair::new(); + + let mut config = CliConfig::recent_for_tests(); + config.json_rpc_url = test_validator.rpc_url(); + config.signers = vec![&default_signer]; + + request_and_confirm_airdrop(&rpc_client, &config, &config.signers[0].pubkey(), 100_000) + .unwrap(); + + // Create vote account + let vote_account_keypair = Keypair::new(); + config.signers = vec![&default_signer, &vote_account_keypair]; + config.command = CliCommand::CreateVoteAccount { + vote_account: 1, + seed: None, + identity_account: 0, + authorized_voter: None, + authorized_withdrawer: config.signers[0].pubkey(), + commission: 0, + sign_only: false, + dump_transaction_message: false, + blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster), + nonce_account: None, + nonce_authority: 0, + memo: None, + fee_payer: 0, + compute_unit_price: self.compute_unit_price, + }; + process_command(&config).unwrap(); + } +} + +fn bench_create_vote_account(c: &mut Criterion) { + let test_setup = TestSetup::new(1_000_000); + c.bench_function("create_vote_account", |bencher| { + bencher.iter(|| test_setup.run()) + }); +} + +criterion_group!(benches, bench_create_vote_account,); +criterion_main!(benches);