From 932763fcf2a5a98770c2a046c2cbc14916414f6f Mon Sep 17 00:00:00 2001 From: moudyellaz Date: Tue, 19 May 2026 23:48:05 +0200 Subject: [PATCH] refactor(e2e_bench): rename ScenarioResult to ScenarioOutput --- tools/e2e_bench/src/harness.rs | 22 +++++----- tools/e2e_bench/src/main.rs | 26 ++++++------ tools/e2e_bench/src/scenarios/amm.rs | 50 +++++++++++------------ tools/e2e_bench/src/scenarios/fanout.rs | 22 +++++----- tools/e2e_bench/src/scenarios/parallel.rs | 26 ++++++------ tools/e2e_bench/src/scenarios/private.rs | 34 +++++++-------- tools/e2e_bench/src/scenarios/token.rs | 30 +++++++------- 7 files changed, 105 insertions(+), 105 deletions(-) diff --git a/tools/e2e_bench/src/harness.rs b/tools/e2e_bench/src/harness.rs index c83904fd..7020352b 100644 --- a/tools/e2e_bench/src/harness.rs +++ b/tools/e2e_bench/src/harness.rs @@ -49,7 +49,7 @@ pub struct StepResult { } #[derive(Debug, Serialize, Default)] -pub struct ScenarioResult { +pub struct ScenarioOutput { pub name: String, #[serde(serialize_with = "ser_duration_secs", rename = "setup_s")] pub setup: Duration, @@ -68,7 +68,7 @@ pub struct ScenarioResult { pub bedrock_finality: Option, } -impl ScenarioResult { +impl ScenarioOutput { pub fn new(name: impl Into) -> Self { Self { name: name.into(), @@ -203,8 +203,8 @@ async fn sync_wallet_to_tip(ctx: &mut BenchContext) -> Result<()> { Ok(()) } -pub fn print_table(result: &ScenarioResult) { - let label_width = result +pub fn print_table(output: &ScenarioOutput) { + let label_width = output .steps .iter() .map(|s| s.label.len()) @@ -214,9 +214,9 @@ pub fn print_table(result: &ScenarioResult) { println!( "\nScenario: {} (setup {:.2}s, total {:.2}s)", - result.name, - result.setup.as_secs_f64(), - result.total.as_secs_f64(), + output.name, + output.setup.as_secs_f64(), + output.total.as_secs_f64(), ); println!( "{:10} {:>12} {:>10} {:>10}", @@ -228,7 +228,7 @@ pub fn print_table(result: &ScenarioResult) { lw = label_width, ); println!("{}", "-".repeat(label_width.saturating_add(50))); - for s in &result.steps { + for s in &output.steps { let inclusion = s .inclusion .map_or_else(|| "-".to_owned(), |v| format!("{:.3}", v.as_secs_f64())); @@ -246,13 +246,13 @@ pub fn print_table(result: &ScenarioResult) { ); } - print_size_summary(result); + print_size_summary(output); } /// Aggregate borsh sizes per scenario: total/mean/min/max block bytes, and /// per-tx bytes split by variant. Empty if no blocks were captured. -fn print_size_summary(result: &ScenarioResult) { - let blocks: Vec<&BlockSize> = result.steps.iter().flat_map(|s| s.blocks.iter()).collect(); +fn print_size_summary(output: &ScenarioOutput) { + let blocks: Vec<&BlockSize> = output.steps.iter().flat_map(|s| s.blocks.iter()).collect(); if blocks.is_empty() { return; } diff --git a/tools/e2e_bench/src/main.rs b/tools/e2e_bench/src/main.rs index 80f547ab..7de1d323 100644 --- a/tools/e2e_bench/src/main.rs +++ b/tools/e2e_bench/src/main.rs @@ -34,7 +34,7 @@ use anyhow::{Context as _, Result}; use bedrock_handle::BedrockHandle; use bench_context::BenchContext; use clap::{Parser, ValueEnum}; -use harness::ScenarioResult; +use harness::ScenarioOutput; use serde::Serialize; mod bedrock_handle; @@ -67,7 +67,7 @@ struct Cli { #[derive(Debug, Serialize)] struct BenchRunReport { risc0_dev_mode: bool, - scenarios: Vec, + scenarios: Vec, total_wall_s: f64, } @@ -97,7 +97,7 @@ async fn main() -> Result<()> { }; let overall_started = std::time::Instant::now(); - let mut all_results = Vec::with_capacity(to_run.len()); + let mut all_outputs = Vec::with_capacity(to_run.len()); for name in to_run { eprintln!("\n=== running scenario: {name:?} ==="); @@ -122,12 +122,12 @@ async fn main() -> Result<()> { eprintln!("setup: {:.2}s", setup.as_secs_f64()); let disk_before = ctx.disk_sizes(); - let mut result = run_scenario(name, setup, &mut ctx).await?; - result.disk_before = Some(disk_before); - result.disk_after = Some(ctx.disk_sizes()); - result.bedrock_finality = Some(measure_bedrock_finality(&ctx).await?); - harness::print_table(&result); - all_results.push(result); + let mut output = run_scenario(name, setup, &mut ctx).await?; + output.disk_before = Some(disk_before); + output.disk_after = Some(ctx.disk_sizes()); + output.bedrock_finality = Some(measure_bedrock_finality(&ctx).await?); + harness::print_table(&output); + all_outputs.push(output); // ctx and bedrock drop here at end of scope, killing the bedrock child // before we sleep so the next iteration can rebind the port. @@ -141,7 +141,7 @@ async fn main() -> Result<()> { let report = BenchRunReport { risc0_dev_mode, - scenarios: all_results, + scenarios: all_outputs, total_wall_s, }; @@ -170,8 +170,8 @@ async fn run_scenario( name: ScenarioName, setup: Duration, ctx: &mut BenchContext, -) -> Result { - let result = match name { +) -> Result { + let output = match name { ScenarioName::Token => scenarios::token::run(ctx).await?, ScenarioName::Amm => scenarios::amm::run(ctx).await?, ScenarioName::Fanout => scenarios::fanout::run(ctx).await?, @@ -179,7 +179,7 @@ async fn run_scenario( ScenarioName::Parallel => scenarios::parallel::run(ctx).await?, ScenarioName::All => unreachable!("dispatched above"), }; - Ok(ScenarioResult { setup, ..result }) + Ok(ScenarioOutput { setup, ..output }) } /// Poll the indexer's L1-finalised block id until it catches up with the diff --git a/tools/e2e_bench/src/scenarios/amm.rs b/tools/e2e_bench/src/scenarios/amm.rs index b92bd823..6756321d 100644 --- a/tools/e2e_bench/src/scenarios/amm.rs +++ b/tools/e2e_bench/src/scenarios/amm.rs @@ -10,25 +10,25 @@ use wallet::cli::{ programs::{amm::AmmProgramAgnosticSubcommand, token::TokenProgramAgnosticSubcommand}, }; -use crate::harness::{ScenarioResult, finalize_step}; +use crate::harness::{ScenarioOutput, finalize_step}; -pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result { - let mut result = ScenarioResult::new("amm_swap_flow"); +pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result { + let mut output = ScenarioOutput::new("amm_swap_flow"); - let def_a = new_public_account(ctx, &mut result, "create_acc_def_a").await?; - let supply_a = new_public_account(ctx, &mut result, "create_acc_supply_a").await?; - let user_a = new_public_account(ctx, &mut result, "create_acc_user_a").await?; + let def_a = new_public_account(ctx, &mut output, "create_acc_def_a").await?; + let supply_a = new_public_account(ctx, &mut output, "create_acc_supply_a").await?; + let user_a = new_public_account(ctx, &mut output, "create_acc_user_a").await?; - let def_b = new_public_account(ctx, &mut result, "create_acc_def_b").await?; - let supply_b = new_public_account(ctx, &mut result, "create_acc_supply_b").await?; - let user_b = new_public_account(ctx, &mut result, "create_acc_user_b").await?; + let def_b = new_public_account(ctx, &mut output, "create_acc_def_b").await?; + let supply_b = new_public_account(ctx, &mut output, "create_acc_supply_b").await?; + let user_b = new_public_account(ctx, &mut output, "create_acc_user_b").await?; - let user_lp = new_public_account(ctx, &mut result, "create_acc_user_lp").await?; + let user_lp = new_public_account(ctx, &mut output, "create_acc_user_lp").await?; - timed_token_new(ctx, &mut result, "token_a_new", def_a, supply_a, "TokA").await?; + timed_token_new(ctx, &mut output, "token_a_new", def_a, supply_a, "TokA").await?; timed_token_send( ctx, - &mut result, + &mut output, "token_a_fund_user", supply_a, user_a, @@ -36,10 +36,10 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result Result Result Result Result Result { let pre_block = crate::harness::begin_step(ctx).await?; @@ -140,7 +140,7 @@ async fn new_public_account( ) .await?; let step = finalize_step(label, started, pre_block, &ret, ctx).await?; - result.push(step); + output.push(step); match ret { SubcommandReturnValue::RegisterAccount { account_id } => Ok(account_id), other => bail!("expected RegisterAccount, got {other:?}"), @@ -149,7 +149,7 @@ async fn new_public_account( async fn timed_token_new( ctx: &mut crate::bench_context::BenchContext, - result: &mut ScenarioResult, + output: &mut ScenarioOutput, label: &str, def_id: nssa::AccountId, supply_id: nssa::AccountId, @@ -168,13 +168,13 @@ async fn timed_token_new( ) .await?; let step = finalize_step(label, started, pre_block, &ret, ctx).await?; - result.push(step); + output.push(step); Ok(()) } async fn timed_token_send( ctx: &mut crate::bench_context::BenchContext, - result: &mut ScenarioResult, + output: &mut ScenarioOutput, label: &str, from_id: nssa::AccountId, to_id: nssa::AccountId, @@ -195,6 +195,6 @@ async fn timed_token_send( ) .await?; let step = finalize_step(label, started, pre_block, &ret, ctx).await?; - result.push(step); + output.push(step); Ok(()) } diff --git a/tools/e2e_bench/src/scenarios/fanout.rs b/tools/e2e_bench/src/scenarios/fanout.rs index adede185..59e9a64b 100644 --- a/tools/e2e_bench/src/scenarios/fanout.rs +++ b/tools/e2e_bench/src/scenarios/fanout.rs @@ -10,16 +10,16 @@ use wallet::cli::{ programs::token::TokenProgramAgnosticSubcommand, }; -use crate::harness::{ScenarioResult, finalize_step}; +use crate::harness::{ScenarioOutput, finalize_step}; const FANOUT_COUNT: usize = 10; const AMOUNT_PER_TRANSFER: u128 = 100; -pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result { - let mut result = ScenarioResult::new("multi_recipient_fanout"); +pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result { + let mut output = ScenarioOutput::new("multi_recipient_fanout"); - let def_id = new_public_account(ctx, &mut result, "create_acc_def").await?; - let supply_id = new_public_account(ctx, &mut result, "create_acc_supply").await?; + let def_id = new_public_account(ctx, &mut output, "create_acc_def").await?; + let supply_id = new_public_account(ctx, &mut output, "create_acc_supply").await?; { let pre_block = crate::harness::begin_step(ctx).await?; @@ -35,12 +35,12 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result Result Result { let pre_block = crate::harness::begin_step(ctx).await?; @@ -82,7 +82,7 @@ async fn new_public_account( ) .await?; let step = finalize_step(label, started, pre_block, &ret, ctx).await?; - result.push(step); + output.push(step); match ret { SubcommandReturnValue::RegisterAccount { account_id } => Ok(account_id), other => bail!("expected RegisterAccount, got {other:?}"), diff --git a/tools/e2e_bench/src/scenarios/parallel.rs b/tools/e2e_bench/src/scenarios/parallel.rs index 23dd2247..86368a0d 100644 --- a/tools/e2e_bench/src/scenarios/parallel.rs +++ b/tools/e2e_bench/src/scenarios/parallel.rs @@ -17,27 +17,27 @@ use wallet::cli::{ use crate::{ bench_context::BenchContext, - harness::{BlockSize, ScenarioResult, StepResult, finalize_step}, + harness::{BlockSize, ScenarioOutput, StepResult, finalize_step}, }; const PARALLEL_FANOUT_N: usize = 10; const AMOUNT_PER_TRANSFER: u128 = 100; -pub async fn run(ctx: &mut BenchContext) -> Result { - let mut result = ScenarioResult::new("parallel_fanout"); +pub async fn run(ctx: &mut BenchContext) -> Result { + let mut output = ScenarioOutput::new("parallel_fanout"); // Setup: definition, master supply, N parallel supplies, N recipients. - let def_id = new_public_account(ctx, &mut result, "create_acc_def").await?; - let master_id = new_public_account(ctx, &mut result, "create_acc_master").await?; + let def_id = new_public_account(ctx, &mut output, "create_acc_def").await?; + let master_id = new_public_account(ctx, &mut output, "create_acc_master").await?; let mut senders = Vec::with_capacity(PARALLEL_FANOUT_N); for i in 0..PARALLEL_FANOUT_N { - let id = new_public_account(ctx, &mut result, &format!("create_sender_{i:02}")).await?; + let id = new_public_account(ctx, &mut output, &format!("create_sender_{i:02}")).await?; senders.push(id); } let mut recipients = Vec::with_capacity(PARALLEL_FANOUT_N); for i in 0..PARALLEL_FANOUT_N { - let id = new_public_account(ctx, &mut result, &format!("create_recipient_{i:02}")).await?; + let id = new_public_account(ctx, &mut output, &format!("create_recipient_{i:02}")).await?; recipients.push(id); } @@ -60,7 +60,7 @@ pub async fn run(ctx: &mut BenchContext) -> Result { ) .await?; let step = finalize_step("token_new_fungible", started, pre_block, &ret, ctx).await?; - result.push(step); + output.push(step); } // Fund each sender from master. Serial; this is setup, not measured throughput. @@ -81,7 +81,7 @@ pub async fn run(ctx: &mut BenchContext) -> Result { .await?; let step = finalize_step(format!("fund_sender_{i:02}"), started, pre_block, &ret, ctx).await?; - result.push(step); + output.push(step); } // The measured phase: submit N transfers as fast as possible, do not wait @@ -162,14 +162,14 @@ pub async fn run(ctx: &mut BenchContext) -> Result { tx_hash: None, blocks, }; - result.push(burst_step); + output.push(burst_step); - Ok(result) + Ok(output) } async fn new_public_account( ctx: &mut BenchContext, - result: &mut ScenarioResult, + output: &mut ScenarioOutput, label: &str, ) -> Result { let pre_block = crate::harness::begin_step(ctx).await?; @@ -183,7 +183,7 @@ async fn new_public_account( ) .await?; let step = finalize_step(label, started, pre_block, &ret, ctx).await?; - result.push(step); + output.push(step); match ret { SubcommandReturnValue::RegisterAccount { account_id } => Ok(account_id), other => bail!("expected RegisterAccount, got {other:?}"), diff --git a/tools/e2e_bench/src/scenarios/private.rs b/tools/e2e_bench/src/scenarios/private.rs index 2a154673..c6ef9888 100644 --- a/tools/e2e_bench/src/scenarios/private.rs +++ b/tools/e2e_bench/src/scenarios/private.rs @@ -10,17 +10,17 @@ use wallet::cli::{ programs::token::TokenProgramAgnosticSubcommand, }; -use crate::harness::{ScenarioResult, finalize_step}; +use crate::harness::{ScenarioOutput, finalize_step}; -pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result { - let mut result = ScenarioResult::new("private_chained_flow"); +pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result { + let mut output = ScenarioOutput::new("private_chained_flow"); - let def_id = new_public_account(ctx, &mut result, "create_acc_def").await?; - let supply_id = new_public_account(ctx, &mut result, "create_acc_supply").await?; + let def_id = new_public_account(ctx, &mut output, "create_acc_def").await?; + let supply_id = new_public_account(ctx, &mut output, "create_acc_supply").await?; let public_recipient_id = - new_public_account(ctx, &mut result, "create_acc_pub_recipient").await?; - let private_a = new_private_account(ctx, &mut result, "create_acc_priv_a").await?; - let private_b = new_private_account(ctx, &mut result, "create_acc_priv_b").await?; + new_public_account(ctx, &mut output, "create_acc_pub_recipient").await?; + let private_a = new_private_account(ctx, &mut output, "create_acc_priv_a").await?; + let private_b = new_private_account(ctx, &mut output, "create_acc_priv_b").await?; // Mint into public supply. { @@ -37,7 +37,7 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result private_a. @@ -57,7 +57,7 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result public_recipient. @@ -77,7 +77,7 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result private_b. @@ -97,15 +97,15 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result Result { let pre_block = crate::harness::begin_step(ctx).await?; @@ -119,7 +119,7 @@ async fn new_public_account( ) .await?; let step = finalize_step(label, started, pre_block, &ret, ctx).await?; - result.push(step); + output.push(step); match ret { SubcommandReturnValue::RegisterAccount { account_id } => Ok(account_id), other => bail!("expected RegisterAccount, got {other:?}"), @@ -128,7 +128,7 @@ async fn new_public_account( async fn new_private_account( ctx: &mut crate::bench_context::BenchContext, - result: &mut ScenarioResult, + output: &mut ScenarioOutput, label: &str, ) -> Result { let pre_block = crate::harness::begin_step(ctx).await?; @@ -142,7 +142,7 @@ async fn new_private_account( ) .await?; let step = finalize_step(label, started, pre_block, &ret, ctx).await?; - result.push(step); + output.push(step); match ret { SubcommandReturnValue::RegisterAccount { account_id } => Ok(account_id), other => bail!("expected RegisterAccount, got {other:?}"), diff --git a/tools/e2e_bench/src/scenarios/token.rs b/tools/e2e_bench/src/scenarios/token.rs index c81bd8c1..24c38fc3 100644 --- a/tools/e2e_bench/src/scenarios/token.rs +++ b/tools/e2e_bench/src/scenarios/token.rs @@ -10,14 +10,14 @@ use wallet::cli::{ programs::token::TokenProgramAgnosticSubcommand, }; -use crate::harness::{ScenarioResult, finalize_step}; +use crate::harness::{ScenarioOutput, finalize_step}; -pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result { - let mut result = ScenarioResult::new("token_onboarding"); +pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result { + let mut output = ScenarioOutput::new("token_onboarding"); - let definition_id = new_public_account(ctx, &mut result, "create_pub_definition").await?; - let supply_id = new_public_account(ctx, &mut result, "create_pub_supply").await?; - let recipient_id = new_public_account(ctx, &mut result, "create_pub_recipient").await?; + let definition_id = new_public_account(ctx, &mut output, "create_pub_definition").await?; + let supply_id = new_public_account(ctx, &mut output, "create_pub_supply").await?; + let recipient_id = new_public_account(ctx, &mut output, "create_pub_recipient").await?; { let pre_block = crate::harness::begin_step(ctx).await?; @@ -33,7 +33,7 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result Result Result Result { let pre_block = crate::harness::begin_step(ctx).await?; @@ -96,7 +96,7 @@ async fn new_public_account( ) .await?; let step = finalize_step(label, started, pre_block, &ret, ctx).await?; - result.push(step); + output.push(step); match ret { SubcommandReturnValue::RegisterAccount { account_id } => Ok(account_id), other => bail!("expected RegisterAccount, got {other:?}"), @@ -105,7 +105,7 @@ async fn new_public_account( async fn new_private_account( ctx: &mut crate::bench_context::BenchContext, - result: &mut ScenarioResult, + output: &mut ScenarioOutput, label: &str, ) -> Result { let pre_block = crate::harness::begin_step(ctx).await?; @@ -119,7 +119,7 @@ async fn new_private_account( ) .await?; let step = finalize_step(label, started, pre_block, &ret, ctx).await?; - result.push(step); + output.push(step); match ret { SubcommandReturnValue::RegisterAccount { account_id } => Ok(account_id), other => bail!("expected RegisterAccount, got {other:?}"),