Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 6e29c80

Browse files
anwaydewillhickey
authored andcommitted
bench-tps: allow option to not set account data size on every transaction (#209)
bench-tps: allow option to not set account data size
1 parent 8714210 commit 6e29c80

File tree

7 files changed

+72
-23
lines changed

7 files changed

+72
-23
lines changed

bench-tps/src/bench.rs

+43-17
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ struct TransactionChunkGenerator<'a, 'b, T: ?Sized> {
139139
reclaim_lamports_back_to_source_account: bool,
140140
compute_unit_price: Option<ComputeUnitPrice>,
141141
instruction_padding_config: Option<InstructionPaddingConfig>,
142+
skip_tx_account_data_size: bool,
142143
}
143144

144145
impl<'a, 'b, T> TransactionChunkGenerator<'a, 'b, T>
@@ -153,6 +154,7 @@ where
153154
compute_unit_price: Option<ComputeUnitPrice>,
154155
instruction_padding_config: Option<InstructionPaddingConfig>,
155156
num_conflict_groups: Option<usize>,
157+
skip_tx_account_data_size: bool,
156158
) -> Self {
157159
let account_chunks = if let Some(num_conflict_groups) = num_conflict_groups {
158160
KeypairChunks::new_with_conflict_groups(gen_keypairs, chunk_size, num_conflict_groups)
@@ -170,6 +172,7 @@ where
170172
reclaim_lamports_back_to_source_account: false,
171173
compute_unit_price,
172174
instruction_padding_config,
175+
skip_tx_account_data_size,
173176
}
174177
}
175178

@@ -195,6 +198,7 @@ where
195198
source_nonce_chunk,
196199
dest_nonce_chunk,
197200
self.reclaim_lamports_back_to_source_account,
201+
self.skip_tx_account_data_size,
198202
&self.instruction_padding_config,
199203
)
200204
} else {
@@ -206,6 +210,7 @@ where
206210
blockhash.unwrap(),
207211
&self.instruction_padding_config,
208212
&self.compute_unit_price,
213+
self.skip_tx_account_data_size,
209214
)
210215
};
211216

@@ -397,6 +402,7 @@ where
397402
sustained,
398403
target_slots_per_epoch,
399404
compute_unit_price,
405+
skip_tx_account_data_size,
400406
use_durable_nonce,
401407
instruction_padding_config,
402408
num_conflict_groups,
@@ -412,6 +418,7 @@ where
412418
compute_unit_price,
413419
instruction_padding_config,
414420
num_conflict_groups,
421+
skip_tx_account_data_size,
415422
);
416423

