Skip to content

Commit

Permalink
bench-tps: allow option to not set account data size
Browse files Browse the repository at this point in the history
  • Loading branch information
anwayde committed Mar 12, 2024
1 parent 0f1ca20 commit 32a51ad
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 18 deletions.
58 changes: 43 additions & 15 deletions bench-tps/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ struct TransactionChunkGenerator<'a, 'b, T: ?Sized> {
reclaim_lamports_back_to_source_account: bool,
compute_unit_price: Option<ComputeUnitPrice>,
instruction_padding_config: Option<InstructionPaddingConfig>,
skip_tx_account_data_size: bool,
}

impl<'a, 'b, T> TransactionChunkGenerator<'a, 'b, T>
Expand All @@ -153,6 +154,7 @@ where
compute_unit_price: Option<ComputeUnitPrice>,
instruction_padding_config: Option<InstructionPaddingConfig>,
num_conflict_groups: Option<usize>,
skip_tx_account_data_size: bool,
) -> Self {
let account_chunks = if let Some(num_conflict_groups) = num_conflict_groups {
KeypairChunks::new_with_conflict_groups(gen_keypairs, chunk_size, num_conflict_groups)
Expand All @@ -170,6 +172,7 @@ where
reclaim_lamports_back_to_source_account: false,
compute_unit_price,
instruction_padding_config,
skip_tx_account_data_size,
}
}

Expand All @@ -195,6 +198,7 @@ where
source_nonce_chunk,
dest_nonce_chunk,
self.reclaim_lamports_back_to_source_account,
self.skip_tx_account_data_size,
&self.instruction_padding_config,
)
} else {
Expand All @@ -206,6 +210,7 @@ where
blockhash.unwrap(),
&self.instruction_padding_config,
&self.compute_unit_price,
self.skip_tx_account_data_size,
)
};

Expand Down Expand Up @@ -397,6 +402,7 @@ where
sustained,
target_slots_per_epoch,
compute_unit_price,
skip_tx_account_data_size,
use_durable_nonce,
instruction_padding_config,
num_conflict_groups,
Expand All @@ -412,6 +418,7 @@ where
compute_unit_price,
instruction_padding_config,
num_conflict_groups,
skip_tx_account_data_size,
);

