-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9be8691
commit 17b7664
Showing
6 changed files
with
619 additions
and
83 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use std::path::PathBuf; | ||
|
||
use bench::{ | ||
benches::{ | ||
api_load::api_load, confirmation_rate::confirmation_rate, | ||
confirmation_slot::confirmation_slot, | ||
}, | ||
tx_size::TxSize, | ||
}; | ||
use clap::{Parser, Subcommand}; | ||
|
||
#[derive(Parser, Debug)] | ||
#[clap(version, about)] | ||
|
||
struct Arguments { | ||
#[clap(subcommand)] | ||
subcommand: SubCommand, | ||
} | ||
|
||
#[derive(Subcommand, Debug)] | ||
enum SubCommand { | ||
ApiLoad { | ||
#[clap(short, long)] | ||
payer_path: PathBuf, | ||
#[clap(short, long)] | ||
rpc_url: String, | ||
#[clap(short, long)] | ||
time_ms: u64, | ||
}, | ||
ConfirmationRate { | ||
#[clap(short, long)] | ||
payer_path: PathBuf, | ||
#[clap(short, long)] | ||
rpc_url: String, | ||
#[clap(short, long)] | ||
size_tx: TxSize, | ||
#[clap(short, long)] | ||
txns_per_round: usize, | ||
#[clap(short, long)] | ||
num_rounds: usize, | ||
}, | ||
ConfirmationSlot { | ||
#[clap(short, long)] | ||
payer_path: PathBuf, | ||
#[clap(short, long)] | ||
#[arg(short = 'a')] | ||
rpc_a: String, | ||
#[clap(short, long)] | ||
#[arg(short = 'b')] | ||
rpc_b: String, | ||
#[clap(short, long)] | ||
size_tx: TxSize, | ||
}, | ||
} | ||
|
||
pub fn initialize_logger() { | ||
tracing_subscriber::fmt() | ||
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) | ||
.with_thread_ids(true) | ||
.with_line_number(true) | ||
.init(); | ||
} | ||
|
||
#[tokio::main(flavor = "multi_thread", worker_threads = 16)] | ||
async fn main() { | ||
let args = Arguments::parse(); | ||
initialize_logger(); | ||
|
||
match args.subcommand { | ||
SubCommand::ApiLoad { | ||
payer_path, | ||
rpc_url, | ||
time_ms, | ||
} => { | ||
api_load(&payer_path, rpc_url, time_ms).await.unwrap(); | ||
} | ||
SubCommand::ConfirmationRate { | ||
payer_path, | ||
rpc_url, | ||
size_tx, | ||
txns_per_round, | ||
num_rounds, | ||
} => confirmation_rate(&payer_path, rpc_url, size_tx, txns_per_round, num_rounds) | ||
.await | ||
.unwrap(), | ||
SubCommand::ConfirmationSlot { | ||
payer_path, | ||
rpc_a, | ||
rpc_b, | ||
size_tx, | ||
} => confirmation_slot(&payer_path, rpc_a, rpc_b, size_tx) | ||
.await | ||
.unwrap(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
use anyhow::Context; | ||
use itertools::Itertools; | ||
use lazy_static::lazy_static; | ||
use rand::{distributions::Alphanumeric, prelude::Distribution, SeedableRng}; | ||
use solana_rpc_client::nonblocking::rpc_client::RpcClient; | ||
use solana_sdk::instruction::AccountMeta; | ||
use solana_sdk::{ | ||
commitment_config::CommitmentConfig, | ||
hash::Hash, | ||
instruction::Instruction, | ||
message::Message, | ||
pubkey::Pubkey, | ||
signature::{Keypair, Signature}, | ||
signer::Signer, | ||
system_instruction, | ||
transaction::Transaction, | ||
}; | ||
use std::path::PathBuf; | ||
use std::{str::FromStr, time::Duration}; | ||
use tokio::time::Instant; | ||
|
||
const MEMO_PROGRAM_ID: &str = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"; | ||
const WAIT_LIMIT_IN_SECONDS: u64 = 60; | ||
|
||
lazy_static! { | ||
static ref USER_KEYPAIR: PathBuf = { | ||
dirs::home_dir() | ||
.unwrap() | ||
.join(".config") | ||
.join("solana") | ||
.join("id.json") | ||
}; | ||
} | ||
|
||
pub struct BenchHelper; | ||
|
||
impl BenchHelper { | ||
pub async fn get_payer() -> anyhow::Result<Keypair> { | ||
let payer = tokio::fs::read_to_string(USER_KEYPAIR.as_path()) | ||
.await | ||
.context("Error reading payer file")?; | ||
let payer: Vec<u8> = serde_json::from_str(&payer)?; | ||
let payer = Keypair::from_bytes(&payer)?; | ||
|
||
Ok(payer) | ||
} | ||
|
||
pub async fn wait_till_signature_status( | ||
rpc_client: &RpcClient, | ||
sig: &Signature, | ||
commitment_config: CommitmentConfig, | ||
) -> anyhow::Result<()> { | ||
let instant = Instant::now(); | ||
loop { | ||
if instant.elapsed() > Duration::from_secs(WAIT_LIMIT_IN_SECONDS) { | ||
return Err(anyhow::Error::msg("Timedout waiting")); | ||
} | ||
if let Some(err) = rpc_client | ||
.get_signature_status_with_commitment(sig, commitment_config) | ||
.await? | ||
{ | ||
err?; | ||
return Ok(()); | ||
} | ||
} | ||
} | ||
|
||
pub fn create_transaction(funded_payer: &Keypair, blockhash: Hash) -> Transaction { | ||
let to_pubkey = Pubkey::new_unique(); | ||
|
||
// transfer instruction | ||
let instruction = | ||
system_instruction::transfer(&funded_payer.pubkey(), &to_pubkey, 1_000_000); | ||
|
||
let message = Message::new(&[instruction], Some(&funded_payer.pubkey())); | ||
|
||
Transaction::new(&[funded_payer], message, blockhash) | ||
} | ||
|
||
pub fn generate_random_strings( | ||
num_of_txs: usize, | ||
random_seed: Option<u64>, | ||
n_chars: usize, | ||
) -> Vec<Vec<u8>> { | ||
let seed = random_seed.map_or(0, |x| x); | ||
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(seed); | ||
(0..num_of_txs) | ||
.map(|_| Alphanumeric.sample_iter(&mut rng).take(n_chars).collect()) | ||
.collect() | ||
} | ||
|
||
#[inline] | ||
pub fn generate_txs( | ||
num_of_txs: usize, | ||
funded_payer: &Keypair, | ||
blockhash: Hash, | ||
random_seed: Option<u64>, | ||
) -> Vec<Transaction> { | ||
let seed = random_seed.map_or(0, |x| x); | ||
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(seed); | ||
(0..num_of_txs) | ||
.map(|_| { | ||
let random_bytes: Vec<u8> = Alphanumeric.sample_iter(&mut rng).take(10).collect(); | ||
|
||
Self::create_memo_tx_small(&random_bytes, funded_payer, blockhash) | ||
}) | ||
.collect() | ||
} | ||
|
||
pub fn create_memo_tx_small(msg: &[u8], payer: &Keypair, blockhash: Hash) -> Transaction { | ||
let memo = Pubkey::from_str(MEMO_PROGRAM_ID).unwrap(); | ||
|
||
let instruction = Instruction::new_with_bytes(memo, msg, vec![]); | ||
let message = Message::new(&[instruction], Some(&payer.pubkey())); | ||
Transaction::new(&[payer], message, blockhash) | ||
} | ||
|
||
pub fn create_memo_tx_large(msg: &[u8], payer: &Keypair, blockhash: Hash) -> Transaction { | ||
let accounts = (0..8).map(|_| Keypair::new()).collect_vec(); | ||
|
||
let memo = Pubkey::from_str(MEMO_PROGRAM_ID).unwrap(); | ||
|
||
let instruction = Instruction::new_with_bytes( | ||
memo, | ||
msg, | ||
accounts | ||
.iter() | ||
.map(|keypair| AccountMeta::new_readonly(keypair.pubkey(), true)) | ||
.collect_vec(), | ||
); | ||
let message = Message::new(&[instruction], Some(&payer.pubkey())); | ||
|
||
let mut signers = vec![payer]; | ||
signers.extend(accounts.iter()); | ||
|
||
Transaction::new(&signers, message, blockhash) | ||
} | ||
} |
Oops, something went wrong.