417424
let first_tx_count = loop {
@@ -538,6 +545,7 @@ fn generate_system_txs(
538545
blockhash: &Hash,
539546
instruction_padding_config: &Option<InstructionPaddingConfig>,
540547
compute_unit_price: &Option<ComputeUnitPrice>,
548+
skip_tx_account_data_size: bool,
541549
) -> Vec<TimestampedTransaction> {
542550
let pairs: Vec<_> = if !reclaim {
543551
source.iter().zip(dest.iter()).collect()
@@ -575,6 +583,7 @@ fn generate_system_txs(
575583
*blockhash,
576584
instruction_padding_config,
577585
Some(**compute_unit_price),
586+
skip_tx_account_data_size,
578587
),
579588
Some(timestamp()),
580589
)
@@ -592,6 +601,7 @@ fn generate_system_txs(
592601
*blockhash,
593602
instruction_padding_config,
594603
None,
604+
skip_tx_account_data_size,
595605
),
596606
Some(timestamp()),
597607
)
@@ -607,6 +617,7 @@ fn transfer_with_compute_unit_price_and_padding(
607617
recent_blockhash: Hash,
608618
instruction_padding_config: &Option<InstructionPaddingConfig>,
609619
compute_unit_price: Option<u64>,
620+
skip_tx_account_data_size: bool,
610621
) -> Transaction {
611622
let from_pubkey = from_keypair.pubkey();
612623
let transfer_instruction = system_instruction::transfer(&from_pubkey, to, lamports);
@@ -621,12 +632,15 @@ fn transfer_with_compute_unit_price_and_padding(
621632
} else {
622633
transfer_instruction
623634
};
624-
let mut instructions = vec![
625-
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(
626-
get_transaction_loaded_accounts_data_size(instruction_padding_config.is_some()),
627-
),
628-
instruction,
629-
];
635+
let mut instructions = vec![];
636+
if !skip_tx_account_data_size {
637+
instructions.push(
638+
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(
639+
get_transaction_loaded_accounts_data_size(instruction_padding_config.is_some()),
640+
),
641+
)
642+
}
643+
instructions.push(instruction);
630644
if instruction_padding_config.is_some() {
631645
// By default, CU budget is DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT which is much larger than needed
632646
instructions.push(ComputeBudgetInstruction::set_compute_unit_limit(
@@ -711,6 +725,7 @@ fn nonced_transfer_with_padding(
711725
nonce_account: &Pubkey,
712726
nonce_authority: &Keypair,
713727
nonce_hash: Hash,
728+
skip_tx_account_data_size: bool,
714729
instruction_padding_config: &Option<InstructionPaddingConfig>,
715730
) -> Transaction {
716731
let from_pubkey = from_keypair.pubkey();
@@ -726,12 +741,15 @@ fn nonced_transfer_with_padding(
726741
} else {
727742
transfer_instruction
728743
};
729-
let instructions = vec![
730-
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(
731-
get_transaction_loaded_accounts_data_size(instruction_padding_config.is_some()),
732-
),
733-
instruction,
734-
];
744+
let mut instructions = vec![];
745+
if !skip_tx_account_data_size {
746+
instructions.push(
747+
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(
748+
get_transaction_loaded_accounts_data_size(instruction_padding_config.is_some()),
749+
),
750+
)
751+
}
752+
instructions.push(instruction);
735753
let message = Message::new_with_nonce(
736754
instructions,
737755
Some(&from_pubkey),
@@ -748,6 +766,7 @@ fn generate_nonced_system_txs<T: 'static + BenchTpsClient + Send + Sync + ?Sized
748766
source_nonce: &[&Keypair],
749767
dest_nonce: &VecDeque<&Keypair>,
750768
reclaim: bool,
769+
skip_tx_account_data_size: bool,
751770
instruction_padding_config: &Option<InstructionPaddingConfig>,
752771
) -> Vec<TimestampedTransaction> {
753772
let length = source.len();
@@ -768,6 +787,7 @@ fn generate_nonced_system_txs<T: 'static + BenchTpsClient + Send + Sync + ?Sized
768787
&source_nonce[i].pubkey(),
769788
source[i],
770789
blockhashes[i],
790+
skip_tx_account_data_size,
771791
instruction_padding_config,
772792
),
773793
None,
@@ -786,6 +806,7 @@ fn generate_nonced_system_txs<T: 'static + BenchTpsClient + Send + Sync + ?Sized
786806
&dest_nonce[i].pubkey(),
787807
dest[i],
788808
blockhashes[i],
809+
skip_tx_account_data_size,
789810
instruction_padding_config,
790811
),
791812
None,
@@ -1046,6 +1067,7 @@ pub fn generate_and_fund_keypairs<T: 'static + BenchTpsClient + Send + Sync + ?S
10461067
funding_key: &Keypair,
10471068
keypair_count: usize,
10481069
lamports_per_account: u64,
1070+
skip_tx_account_data_size: bool,
10491071
enable_padding: bool,
10501072
) -> Result<Vec<Keypair>> {
10511073
let rent = client.get_minimum_balance_for_rent_exemption(0)?;
@@ -1059,6 +1081,7 @@ pub fn generate_and_fund_keypairs<T: 'static + BenchTpsClient + Send + Sync + ?S
10591081
&keypairs,
10601082
extra,
10611083
lamports_per_account,
1084+
skip_tx_account_data_size,
10621085
enable_padding,
10631086
)?;
10641087

@@ -1074,6 +1097,7 @@ pub fn fund_keypairs<T: 'static + BenchTpsClient + Send + Sync + ?Sized>(
10741097
keypairs: &[Keypair],
10751098
extra: u64,
10761099
lamports_per_account: u64,
1100+
skip_tx_account_data_size: bool,
10771101
enable_padding: bool,
10781102
) -> Result<()> {
10791103
let rent = client.get_minimum_balance_for_rent_exemption(0)?;
@@ -1131,6 +1155,8 @@ pub fn fund_keypairs<T: 'static + BenchTpsClient + Send + Sync + ?Sized>(
11311155
return Err(BenchTpsError::AirdropFailure);
11321156
}
11331157
}
1158+
let data_size_limit = (!skip_tx_account_data_size)
1159+
.then(|| get_transaction_loaded_accounts_data_size(enable_padding));
11341160

11351161
fund_keys(
11361162
client,
@@ -1139,7 +1165,7 @@ pub fn fund_keypairs<T: 'static + BenchTpsClient + Send + Sync + ?Sized>(
11391165
total,
11401166
max_fee,
11411167
lamports_per_account,
1142-
get_transaction_loaded_accounts_data_size(enable_padding),
1168+
data_size_limit,
11431169
);
11441170
}
11451171
Ok(())
@@ -1181,7 +1207,7 @@ mod tests {
11811207

11821208
let keypair_count = config.tx_count * config.keypair_multiplier;
11831209
let keypairs =
1184-
generate_and_fund_keypairs(client.clone(), &config.id, keypair_count, 20, false)
1210+
generate_and_fund_keypairs(client.clone(), &config.id, keypair_count, 20, false, false)
11851211
.unwrap();
11861212

11871213
do_bench_tps(client, config, keypairs, None);
@@ -1197,7 +1223,7 @@ mod tests {
11971223
let rent = client.get_minimum_balance_for_rent_exemption(0).unwrap();
11981224

11991225
let keypairs =
1200-
generate_and_fund_keypairs(client.clone(), &id, keypair_count, lamports, false)
1226+
generate_and_fund_keypairs(client.clone(), &id, keypair_count, lamports, false, false)
12011227
.unwrap();
12021228

12031229
for kp in &keypairs {
@@ -1222,7 +1248,7 @@ mod tests {
12221248
let rent = client.get_minimum_balance_for_rent_exemption(0).unwrap();
12231249

12241250
let keypairs =
1225-
generate_and_fund_keypairs(client.clone(), &id, keypair_count, lamports, false)
1251+
generate_and_fund_keypairs(client.clone(), &id, keypair_count, lamports, false, false)
12261252
.unwrap();
12271253

12281254
for kp in &keypairs {
@@ -1239,7 +1265,7 @@ mod tests {
12391265
let lamports = 10_000_000;
12401266

12411267
let authority_keypairs =
1242-
generate_and_fund_keypairs(client.clone(), &id, keypair_count, lamports, false)
1268+
generate_and_fund_keypairs(client.clone(), &id, keypair_count, lamports, false, false)
12431269
.unwrap();
12441270

12451271
let nonce_keypairs = generate_durable_nonce_accounts(client.clone(), &authority_keypairs);

bench-tps/src/cli.rs

+13
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub struct Config {
6969
pub use_quic: bool,
7070
pub tpu_connection_pool_size: usize,
7171
pub compute_unit_price: Option<ComputeUnitPrice>,
72+
pub skip_tx_account_data_size: bool,
7273
pub use_durable_nonce: bool,
7374
pub instruction_padding_config: Option<InstructionPaddingConfig>,
7475
pub num_conflict_groups: Option<usize>,
@@ -101,6 +102,7 @@ impl Default for Config {
101102
use_quic: DEFAULT_TPU_USE_QUIC,
102103
tpu_connection_pool_size: DEFAULT_TPU_CONNECTION_POOL_SIZE,
103104
compute_unit_price: None,
105+
skip_tx_account_data_size: false,
104106
use_durable_nonce: false,
105107
instruction_padding_config: None,
106108
num_conflict_groups: None,
@@ -358,6 +360,13 @@ pub fn build_args<'a>(version: &'_ str) -> App<'a, '_> {
358360
.conflicts_with("compute_unit_price")
359361
.help("Sets random compute-unit-price in range [0..100] to transfer transactions"),
360362
)
363+
.arg(
364+
Arg::with_name("skip_tx_account_data_size")
365+
.long("skip-tx-account-data-size")
366+
.takes_value(false)
367+
.conflicts_with("instruction_padding_data_size")
368+
.help("Skips setting the account data size for each transaction"),
369+
)
361370
.arg(
362371
Arg::with_name("use_durable_nonce")
363372
.long("use-durable-nonce")
@@ -537,6 +546,10 @@ pub fn parse_args(matches: &ArgMatches) -> Result<Config, &'static str> {
537546
args.compute_unit_price = Some(ComputeUnitPrice::Random);
538547
}
539548

549+
if matches.is_present("skip_tx_account_data_size") {
550+
args.skip_tx_account_data_size = true;
551+
}
552+
540553
if matches.is_present("use_durable_nonce") {
541554
args.use_durable_nonce = true;
542555
}

bench-tps/src/keypairs.rs

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub fn get_keypairs<T>(
1616
num_lamports_per_account: u64,
1717
client_ids_and_stake_file: &str,
1818
read_from_client_file: bool,
19+
skip_tx_account_data_size: bool,
1920
enable_padding: bool,
2021
) -> Vec<Keypair>
2122
where
@@ -57,6 +58,7 @@ where
5758
&keypairs,
5859
keypairs.len().saturating_sub(keypair_count) as u64,
5960
last_balance,
61+
skip_tx_account_data_size,
6062
enable_padding,
6163
)
6264
.unwrap_or_else(|e| {
@@ -70,6 +72,7 @@ where
7072
id,
7173
keypair_count,
7274
num_lamports_per_account,
75+
skip_tx_account_data_size,
7376
enable_padding,
7477
)
7578
.unwrap_or_else(|e| {

bench-tps/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ fn main() {
194194
external_client_type,
195195
use_quic,
196196
tpu_connection_pool_size,
197+
skip_tx_account_data_size,
197198
compute_unit_price,
198199
use_durable_nonce,
199200
instruction_padding_config,
@@ -267,6 +268,7 @@ fn main() {
267268
*num_lamports_per_account,
268269
client_ids_and_stake_file,
269270
*read_from_client_file,
271+
*skip_tx_account_data_size,
270272
instruction_padding_config.is_some(),
271273
);
272274

bench-tps/src/send_batch.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn fund_keys<T: 'static + BenchTpsClient + Send + Sync + ?Sized>(
6666
total: u64,
6767
max_fee: u64,
6868
lamports_per_account: u64,
69-
data_size_limit: u32,
69+
data_size_limit: Option<u32>,
7070
) {
7171
let mut funded: Vec<&Keypair> = vec![source];
7272
let mut funded_funds = total;
@@ -354,7 +354,7 @@ trait FundingTransactions<'a>: SendBatchTransactions<'a, FundingSigners<'a>> {
354354
client: &Arc<T>,
355355
to_fund: &FundingChunk<'a>,
356356
to_lamports: u64,
357-
data_size_limit: u32,
357+
data_size_limit: Option<u32>,
358358
);
359359
}
360360

@@ -364,13 +364,15 @@ impl<'a> FundingTransactions<'a> for FundingContainer<'a> {
364364
client: &Arc<T>,
365365
to_fund: &FundingChunk<'a>,
366366
to_lamports: u64,
367-
data_size_limit: u32,
367+
data_size_limit: Option<u32>,
368368
) {
369369
self.make(to_fund, |(k, t)| -> (FundingSigners<'a>, Transaction) {
370370
let mut instructions = system_instruction::transfer_many(&k.pubkey(), t);
371-
instructions.push(
372-
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(data_size_limit),
373-
);
371+
if let Some(data_size_limit) = data_size_limit {
372+
instructions.push(
373+
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(data_size_limit),
374+
);
375+
}
374376
let message = Message::new(&instructions, Some(&k.pubkey()));
375377
(*k, Transaction::new_unsigned(message))
376378
});

bench-tps/tests/bench_tps.rs

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ fn test_bench_tps_local_cluster(config: Config) {
106106
keypair_count,
107107
lamports_per_account,
108108
false,
109+
false,
109110
)
110111
.unwrap();
111112

@@ -152,6 +153,7 @@ fn test_bench_tps_test_validator(config: Config) {
152153
keypair_count,
153154
lamports_per_account,
154155
false,
156+
false,
155157
)
156158
.unwrap();
157159
let nonce_keypairs = if config.use_durable_nonce {

dos/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ fn create_payers<T: 'static + BenchTpsClient + Send + Sync>(
560560
size,
561561
1_000_000,
562562
false,
563+
false,
563564
)
564565
.unwrap_or_else(|e| {
565566
eprintln!("Error could not fund keys: {e:?}");

0 commit comments

Comments
 (0)