refactor(e2e_bench): rename ScenarioResult to ScenarioOutput

This commit is contained in:
moudyellaz 2026-05-19 23:48:05 +02:00
parent 619db3846d
commit 932763fcf2
7 changed files with 105 additions and 105 deletions

View File

@ -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<Duration>,
}
impl ScenarioResult {
impl ScenarioOutput {
pub fn new(name: impl Into<String>) -> 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!(
"{:<lw$} {:>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;
}

View File

@ -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<ScenarioResult>,
scenarios: Vec<ScenarioOutput>,
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<ScenarioResult> {
let result = match name {
) -> Result<ScenarioOutput> {
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

View File

@ -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<ScenarioResult> {
let mut result = ScenarioResult::new("amm_swap_flow");
pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result<ScenarioOutput> {
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<Scenari
)
.await?;
timed_token_new(ctx, &mut result, "token_b_new", def_b, supply_b, "TokB").await?;
timed_token_new(ctx, &mut output, "token_b_new", def_b, supply_b, "TokB").await?;
timed_token_send(
ctx,
&mut result,
&mut output,
"token_b_fund_user",
supply_b,
user_b,
@ -62,7 +62,7 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result<Scenari
)
.await?;
let step = finalize_step("amm_new_pool", started, pre_block, &ret, ctx).await?;
result.push(step);
output.push(step);
}
{
@ -80,7 +80,7 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result<Scenari
)
.await?;
let step = finalize_step("amm_swap_exact_input", started, pre_block, &ret, ctx).await?;
result.push(step);
output.push(step);
}
{
@ -99,7 +99,7 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result<Scenari
)
.await?;
let step = finalize_step("amm_add_liquidity", started, pre_block, &ret, ctx).await?;
result.push(step);
output.push(step);
}
{
@ -118,15 +118,15 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result<Scenari
)
.await?;
let step = finalize_step("amm_remove_liquidity", started, pre_block, &ret, ctx).await?;
result.push(step);
output.push(step);
}
Ok(result)
Ok(output)
}
async fn new_public_account(
ctx: &mut crate::bench_context::BenchContext,
result: &mut ScenarioResult,
output: &mut ScenarioOutput,
label: &str,
) -> Result<nssa::AccountId> {
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(())
}

View File

@ -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<ScenarioResult> {
let mut result = ScenarioResult::new("multi_recipient_fanout");
pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result<ScenarioOutput> {
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<Scenari
)
.await?;
let step = finalize_step("token_new_fungible", started, pre_block, &ret, ctx).await?;
result.push(step);
output.push(step);
}
let mut recipients = Vec::with_capacity(FANOUT_COUNT);
for i in 0..FANOUT_COUNT {
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,15 +60,15 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result<Scenari
)
.await?;
let step = finalize_step(format!("transfer_{i:02}"), started, pre_block, &ret, ctx).await?;
result.push(step);
output.push(step);
}
Ok(result)
Ok(output)
}
async fn new_public_account(
ctx: &mut crate::bench_context::BenchContext,
result: &mut ScenarioResult,
output: &mut ScenarioOutput,
label: &str,
) -> Result<nssa::AccountId> {
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:?}"),

View File

@ -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<ScenarioResult> {
let mut result = ScenarioResult::new("parallel_fanout");
pub async fn run(ctx: &mut BenchContext) -> Result<ScenarioOutput> {
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<ScenarioResult> {
)
.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<ScenarioResult> {
.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<ScenarioResult> {
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<nssa::AccountId> {
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:?}"),

View File

@ -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<ScenarioResult> {
let mut result = ScenarioResult::new("private_chained_flow");
pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result<ScenarioOutput> {
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<Scenari
)
.await?;
let step = finalize_step("token_new_fungible", started, pre_block, &ret, ctx).await?;
result.push(step);
output.push(step);
}
// Shielded transfer: public supply -> private_a.
@ -57,7 +57,7 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result<Scenari
)
.await?;
let step = finalize_step("shielded_transfer", started, pre_block, &ret, ctx).await?;
result.push(step);
output.push(step);
}
// Deshielded transfer: private_a -> public_recipient.
@ -77,7 +77,7 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result<Scenari
)
.await?;
let step = finalize_step("deshielded_transfer", started, pre_block, &ret, ctx).await?;
result.push(step);
output.push(step);
}
// Private-to-private transfer: private_a -> private_b.
@ -97,15 +97,15 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result<Scenari
)
.await?;
let step = finalize_step("private_to_private", started, pre_block, &ret, ctx).await?;
result.push(step);
output.push(step);
}
Ok(result)
Ok(output)
}
async fn new_public_account(
ctx: &mut crate::bench_context::BenchContext,
result: &mut ScenarioResult,
output: &mut ScenarioOutput,
label: &str,
) -> Result<nssa::AccountId> {
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<nssa::AccountId> {
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:?}"),

View File

@ -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<ScenarioResult> {
let mut result = ScenarioResult::new("token_onboarding");
pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result<ScenarioOutput> {
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<Scenari
)
.await?;
let step = finalize_step("token_new_fungible", started, pre_block, &ret, ctx).await?;
result.push(step);
output.push(step);
}
{
@ -52,11 +52,11 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result<Scenari
)
.await?;
let step = finalize_step("token_public_transfer", started, pre_block, &ret, ctx).await?;
result.push(step);
output.push(step);
}
let private_recipient_id =
new_private_account(ctx, &mut result, "create_priv_recipient").await?;
new_private_account(ctx, &mut output, "create_priv_recipient").await?;
{
let pre_block = crate::harness::begin_step(ctx).await?;
@ -74,15 +74,15 @@ pub async fn run(ctx: &mut crate::bench_context::BenchContext) -> Result<Scenari
)
.await?;
let step = finalize_step("token_shielded_transfer", started, pre_block, &ret, ctx).await?;
result.push(step);
output.push(step);
}
Ok(result)
Ok(output)
}
async fn new_public_account(
ctx: &mut crate::bench_context::BenchContext,
result: &mut ScenarioResult,
output: &mut ScenarioOutput,
label: &str,
) -> Result<nssa::AccountId> {
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<nssa::AccountId> {
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:?}"),