From 8d6ffff28624915ec51de43a641ec35fe554fbec Mon Sep 17 00:00:00 2001 From: zeroXbrock <2791467+zeroXbrock@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:03:12 -0800 Subject: [PATCH 1/5] export report to report.csv by default --- .gitignore | 1 + crates/cli/src/commands/report.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 4469471..4269823 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target cargotest.toml *.db +report.csv diff --git a/crates/cli/src/commands/report.rs b/crates/cli/src/commands/report.rs index 37b02f4..c699325 100644 --- a/crates/cli/src/commands/report.rs +++ b/crates/cli/src/commands/report.rs @@ -33,10 +33,15 @@ pub fn report( let mut writer = WriterBuilder::new().has_headers(true).from_path(out_file)?; write_run_txs(&mut writer, &txs)?; } else { + // print to stdout and write to default file let mut writer = WriterBuilder::new() .has_headers(true) .from_writer(std::io::stdout()); write_run_txs(&mut writer, &txs)?; // TODO: write a macro that lets us generalize the writer param to write_run_txs, then refactor this duplication + let mut writer = WriterBuilder::new() + .has_headers(true) + .from_path("report.csv")?; + write_run_txs(&mut writer, &txs)?; }; Ok(()) From 067327dfd27837c27207ba3c0223058daf54fc01 Mon Sep 17 00:00:00 2001 From: zeroXbrock <2791467+zeroXbrock@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:03:41 -0800 Subject: [PATCH 2/5] fix ms-sec logging in report --- crates/core/src/spammer/tx_actor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/spammer/tx_actor.rs b/crates/core/src/spammer/tx_actor.rs index 35d3b87..6f89488 100644 --- a/crates/core/src/spammer/tx_actor.rs +++ b/crates/core/src/spammer/tx_actor.rs @@ -165,7 +165,7 @@ where } RunTx { tx_hash: pending_tx.tx_hash, - start_timestamp: pending_tx.start_timestamp, + start_timestamp: pending_tx.start_timestamp / 1000, end_timestamp: target_block.header.timestamp as usize, block_number: target_block.header.number, gas_used: receipt.gas_used, From 0d3aab81f0cc8bb96a19f68efebc0958d95d8df7 Mon Sep 17 00:00:00 2001 From: zeroXbrock <2791467+zeroXbrock@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:11:10 -0800 Subject: [PATCH 3/5] save report to ~/.contender/ --- crates/cli/src/commands/report.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/cli/src/commands/report.rs b/crates/cli/src/commands/report.rs index c699325..b9e5d57 100644 --- a/crates/cli/src/commands/report.rs +++ b/crates/cli/src/commands/report.rs @@ -38,10 +38,15 @@ pub fn report( .has_headers(true) .from_writer(std::io::stdout()); write_run_txs(&mut writer, &txs)?; // TODO: write a macro that lets us generalize the writer param to write_run_txs, then refactor this duplication + let home_dir = std::env::var("HOME").expect("Could not get home directory"); + let contender_dir = format!("{}/.contender", home_dir); + std::fs::create_dir_all(&contender_dir)?; + let report_path = format!("{}/report.csv", contender_dir); let mut writer = WriterBuilder::new() .has_headers(true) - .from_path("report.csv")?; + .from_path(report_path.to_owned())?; write_run_txs(&mut writer, &txs)?; + println!("saved report to {}", report_path); }; Ok(()) From 93c75aa40e81cee419fc95b28468917f214e3b7d Mon Sep 17 00:00:00 2001 From: zeroXbrock <2791467+zeroXbrock@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:22:50 -0800 Subject: [PATCH 4/5] save DB to ~/.contender/ --- crates/cli/src/main.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 5ac088d..869cd51 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -9,7 +9,15 @@ use contender_core::{db::DbOps, generator::RandSeed}; use contender_sqlite::SqliteDb; static DB: LazyLock = std::sync::LazyLock::new(|| { - SqliteDb::from_file("contender.db").expect("failed to open contender.db") + let path = &format!( + "{}{}", + std::env::var("HOME").unwrap(), + "/.contender/contender.db" + ); + println!("opening DB at {}", path); + std::fs::create_dir_all(std::env::var("HOME").unwrap() + "/.contender") + .expect("failed to create ~/.contender directory"); + SqliteDb::from_file(path).expect("failed to open contender DB file") }); #[tokio::main] From fa66bc6393550b3169254ac99fec68e26b2a245d Mon Sep 17 00:00:00 2001 From: zeroXbrock <2791467+zeroXbrock@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:26:02 -0800 Subject: [PATCH 5/5] chore: clippy --- crates/cli/src/commands/report.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cli/src/commands/report.rs b/crates/cli/src/commands/report.rs index b9e5d57..73a29a8 100644 --- a/crates/cli/src/commands/report.rs +++ b/crates/cli/src/commands/report.rs @@ -44,7 +44,7 @@ pub fn report( let report_path = format!("{}/report.csv", contender_dir); let mut writer = WriterBuilder::new() .has_headers(true) - .from_path(report_path.to_owned())?; + .from_path(&report_path)?; write_run_txs(&mut writer, &txs)?; println!("saved report to {}", report_path); };