-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(starknet_committer_and_os_cli): moved committer logic into sepa…
…rate folder
- Loading branch information
1 parent
148a9ef
commit da0e82a
Showing
29 changed files
with
211 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pub mod block_hash; | ||
pub mod commands; | ||
pub mod filled_tree_output; | ||
pub mod parse_input; | ||
pub mod run_committer_cli; | ||
pub mod tests; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
crates/starknet_committer_and_os_cli/src/committer_cli/parse_input/read.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use starknet_patricia::storage::errors::DeserializationError; | ||
|
||
use crate::committer_cli::parse_input::cast::InputImpl; | ||
use crate::committer_cli::parse_input::raw_input::RawInput; | ||
|
||
#[cfg(test)] | ||
#[path = "read_test.rs"] | ||
pub mod read_test; | ||
|
||
type DeserializationResult<T> = Result<T, DeserializationError>; | ||
|
||
pub fn parse_input(input: &str) -> DeserializationResult<InputImpl> { | ||
serde_json::from_str::<RawInput>(input)?.try_into() | ||
} |
File renamed without changes.
99 changes: 99 additions & 0 deletions
99
crates/starknet_committer_and_os_cli/src/committer_cli/run_committer_cli.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
use clap::{Parser, Subcommand}; | ||
use starknet_api::block_hash::block_hash_calculator::{ | ||
calculate_block_commitments, | ||
calculate_block_hash, | ||
}; | ||
use tracing::info; | ||
use tracing::level_filters::LevelFilter; | ||
use tracing_subscriber::reload::Handle; | ||
use tracing_subscriber::Registry; | ||
|
||
use crate::committer_cli::block_hash::{BlockCommitmentsInput, BlockHashInput}; | ||
use crate::committer_cli::commands::parse_and_commit; | ||
use crate::committer_cli::tests::python_tests::PythonTest; | ||
use crate::shared_utils::read::{load_input, read_input, write_to_file}; | ||
use crate::shared_utils::types::IoArgs; | ||
|
||
#[derive(Parser, Debug)] | ||
pub struct CommitterCliCommand { | ||
#[clap(subcommand)] | ||
command: Command, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
enum Command { | ||
/// Calculates the block hash. | ||
BlockHash { | ||
#[clap(flatten)] | ||
io_args: IoArgs, | ||
}, | ||
/// Calculates commitments needed for the block hash. | ||
BlockHashCommitments { | ||
#[clap(flatten)] | ||
io_args: IoArgs, | ||
}, | ||
/// Given previous state tree skeleton and a state diff, computes the new commitment. | ||
Commit { | ||
#[clap(flatten)] | ||
io_args: IoArgs, | ||
}, | ||
PythonTest { | ||
#[clap(flatten)] | ||
io_args: IoArgs, | ||
|
||
/// Test name. | ||
#[clap(long)] | ||
test_name: String, | ||
}, | ||
} | ||
|
||
pub async fn run_committer_cli( | ||
committer_command: CommitterCliCommand, | ||
log_filter_handle: Handle<LevelFilter, Registry>, | ||
) { | ||
info!("Starting committer-cli with command: \n{:?}", committer_command); | ||
match committer_command.command { | ||
Command::Commit { io_args: IoArgs { input_path, output_path } } => { | ||
parse_and_commit(input_path, output_path, log_filter_handle).await; | ||
} | ||
|
||
Command::PythonTest { io_args: IoArgs { input_path, output_path }, test_name } => { | ||
// Create PythonTest from test_name. | ||
let test = PythonTest::try_from(test_name) | ||
.unwrap_or_else(|error| panic!("Failed to create PythonTest: {}", error)); | ||
let input = read_input(input_path); | ||
|
||
// Run relevant test. | ||
let output = test | ||
.run(Some(&input)) | ||
.await | ||
.unwrap_or_else(|error| panic!("Failed to run test: {}", error)); | ||
|
||
// Write test's output. | ||
write_to_file(&output_path, &output); | ||
} | ||
|
||
Command::BlockHash { io_args: IoArgs { input_path, output_path } } => { | ||
let block_hash_input: BlockHashInput = load_input(input_path); | ||
info!("Successfully loaded block hash input."); | ||
let block_hash = | ||
calculate_block_hash(block_hash_input.header, block_hash_input.block_commitments) | ||
.unwrap_or_else(|error| panic!("Failed to calculate block hash: {}", error)); | ||
write_to_file(&output_path, &block_hash); | ||
info!("Successfully computed block hash {:?}.", block_hash); | ||
} | ||
|
||
Command::BlockHashCommitments { io_args: IoArgs { input_path, output_path } } => { | ||
let commitments_input: BlockCommitmentsInput = load_input(input_path); | ||
info!("Successfully loaded block hash commitment input."); | ||
let commitments = calculate_block_commitments( | ||
&commitments_input.transactions_data, | ||
&commitments_input.state_diff, | ||
commitments_input.l1_da_mode, | ||
&commitments_input.starknet_version, | ||
); | ||
write_to_file(&output_path, &commitments); | ||
info!("Successfully computed block hash commitment: \n{:?}", commitments); | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
pub mod block_hash; | ||
pub mod commands; | ||
pub mod filled_tree_output; | ||
pub mod parse_input; | ||
pub mod tests; | ||
pub mod committer_cli; | ||
pub mod os_cli; | ||
pub mod shared_utils; | ||
pub mod tracing_utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,119 +1,50 @@ | ||
use clap::{Args, Parser, Subcommand}; | ||
use starknet_api::block_hash::block_hash_calculator::{ | ||
calculate_block_commitments, | ||
calculate_block_hash, | ||
use starknet_committer_and_os_cli::committer_cli::run_committer_cli::{ | ||
run_committer_cli, | ||
CommitterCliCommand, | ||
}; | ||
use starknet_committer_and_os_cli::block_hash::{BlockCommitmentsInput, BlockHashInput}; | ||
use starknet_committer_and_os_cli::commands::parse_and_commit; | ||
use starknet_committer_and_os_cli::parse_input::read::{load_input, read_input, write_to_file}; | ||
use starknet_committer_and_os_cli::tests::python_tests::PythonTest; | ||
use starknet_committer_and_os_cli::os_cli::run_os_cli::{run_os_cli, OsCliCommand}; | ||
use starknet_committer_and_os_cli::tracing_utils::configure_tracing; | ||
use tracing::info; | ||
|
||
/// Committer CLI. | ||
/// Committer and OS CLI. | ||
#[derive(Debug, Parser)] | ||
#[clap(name = "committer-cli", version)] | ||
pub struct CommitterCliArgs { | ||
#[clap(name = "committer-and-os-cli", version)] | ||
struct CliArgs { | ||
#[clap(flatten)] | ||
global_options: GlobalOptions, | ||
|
||
#[clap(subcommand)] | ||
command: Command, | ||
} | ||
|
||
#[derive(Debug, Args)] | ||
pub struct IoArgs { | ||
/// File path to input. | ||
#[clap(long, short = 'i')] | ||
input_path: String, | ||
|
||
/// File path to output. | ||
#[clap(long, short = 'o', default_value = "stdout")] | ||
output_path: String, | ||
command: CommitterOrOsCommand, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
enum Command { | ||
/// Calculates the block hash. | ||
BlockHash { | ||
#[clap(flatten)] | ||
io_args: IoArgs, | ||
}, | ||
/// Calculates commitments needed for the block hash. | ||
BlockHashCommitments { | ||
#[clap(flatten)] | ||
io_args: IoArgs, | ||
}, | ||
/// Given previous state tree skeleton and a state diff, computes the new commitment. | ||
Commit { | ||
#[clap(flatten)] | ||
io_args: IoArgs, | ||
}, | ||
PythonTest { | ||
#[clap(flatten)] | ||
io_args: IoArgs, | ||
|
||
/// Test name. | ||
#[clap(long)] | ||
test_name: String, | ||
}, | ||
enum CommitterOrOsCommand { | ||
/// Run Committer CLI. | ||
Committer(CommitterCliCommand), | ||
/// Run OS CLI. | ||
OS(OsCliCommand), | ||
} | ||
|
||
#[derive(Debug, Args)] | ||
struct GlobalOptions {} | ||
|
||
#[tokio::main] | ||
/// Main entry point of the committer CLI. | ||
/// Main entry point of the committer & OS CLI. | ||
async fn main() { | ||
// Initialize the logger. The log_filter_handle is used to change the log level. The | ||
// default log level is INFO. | ||
let log_filter_handle = configure_tracing(); | ||
|
||
let args = CommitterCliArgs::parse(); | ||
info!("Starting committer-cli with args: \n{:?}", args); | ||
let args = CliArgs::parse(); | ||
info!("Starting committer & OS cli with args: \n{:?}", args); | ||
|
||
match args.command { | ||
Command::Commit { io_args: IoArgs { input_path, output_path } } => { | ||
parse_and_commit(input_path, output_path, log_filter_handle).await; | ||
} | ||
|
||
Command::PythonTest { io_args: IoArgs { input_path, output_path }, test_name } => { | ||
// Create PythonTest from test_name. | ||
let test = PythonTest::try_from(test_name) | ||
.unwrap_or_else(|error| panic!("Failed to create PythonTest: {}", error)); | ||
let input = read_input(input_path); | ||
|
||
// Run relevant test. | ||
let output = test | ||
.run(Some(&input)) | ||
.await | ||
.unwrap_or_else(|error| panic!("Failed to run test: {}", error)); | ||
|
||
// Write test's output. | ||
write_to_file(&output_path, &output); | ||
CommitterOrOsCommand::Committer(command) => { | ||
run_committer_cli(command, log_filter_handle).await; | ||
} | ||
|
||
Command::BlockHash { io_args: IoArgs { input_path, output_path } } => { | ||
let block_hash_input: BlockHashInput = load_input(input_path); | ||
info!("Successfully loaded block hash input."); | ||
let block_hash = | ||
calculate_block_hash(block_hash_input.header, block_hash_input.block_commitments) | ||
.unwrap_or_else(|error| panic!("Failed to calculate block hash: {}", error)); | ||
write_to_file(&output_path, &block_hash); | ||
info!("Successfully computed block hash {:?}.", block_hash); | ||
} | ||
|
||
Command::BlockHashCommitments { io_args: IoArgs { input_path, output_path } } => { | ||
let commitments_input: BlockCommitmentsInput = load_input(input_path); | ||
info!("Successfully loaded block hash commitment input."); | ||
let commitments = calculate_block_commitments( | ||
&commitments_input.transactions_data, | ||
&commitments_input.state_diff, | ||
commitments_input.l1_da_mode, | ||
&commitments_input.starknet_version, | ||
); | ||
write_to_file(&output_path, &commitments); | ||
info!("Successfully computed block hash commitment: \n{:?}", commitments); | ||
CommitterOrOsCommand::OS(command) => { | ||
run_os_cli(command, log_filter_handle).await; | ||
} | ||
} | ||
} |
Oops, something went wrong.