Repository: MystenLabs/sui
File: crates/sui-benchmark/src/drivers/bench_driver.rs (Rust)

Code before:
                                        (start_idx, digests, result)
                                    }
                                })
                                .collect();

                            let bundle_results = futures::future::join_all(bundle_futures).await;
                            let latency = start.elapsed();

                            process_bundle_results(num_txs, payload, latency, &metrics_clone, bundle_results)
                        };
                        futures.push(Box::pin(res));
                    } else {
                        let tx = payload.make_transaction();
                        let start = Arc::new(Instant::now());
                        let metrics = Arc::clone(&metrics);
                        let num_in_flight_metric = metrics.num_in_flight.with_label_values(&[&payload.to_string()]);
                        // TODO: clone committee for each request is not ideal.
                        let committee = worker.execution_proxy.clone_committee();

                        // Occasionally submit to multiple validators to test unpaid amplification deferral.
                        // With 5% probability, submit to 3 validators to trigger the deferral logic.
                        let use_amplification = rand::thread_rng().gen_bool(0.05);
                        let proxy = worker.execution_proxy.clone_new();
                        let res = async move {
                            let (client_type, res) = if use_amplification {
                                proxy.execute_transaction_block_with_amplification(tx.clone(), 3).await
                            } else {
                                proxy.execute_transaction_block(tx.clone()).await
                            };
                            metrics.num_submitted.with_label_values(&[&payload.to_string(), &client_type.to_string()]).inc();
                            handle_execute_transaction_response(res, start, tx, payload, committee, client_type)
                        }.count_in_flight(num_in_flight_metric);
                        futures.push(Box::pin(res));
                    }
                }
            }
            Some(op) = futures.next() => {
                match op {
                    NextOp::Retry(b) => {
                        retry_queue.push_back(b);

                        // Update total benchmark progress
                        if update_progress(1) {
                            break;
                        }
                    }
                    NextOp::Failure { payload } => {
                        num_error_txes += 1;
                        num_in_flight -= 1;
                        free_pool.push_back(payload);
                        // Update total benchmark progress

Review comment (suggestion):
Shall we make also the number of submissions also random? Something in the range `3...committee_size - 1`? In the spirit that we might increase the chances of testing long deferrals (across multiple commits)

Code after:
                                        (start_idx, digests, result)
                                    }
                                })
                                .collect();

                            let bundle_results = futures::future::join_all(bundle_futures).await;
                            let latency = start.elapsed();

                            process_bundle_results(num_txs, payload, latency, &metrics_clone, bundle_results)
                        };
                        futures.push(Box::pin(res));
                    } else {
                        let tx = payload.make_transaction();
                        let start = Arc::new(Instant::now());
                        let metrics = Arc::clone(&metrics);
                        let num_in_flight_metric = metrics.num_in_flight.with_label_values(&[&payload.to_string()]);
                        // TODO: clone committee for each request is not ideal.
                        let committee = worker.execution_proxy.clone_committee();

                        // Occasionally submit to multiple validators to test unpaid amplification deferral.
                        // With 5% probability, submit to a random number of validators (3 to committee_size - 1)
                        // to trigger the deferral logic. Randomizing increases chances of testing longer deferrals.
                        let use_amplification = rand::thread_rng().gen_bool(0.05);
                        let committee_size = committee.num_members();
                        let proxy = worker.execution_proxy.clone_new();
                        let res = async move {
                            let (client_type, res) = if use_amplification {
                                let num_validators = rand::thread_rng().gen_range(3..committee_size.max(4));
                                proxy.execute_transaction_block_with_amplification(tx.clone(), num_validators).await
                            } else {
                                proxy.execute_transaction_block(tx.clone()).await
                            };
                            metrics.num_submitted.with_label_values(&[&payload.to_string(), &client_type.to_string()]).inc();
                            handle_execute_transaction_response(res, start, tx, payload, committee, client_type)
                        }.count_in_flight(num_in_flight_metric);
                        futures.push(Box::pin(res));
                    }
                }
            }
            Some(op) = futures.next() => {
                match op {
                    NextOp::Retry(b) => {
                        retry_queue.push_back(b);

                        // Update total benchmark progress
                        if update_progress(1) {
                            break;
                        }
                    }
                    NextOp::Failure { payload } => {
                        num_error_txes += 1;