Skip to content

Commit

Permalink
remove timeout, add env var to fill blocks up to a percent
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroXbrock committed Dec 5, 2024
1 parent 69f0021 commit 9930284
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
17 changes: 15 additions & 2 deletions crates/cli/src/default_scenarios/runconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand All @@ -35,8 +42,14 @@ impl From<BuiltinScenarioConfig> 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 {
Expand Down
6 changes: 6 additions & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod commands;
mod default_scenarios;

use std::{
env,
io::Write,
str::FromStr,
sync::{Arc, LazyLock},
Expand Down Expand Up @@ -286,11 +287,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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();
Expand Down
10 changes: 3 additions & 7 deletions crates/core/src/spammer/spammer_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 9930284

Please sign in to comment.