Skip to content

refactor: add parse_and_commit #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions crates/committer_cli/benches/committer_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use committer::{
types::NodeIndex,
},
};
use committer_cli::{
commands::commit, parse_input::read::parse_input,
tests::utils::parse_from_python::TreeFlowInput,
};
use committer_cli::{commands::parse_and_commit, tests::utils::parse_from_python::TreeFlowInput};
use criterion::{criterion_group, criterion_main, Criterion};

const CONCURRENCY_MODE: bool = true;
Expand Down Expand Up @@ -62,16 +59,15 @@ pub fn full_committer_flow_benchmark(criterion: &mut Criterion) {
// TODO(Aner, 8/7/2024): use structs for deserialization.
let input: HashMap<String, String> = serde_json::from_str(FLOW_TEST_INPUT).unwrap();
let committer_input_string = input.get("committer_input").unwrap();

// TODO(Aner, 27/06/2024): output path should be a pipe (file on memory)
// to avoid disk IO in the benchmark.
// TODO(Aner, 11/7/24): consider moving function to production code.
async fn parse_and_commit(input_str: &str) {
let committer_input = parse_input(input_str).expect("Failed to parse the given input.");
commit(committer_input, OUTPUT_PATH.to_owned()).await;
}
criterion.bench_function("full_committer_flow", |benchmark| {
benchmark.iter(|| {
runtime.block_on(parse_and_commit(committer_input_string));
runtime.block_on(parse_and_commit(
committer_input_string,
OUTPUT_PATH.to_owned(),
));
})
});
}
Expand Down
8 changes: 7 additions & 1 deletion crates/committer_cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ use committer::block_committer::{
};

use crate::{
filled_tree_output::filled_forest::SerializedForest, parse_input::read::write_to_file,
filled_tree_output::filled_forest::SerializedForest,
parse_input::read::{parse_input, write_to_file},
};

pub async fn parse_and_commit(input_string: &str, output_path: String) {
let input = parse_input(input_string).expect("Failed to parse the given input.");
commit(input, output_path).await;
}

pub async fn commit(input: Input<ConfigImpl>, output_path: String) {
let serialized_filled_forest = SerializedForest(
commit_block(input)
Expand Down
10 changes: 4 additions & 6 deletions crates/committer_cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use clap::{Args, Parser, Subcommand};
use committer_cli::block_hash::{BlockCommitmentsInput, BlockHashInput};
use committer_cli::commands::commit;
use committer_cli::parse_input::read::{
load_from_stdin, parse_input, read_from_stdin, write_to_file,
};
use committer_cli::commands::parse_and_commit;
use committer_cli::parse_input::read::{load_from_stdin, read_from_stdin, write_to_file};
use committer_cli::tests::python_tests::PythonTest;
use simplelog::{ColorChoice, Config, LevelFilter, TermLogger, TerminalMode};
use starknet_api::block_hash::block_hash_calculator::{
Expand Down Expand Up @@ -73,8 +71,8 @@ async fn main() {

match args.command {
Command::Commit { output_path } => {
let input = parse_input(&read_from_stdin()).expect("Failed to parse the given input.");
commit(input, output_path).await;
// TODO(Aner, 15/7/24): try moving read_from_stdin into function.
parse_and_commit(&read_from_stdin(), output_path).await;
}

Command::PythonTest {
Expand Down
Loading