Skip to content

Commit

Permalink
use get_multiple_accounts in bench-tps
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Lykov committed Aug 26, 2022
1 parent b0138f9 commit 3da1fcb
Showing 1 changed file with 88 additions and 44 deletions.
132 changes: 88 additions & 44 deletions bench-tps/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use {
rayon::prelude::*,
solana_metrics::{self, datapoint_info},
solana_sdk::{
account::Account,
clock::{DEFAULT_MS_PER_SLOT, DEFAULT_S_PER_SLOT, MAX_PROCESSING_AGE},
commitment_config::CommitmentConfig,
compute_budget::ComputeBudgetInstruction,
hash::Hash,
instruction::{AccountMeta, Instruction},
Expand All @@ -24,7 +24,7 @@ use {
transaction::Transaction,
},
std::{
collections::VecDeque,
collections::{HashSet, VecDeque},
process::exit,
sync::{
atomic::{AtomicBool, AtomicIsize, AtomicUsize, Ordering},
Expand Down Expand Up @@ -540,21 +540,15 @@ fn transfer_with_compute_unit_price(
Transaction::new(&[from_keypair], message, recent_blockhash)
}

fn get_nonce_blockhash<T: 'static + BenchTpsClient + Send + Sync + ?Sized>(
client: Arc<T>,
nonce_account_pubkey: Pubkey,
) -> Hash {
fn get_nonce_accounts<T: 'static + BenchTpsClient + Send + Sync + ?Sized>(
client: &Arc<T>,
nonce_pubkeys: &[Pubkey],
) -> Vec<Option<Account>> {
loop {
match client
.get_account_with_commitment(&nonce_account_pubkey, CommitmentConfig::processed())
{
Ok(nonce_account) => match nonce_utils::data_from_account(&nonce_account) {
Ok(nonce_data) => return nonce_data.blockhash(),
Err(err) => {
info!("Couldn't get data from durable nonce account: {:?}", err);
sleep(Duration::from_secs(1));
}
},
match client.get_multiple_accounts(&nonce_pubkeys) {
Ok(nonce_account) => {
return nonce_account;
}
Err(err) => {
info!("Couldn't get durable nonce account: {:?}", err);
sleep(Duration::from_secs(1));
Expand All @@ -563,6 +557,47 @@ fn get_nonce_blockhash<T: 'static + BenchTpsClient + Send + Sync + ?Sized>(
}
}

fn get_nonce_blockhashes<T: 'static + BenchTpsClient + Send + Sync + ?Sized>(
client: Arc<T>,
nonce_pubkeys: &[Pubkey],
) -> Vec<Hash> {
let num_accounts = nonce_pubkeys.len();
let mut blockhashes = vec![Hash::default(); num_accounts];
let mut unprocessed = HashSet::with_capacity(num_accounts);
for i in 0..num_accounts {
unprocessed.insert(i);
}

let mut request_pubkeys = Vec::<Pubkey>::with_capacity(num_accounts);
let mut request_indexes = Vec::<usize>::with_capacity(num_accounts);

while !unprocessed.is_empty() {
for i in &unprocessed {
request_pubkeys.push(nonce_pubkeys[*i]);
request_indexes.push(*i);
}

let num_unprocessed_before = unprocessed.len();
info!("Request {} durable nonce accounts", num_unprocessed_before);
let accounts = get_nonce_accounts(&client, nonce_pubkeys);
for (account, index) in accounts.iter().zip(request_indexes.iter()) {
if let Some(nonce_account) = account {
let nonce_data = nonce_utils::data_from_account(nonce_account).unwrap();
blockhashes[*index] = nonce_data.blockhash();
unprocessed.remove(index);
}
}
let num_unprocessed_after = unprocessed.len();
info!(
"Received {} durable nonce accounts",
num_unprocessed_before - num_unprocessed_after
);
request_pubkeys.clear();
request_indexes.clear();
}
blockhashes
}

fn generate_nonced_system_txs<T: 'static + BenchTpsClient + Send + Sync + ?Sized>(
client: Arc<T>,
source: &[&Keypair],
Expand All @@ -573,34 +608,43 @@ fn generate_nonced_system_txs<T: 'static + BenchTpsClient + Send + Sync + ?Sized
) -> Vec<TimestampedTransaction> {
let length = source.len();
let mut transactions: Vec<TimestampedTransaction> = Vec::with_capacity(length);
for i in 0..length {
let (from, to, nonce, nonce_blockhash) = if !reclaim {
(
source[i],
dest[i],
source_nonce[i],
get_nonce_blockhash(client.clone(), source_nonce[i].pubkey()),
)
} else {
(
dest[i],
source[i],
dest_nonce[i],
get_nonce_blockhash(client.clone(), dest_nonce[i].pubkey()),
)
};

transactions.push((
system_transaction::nonced_transfer(
from,
&to.pubkey(),
1,
&nonce.pubkey(),
from,
nonce_blockhash,
),
None,
));
if !reclaim {
let pubkeys: Vec<Pubkey> = source_nonce
.iter()
.map(|keypair| keypair.pubkey())
.collect();
let blockhashes = get_nonce_blockhashes(client, &pubkeys);

for i in 0..length {
transactions.push((
system_transaction::nonced_transfer(
source[i],
&dest[i].pubkey(),
1,
&source_nonce[i].pubkey(),
source[i],
blockhashes[i],
),
None,
));
}
} else {
let pubkeys: Vec<Pubkey> = dest_nonce.iter().map(|keypair| keypair.pubkey()).collect();
let blockhashes = get_nonce_blockhashes(client, &pubkeys);

for i in 0..length {
transactions.push((
system_transaction::nonced_transfer(
dest[i],
&source[i].pubkey(),
1,
&dest_nonce[i].pubkey(),
dest[i],
blockhashes[i],
),
None,
));
}
}
transactions
}
Expand Down

0 comments on commit 3da1fcb

Please sign in to comment.