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

Commit f0725b4

Browse files
mvinessolana-grimes
authored andcommitted
Avoid panicking if poll_get_balance() fails while in the transaction loop
1 parent 327ba53 commit f0725b4

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/bin/bench-tps.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ fn main() {
297297
let mut client = mk_client(&leader);
298298

299299
let starting_balance = client.poll_get_balance(&id.pubkey()).unwrap();
300-
println!("Token balance: {:?}", starting_balance);
300+
println!("Token balance: {}", starting_balance);
301301
let txs: i64 = 500_000;
302302

303303
if starting_balance < txs {
@@ -321,7 +321,7 @@ fn main() {
321321
}
322322
println!(".");
323323
}
324-
println!("Token balance: {:?}", current_balance);
324+
println!("Token balance: {}", current_balance);
325325
if current_balance - starting_balance != airdrop_amount {
326326
println!("Airdrop failed!");
327327
exit(1);
@@ -336,7 +336,7 @@ fn main() {
336336
seed.copy_from_slice(&id.public_key_bytes()[..32]);
337337
let rnd = GenKeys::new(seed);
338338

339-
println!("Creating keypairs...");
339+
println!("Creating {} keypairs...", txs / 2);
340340
let keypairs = rnd.gen_n_keypairs(txs / 2);
341341

342342
let first_tx_count = client.transaction_count();
@@ -368,8 +368,8 @@ fn main() {
368368
let now = Instant::now();
369369
let mut reclaim_tokens_back_to_source_account = false;
370370
while now.elapsed() < time || reclaim_tokens_back_to_source_account {
371-
let balance = client.poll_get_balance(&id.pubkey()).unwrap();
372-
println!("Token balance: {:?}", balance);
371+
let balance = client.poll_get_balance(&id.pubkey()).unwrap_or(-1);
372+
println!("Token balance: {}", balance);
373373

374374
// ping-pong between source and destination accounts for each loop iteration
375375
// this seems to be faster than trying to determine the balance of individual
@@ -394,8 +394,8 @@ fn main() {
394394
t.join().unwrap();
395395
}
396396

397-
let balance = client.poll_get_balance(&id.pubkey()).unwrap();
398-
println!("Token balance: {:?}", balance);
397+
let balance = client.poll_get_balance(&id.pubkey()).unwrap_or(-1);
398+
println!("Token balance: {}", balance);
399399

400400
// Compute/report stats
401401
let mut max_of_maxes = 0.0;

0 commit comments

Comments
 (0)