From 9930284182858d34bc6ee4f62b3918a219dc9d63 Mon Sep 17 00:00:00 2001 From: zeroXbrock <2791467+zeroXbrock@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:14:18 -0800 Subject: [PATCH] remove timeout, add env var to fill blocks up to a percent --- crates/cli/src/default_scenarios/runconfig.rs | 17 +++++++++++++++-- crates/cli/src/main.rs | 6 ++++++ crates/core/src/spammer/spammer_trait.rs | 10 +++------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/crates/cli/src/default_scenarios/runconfig.rs b/crates/cli/src/default_scenarios/runconfig.rs index 476d328..d5218e1 100644 --- a/crates/cli/src/default_scenarios/runconfig.rs +++ b/crates/cli/src/default_scenarios/runconfig.rs @@ -15,15 +15,22 @@ pub enum BuiltinScenarioConfig { max_gas_per_block: u128, num_txs: u64, sender: Address, + fill_percent: u16, }, } impl BuiltinScenarioConfig { - pub fn fill_block(max_gas_per_block: u128, num_txs: u64, sender: Address) -> Self { + pub fn fill_block( + max_gas_per_block: u128, + num_txs: u64, + sender: Address, + fill_percent: u16, + ) -> Self { Self::FillBlock { max_gas_per_block, num_txs, sender, + fill_percent, } } } @@ -35,8 +42,14 @@ impl From for TestConfig { max_gas_per_block, num_txs, sender, + fill_percent, } => { - let gas_per_tx = max_gas_per_block / num_txs as u128; + let gas_per_tx = + ((max_gas_per_block / num_txs as u128) / 100) * fill_percent as u128; + println!( + "Filling blocks to {}% with {} gas per tx", + fill_percent, gas_per_tx + ); let spam_txs = (0..num_txs) .map(|_| { SpamRequest::Tx(FunctionCallDefinition { diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index b6c5c1e..8b374dc 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -2,6 +2,7 @@ mod commands; mod default_scenarios; use std::{ + env, io::Write, str::FromStr, sync::{Arc, LazyLock}, @@ -286,11 +287,16 @@ async fn main() -> Result<(), Box> { None, ))?; + let fill_percent = env::var("C_FILL_PERCENT") + .map(|s| u16::from_str(&s).expect("invalid u16: fill_percent")) + .unwrap_or(100u16); + let scenario_config = match scenario { BuiltinScenario::FillBlock => BuiltinScenarioConfig::fill_block( block_gas_limit, txs_per_duration as u64, admin_signer.address(), + fill_percent, ), }; let testconfig: TestConfig = scenario_config.into(); diff --git a/crates/core/src/spammer/spammer_trait.rs b/crates/core/src/spammer/spammer_trait.rs index 2631c68..e134055 100644 --- a/crates/core/src/spammer/spammer_trait.rs +++ b/crates/core/src/spammer/spammer_trait.rs @@ -69,22 +69,18 @@ where tick += 1; } - let mut timeout_counter = 0; + let mut block_counter = 0; if let Some(run_id) = run_id { loop { - if timeout_counter > (num_periods * txs_per_period + 1) { - println!("quitting due to timeout"); - break; - } let cache_size = scenario .msg_handle - .flush_cache(run_id, block_num + timeout_counter as u64) + .flush_cache(run_id, block_num + block_counter as u64) .await .expect("failed to flush cache"); if cache_size == 0 { break; } - timeout_counter += 1; + block_counter += 1; } println!("done spamming. run_id={}", run_id); }