From b275a7408c5c4481d195264ad5d422fe71f6887b Mon Sep 17 00:00:00 2001 From: Anway De Date: Tue, 12 Mar 2024 14:45:48 +0000 Subject: [PATCH] bench-tps: allow option to not set account data size --- bench-tps/src/bench.rs | 62 ++++++++++++++++++++++++++---------- bench-tps/src/cli.rs | 13 ++++++++ bench-tps/src/keypairs.rs | 3 ++ bench-tps/src/main.rs | 2 ++ bench-tps/src/send_batch.rs | 8 +++-- bench-tps/tests/bench_tps.rs | 2 ++ dos/src/main.rs | 1 + 7 files changed, 71 insertions(+), 20 deletions(-) diff --git a/bench-tps/src/bench.rs b/bench-tps/src/bench.rs index bddce402ac6382..41ec1b6e8b3eef 100644 --- a/bench-tps/src/bench.rs +++ b/bench-tps/src/bench.rs @@ -139,6 +139,7 @@ struct TransactionChunkGenerator<'a, 'b, T: ?Sized> { reclaim_lamports_back_to_source_account: bool, compute_unit_price: Option, instruction_padding_config: Option, + skip_tx_account_data_size: bool, } impl<'a, 'b, T> TransactionChunkGenerator<'a, 'b, T> @@ -153,6 +154,7 @@ where compute_unit_price: Option, instruction_padding_config: Option, num_conflict_groups: Option, + 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) @@ -170,6 +172,7 @@ where reclaim_lamports_back_to_source_account: false, compute_unit_price, instruction_padding_config, + skip_tx_account_data_size, } } @@ -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 { @@ -206,6 +210,7 @@ where blockhash.unwrap(), &self.instruction_padding_config, &self.compute_unit_price, + self.skip_tx_account_data_size, ) }; @@ -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, @@ -412,6 +418,7 @@ where compute_unit_price, instruction_padding_config, num_conflict_groups, + skip_tx_account_data_size, ); let first_tx_count = loop { @@ -538,6 +545,7 @@ fn generate_system_txs( blockhash: &Hash, instruction_padding_config: &Option, compute_unit_price: &Option, + skip_tx_account_data_size: bool, ) -> Vec { let pairs: Vec<_> = if !reclaim { source.iter().zip(dest.iter()).collect() @@ -575,6 +583,7 @@ fn generate_system_txs( *blockhash, instruction_padding_config, Some(**compute_unit_price), + skip_tx_account_data_size, ), Some(timestamp()), ) @@ -592,6 +601,7 @@ fn generate_system_txs( *blockhash, instruction_padding_config, None, + skip_tx_account_data_size, ), Some(timestamp()), ) @@ -607,6 +617,7 @@ fn transfer_with_compute_unit_price_and_padding( recent_blockhash: Hash, instruction_padding_config: &Option, compute_unit_price: Option, + skip_tx_account_data_size: bool, ) -> Transaction { let from_pubkey = from_keypair.pubkey(); let transfer_instruction = system_instruction::transfer(&from_pubkey, to, lamports); @@ -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( - get_transaction_loaded_accounts_data_size(instruction_padding_config.is_some()), - ), - instruction, - ]; + 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()), + ), + ) + } + 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( @@ -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, ) -> Transaction { let from_pubkey = from_keypair.pubkey(); @@ -726,12 +741,15 @@ fn nonced_transfer_with_padding( } else { transfer_instruction }; - let instructions = vec![ - ComputeBudgetInstruction::set_loaded_accounts_data_size_limit( - get_transaction_loaded_accounts_data_size(instruction_padding_config.is_some()), - ), - instruction, - ]; + 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()), + ), + ) + } + instructions.push(instruction); let message = Message::new_with_nonce( instructions, Some(&from_pubkey), @@ -748,6 +766,7 @@ fn generate_nonced_system_txs, reclaim: bool, + skip_tx_account_data_size: bool, instruction_padding_config: &Option, ) -> Vec { let length = source.len(); @@ -768,6 +787,7 @@ fn generate_nonced_system_txs Result> { let rent = client.get_minimum_balance_for_rent_exemption(0)?; @@ -1059,6 +1081,7 @@ pub fn generate_and_fund_keypairs( 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)?; @@ -1131,6 +1155,10 @@ pub fn fund_keypairs( 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, @@ -1139,7 +1167,7 @@ pub fn fund_keypairs( total, max_fee, lamports_per_account, - get_transaction_loaded_accounts_data_size(enable_padding), + data_size_limit, ); } Ok(()) @@ -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); @@ -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 { @@ -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 { @@ -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); diff --git a/bench-tps/src/cli.rs b/bench-tps/src/cli.rs index e2ee75fc551400..1804dbbc454e02 100644 --- a/bench-tps/src/cli.rs +++ b/bench-tps/src/cli.rs @@ -69,6 +69,7 @@ pub struct Config { pub use_quic: bool, pub tpu_connection_pool_size: usize, pub compute_unit_price: Option, + pub skip_tx_account_data_size: bool, pub use_durable_nonce: bool, pub instruction_padding_config: Option, pub num_conflict_groups: Option, @@ -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, @@ -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") @@ -537,6 +546,10 @@ pub fn parse_args(matches: &ArgMatches) -> Result { 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; } diff --git a/bench-tps/src/keypairs.rs b/bench-tps/src/keypairs.rs index d5f839190bd638..177e15bf5fca5f 100644 --- a/bench-tps/src/keypairs.rs +++ b/bench-tps/src/keypairs.rs @@ -16,6 +16,7 @@ pub fn get_keypairs( 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 where @@ -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| { @@ -70,6 +72,7 @@ where id, keypair_count, num_lamports_per_account, + skip_tx_account_data_size, enable_padding, ) .unwrap_or_else(|e| { diff --git a/bench-tps/src/main.rs b/bench-tps/src/main.rs index 1560b9346ed28c..fa0fc1509055e4 100644 --- a/bench-tps/src/main.rs +++ b/bench-tps/src/main.rs @@ -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, @@ -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(), ); diff --git a/bench-tps/src/send_batch.rs b/bench-tps/src/send_batch.rs index 75079c72ab020a..80ce53a216679c 100644 --- a/bench-tps/src/send_batch.rs +++ b/bench-tps/src/send_batch.rs @@ -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)) }); diff --git a/bench-tps/tests/bench_tps.rs b/bench-tps/tests/bench_tps.rs index 2efdd6c8ff6ef4..7a2b0fe20a5b8d 100644 --- a/bench-tps/tests/bench_tps.rs +++ b/bench-tps/tests/bench_tps.rs @@ -106,6 +106,7 @@ fn test_bench_tps_local_cluster(config: Config) { keypair_count, lamports_per_account, false, + false, ) .unwrap(); @@ -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 { diff --git a/dos/src/main.rs b/dos/src/main.rs index 055b1f4bb65d4c..577e4a2d067393 100644 --- a/dos/src/main.rs +++ b/dos/src/main.rs @@ -560,6 +560,7 @@ fn create_payers( size, 1_000_000, false, + false, ) .unwrap_or_else(|e| { eprintln!("Error could not fund keys: {e:?}");