Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve script tx batch size logic #7583

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions crates/script/src/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,33 +319,29 @@ impl BundledState {

let pb = init_progress!(transactions, "txes");

// We send transactions and wait for receipts in batches of 100, since some networks
// cannot handle more than that.
let valid_batch_size = self.args.batch_size.min(100);
let batch_size = if sequential_broadcast { 1 } else { valid_batch_size };
// We send transactions and wait for receipts in batches.
let batch_size = if sequential_broadcast { 1 } else { self.args.batch_size };
let mut index = already_broadcasted;

for (batch_number, batch) in
transactions.chunks(batch_size).map(|f| f.to_vec()).enumerate()
{
for (batch_number, batch) in transactions.chunks(batch_size).enumerate() {
let mut pending_transactions = vec![];

shell::println(format!(
"##\nSending transactions [{} - {}].",
batch_number * batch_size,
batch_number * batch_size + std::cmp::min(batch_size, batch.len()) - 1
))?;
for (tx, kind, is_fixed_gas_limit) in batch.into_iter() {
let tx_hash = send_transaction(
for (tx, kind, is_fixed_gas_limit) in batch {
let fut = send_transaction(
provider.clone(),
tx,
kind,
tx.clone(),
kind.clone(),
sequential_broadcast,
is_fixed_gas_limit,
*is_fixed_gas_limit,
estimate_via_rpc,
self.args.gas_estimate_multiplier,
);
pending_transactions.push(tx_hash);
pending_transactions.push(fut);
}

if !pending_transactions.is_empty() {
Expand Down
2 changes: 2 additions & 0 deletions crates/script/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ pub struct ScriptArgs {
pub broadcast: bool,

/// Batch size of transactions.
///
/// This is ignored and set to 1 if batching is not available or `--slow` is enabled.
#[arg(long, default_value = "100")]
pub batch_size: usize,

Expand Down
Loading