let first_tx_count = loop {
Expand Down Expand Up @@ -538,6 +545,7 @@ fn generate_system_txs(
blockhash: &Hash,
instruction_padding_config: &Option<InstructionPaddingConfig>,
compute_unit_price: &Option<ComputeUnitPrice>,
skip_tx_account_data_size: bool,
) -> Vec<TimestampedTransaction> {
let pairs: Vec<_> = if !reclaim {
source.iter().zip(dest.iter()).collect()
Expand Down Expand Up @@ -575,6 +583,7 @@ fn generate_system_txs(
*blockhash,
instruction_padding_config,
Some(**compute_unit_price),
skip_tx_account_data_size,
),
Some(timestamp()),
)
Expand All @@ -592,6 +601,7 @@ fn generate_system_txs(
*blockhash,
instruction_padding_config,
None,
skip_tx_account_data_size,
),
Some(timestamp()),
)
Expand All @@ -607,6 +617,7 @@ fn transfer_with_compute_unit_price_and_padding(
recent_blockhash: Hash,
instruction_padding_config: &Option<InstructionPaddingConfig>,
compute_unit_price: Option<u64>,
skip_tx_account_data_size: bool,
) -> Transaction {
let from_pubkey = from_keypair.pubkey();
let transfer_instruction = system_instruction::transfer(&from_pubkey, to, lamports);
Expand All @@ -621,12 +632,15 @@ fn transfer_with_compute_unit_price_and_padding(
} else {
transfer_instruction
};
let mut instructions = vec![
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(
let mut instructions = vec![];
if !skip_tx_account_data_size {
instructions.push(
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(
get_transaction_loaded_accounts_data_size(instruction_padding_config.is_some()),
),
instruction,
];
)
)
}
instructions.push(instruction);
if instruction_padding_config.is_some() {
// By default, CU budget is DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT which is much larger than needed
instructions.push(ComputeBudgetInstruction::set_compute_unit_limit(
Expand Down Expand Up @@ -711,6 +725,7 @@ fn nonced_transfer_with_padding(
nonce_account: &Pubkey,
nonce_authority: &Keypair,
nonce_hash: Hash,
skip_tx_account_data_size: bool,
instruction_padding_config: &Option<InstructionPaddingConfig>,
) -> Transaction {
let from_pubkey = from_keypair.pubkey();
Expand All @@ -726,12 +741,15 @@ fn nonced_transfer_with_padding(
} else {
transfer_instruction
};
let instructions = vec![
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(
let mut instructions = vec![];
if !skip_tx_account_data_size {
instructions.push(
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(
get_transaction_loaded_accounts_data_size(instruction_padding_config.is_some()),
),
instruction,
];
)
)
}
instructions.push(instruction);
let message = Message::new_with_nonce(
instructions,
Some(&from_pubkey),
Expand All @@ -748,6 +766,7 @@ fn generate_nonced_system_txs<T: 'static + BenchTpsClient + Send + Sync + ?Sized
source_nonce: &[&Keypair],
dest_nonce: &VecDeque<&Keypair>,
reclaim: bool,
skip_tx_account_data_size: bool,
instruction_padding_config: &Option<InstructionPaddingConfig>,
) -> Vec<TimestampedTransaction> {
let length = source.len();
Expand All @@ -768,6 +787,7 @@ fn generate_nonced_system_txs<T: 'static + BenchTpsClient + Send + Sync + ?Sized
&source_nonce[i].pubkey(),
source[i],
blockhashes[i],
skip_tx_account_data_size,
instruction_padding_config,
),
None,
Expand All @@ -786,6 +806,7 @@ fn generate_nonced_system_txs<T: 'static + BenchTpsClient + Send + Sync + ?Sized
&dest_nonce[i].pubkey(),
dest[i],
blockhashes[i],
skip_tx_account_data_size,
instruction_padding_config,
),
None,
Expand Down Expand Up @@ -1046,6 +1067,7 @@ pub fn generate_and_fund_keypairs<T: 'static + BenchTpsClient + Send + Sync + ?S
funding_key: &Keypair,
keypair_count: usize,
lamports_per_account: u64,
skip_tx_account_data_size: bool,
enable_padding: bool,
) -> Result<Vec<Keypair>> {
let rent = client.get_minimum_balance_for_rent_exemption(0)?;
Expand All @@ -1059,6 +1081,7 @@ pub fn generate_and_fund_keypairs<T: 'static + BenchTpsClient + Send + Sync + ?S
&keypairs,
extra,
lamports_per_account,
skip_tx_account_data_size,
enable_padding,
)?;

Expand All @@ -1074,6 +1097,7 @@ pub fn fund_keypairs<T: 'static + BenchTpsClient + Send + Sync + ?Sized>(
keypairs: &[Keypair],
extra: u64,
lamports_per_account: u64,
skip_tx_account_data_size: bool,
enable_padding: bool,
) -> Result<()> {
let rent = client.get_minimum_balance_for_rent_exemption(0)?;
Expand Down Expand Up @@ -1131,6 +1155,10 @@ pub fn fund_keypairs<T: 'static + BenchTpsClient + Send + Sync + ?Sized>(
return Err(BenchTpsError::AirdropFailure);
}
}
let data_size_limit = match skip_tx_account_data_size {
true => 0,
false => get_transaction_loaded_accounts_data_size(enable_padding),
};

fund_keys(
client,
Expand All @@ -1139,7 +1167,7 @@ pub fn fund_keypairs<T: 'static + BenchTpsClient + Send + Sync + ?Sized>(
total,
max_fee,
lamports_per_account,
get_transaction_loaded_accounts_data_size(enable_padding),
data_size_limit,
);
}
Ok(())
Expand Down Expand Up @@ -1181,7 +1209,7 @@ mod tests {

let keypair_count = config.tx_count * config.keypair_multiplier;
let keypairs =
generate_and_fund_keypairs(client.clone(), &config.id, keypair_count, 20, false)
generate_and_fund_keypairs(client.clone(), &config.id, keypair_count, 20, false, false)
.unwrap();

do_bench_tps(client, config, keypairs, None);
Expand All @@ -1197,7 +1225,7 @@ mod tests {
let rent = client.get_minimum_balance_for_rent_exemption(0).unwrap();

let keypairs =
generate_and_fund_keypairs(client.clone(), &id, keypair_count, lamports, false)
generate_and_fund_keypairs(client.clone(), &id, keypair_count, lamports, false, false)
.unwrap();

for kp in &keypairs {
Expand All @@ -1222,7 +1250,7 @@ mod tests {
let rent = client.get_minimum_balance_for_rent_exemption(0).unwrap();

let keypairs =
generate_and_fund_keypairs(client.clone(), &id, keypair_count, lamports, false)
generate_and_fund_keypairs(client.clone(), &id, keypair_count, lamports, false, false)
.unwrap();

for kp in &keypairs {
Expand All @@ -1239,7 +1267,7 @@ mod tests {
let lamports = 10_000_000;

let authority_keypairs =
generate_and_fund_keypairs(client.clone(), &id, keypair_count, lamports, false)
generate_and_fund_keypairs(client.clone(), &id, keypair_count, lamports, false, false)
.unwrap();

let nonce_keypairs = generate_durable_nonce_accounts(client.clone(), &authority_keypairs);
Expand Down
13 changes: 13 additions & 0 deletions bench-tps/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub struct Config {
pub use_quic: bool,
pub tpu_connection_pool_size: usize,
pub compute_unit_price: Option<ComputeUnitPrice>,
pub skip_tx_account_data_size: bool,
pub use_durable_nonce: bool,
pub instruction_padding_config: Option<InstructionPaddingConfig>,
pub num_conflict_groups: Option<usize>,
Expand Down Expand Up @@ -101,6 +102,7 @@ impl Default for Config {
use_quic: DEFAULT_TPU_USE_QUIC,
tpu_connection_pool_size: DEFAULT_TPU_CONNECTION_POOL_SIZE,
compute_unit_price: None,
skip_tx_account_data_size: false,
use_durable_nonce: false,
instruction_padding_config: None,
num_conflict_groups: None,
Expand Down Expand Up @@ -358,6 +360,13 @@ pub fn build_args<'a>(version: &'_ str) -> App<'a, '_> {
.conflicts_with("compute_unit_price")
.help("Sets random compute-unit-price in range [0..100] to transfer transactions"),
)
.arg(
Arg::with_name("skip_tx_account_data_size")
.long("skip-tx-account-data-size")
.takes_value(false)
.conflicts_with("instruction_padding_data_size")
.help("Skips setting the account data size for each transaction"),
)
.arg(
Arg::with_name("use_durable_nonce")
.long("use-durable-nonce")
Expand Down Expand Up @@ -537,6 +546,10 @@ pub fn parse_args(matches: &ArgMatches) -> Result<Config, &'static str> {
args.compute_unit_price = Some(ComputeUnitPrice::Random);
}

if matches.is_present("skip_tx_account_data_size") {
args.skip_tx_account_data_size = true;
}

if matches.is_present("use_durable_nonce") {
args.use_durable_nonce = true;
}
Expand Down
3 changes: 3 additions & 0 deletions bench-tps/src/keypairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub fn get_keypairs<T>(
num_lamports_per_account: u64,
client_ids_and_stake_file: &str,
read_from_client_file: bool,
skip_tx_account_data_size: bool,
enable_padding: bool,
) -> Vec<Keypair>
where
Expand Down Expand Up @@ -57,6 +58,7 @@ where
&keypairs,
keypairs.len().saturating_sub(keypair_count) as u64,
last_balance,
skip_tx_account_data_size,
enable_padding,
)
.unwrap_or_else(|e| {
Expand All @@ -70,6 +72,7 @@ where
id,
keypair_count,
num_lamports_per_account,
skip_tx_account_data_size,
enable_padding,
)
.unwrap_or_else(|e| {
Expand Down
2 changes: 2 additions & 0 deletions bench-tps/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ fn main() {
external_client_type,
use_quic,
tpu_connection_pool_size,
skip_tx_account_data_size,
compute_unit_price,
use_durable_nonce,
instruction_padding_config,
Expand Down Expand Up @@ -267,6 +268,7 @@ fn main() {
*num_lamports_per_account,
client_ids_and_stake_file,
*read_from_client_file,
*skip_tx_account_data_size,
instruction_padding_config.is_some(),
);

Expand Down
8 changes: 5 additions & 3 deletions bench-tps/src/send_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,11 @@ impl<'a> FundingTransactions<'a> for FundingContainer<'a> {
) {
self.make(to_fund, |(k, t)| -> (FundingSigners<'a>, Transaction) {
let mut instructions = system_instruction::transfer_many(&k.pubkey(), t);
instructions.push(
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(data_size_limit),
);
if data_size_limit != 0 {
instructions.push(
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(data_size_limit),
);
}
let message = Message::new(&instructions, Some(&k.pubkey()));
(*k, Transaction::new_unsigned(message))
});
Expand Down
2 changes: 2 additions & 0 deletions bench-tps/tests/bench_tps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ fn test_bench_tps_local_cluster(config: Config) {
keypair_count,
lamports_per_account,
false,
false,
)
.unwrap();

Expand Down Expand Up @@ -152,6 +153,7 @@ fn test_bench_tps_test_validator(config: Config) {
keypair_count,
lamports_per_account,
false,
false,
)
.unwrap();
let nonce_keypairs = if config.use_durable_nonce {
Expand Down
1 change: 1 addition & 0 deletions dos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ fn create_payers<T: 'static + BenchTpsClient + Send + Sync>(
size,
1_000_000,
false,
false,
)
.unwrap_or_else(|e| {
eprintln!("Error could not fund keys: {e:?}");
Expand Down

0 comments on commit 32a51ad

Please sign in to comment.