Skip to content

build: impl main committer logic #175

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
Jun 2, 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions crates/committer/src/block_committer/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::storage::map_storage::MapStorage;
type BlockCommitmentResult<T> = Result<T, BlockCommitmentError<LeafDataImpl>>;

#[allow(dead_code)]
pub(crate) async fn commit_block(input: Input) -> BlockCommitmentResult<()> {
pub async fn commit_block(input: Input) -> BlockCommitmentResult<FilledForestImpl> {
let mut original_forest = OriginalSkeletonForestImpl::<OriginalSkeletonTreeImpl>::create(
MapStorage::from(input.storage),
input.contracts_trie_root_hash,
Expand All @@ -42,19 +42,19 @@ pub(crate) async fn commit_block(input: Input) -> BlockCommitmentResult<()> {
input.tree_heights,
)?;

let _filled_forest = FilledForestImpl::create::<UpdatedSkeletonTreeImpl, TreeHashFunctionImpl>(
updated_forest,
input.state_diff.actual_storage_updates(input.tree_heights),
StateDiff::actual_classes_updates(
&input.state_diff.class_hash_to_compiled_class_hash,
Ok(
FilledForestImpl::create::<UpdatedSkeletonTreeImpl, TreeHashFunctionImpl>(
updated_forest,
input.state_diff.actual_storage_updates(input.tree_heights),
StateDiff::actual_classes_updates(
&input.state_diff.class_hash_to_compiled_class_hash,
input.tree_heights,
),
&input.current_contracts_trie_leaves,
&input.state_diff.address_to_class_hash,
&input.state_diff.address_to_nonce,
input.tree_heights,
),
&input.current_contracts_trie_leaves,
&input.state_diff.address_to_class_hash,
&input.state_diff.address_to_nonce,
input.tree_heights,
)
.await?,
)
.await?;

todo!()
}
2 changes: 1 addition & 1 deletion crates/committer/src/block_committer/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use thiserror::Error;
use crate::{forest_errors::ForestError, patricia_merkle_tree::node_data::leaf::LeafData};

#[derive(Debug, Error)]
pub(crate) enum BlockCommitmentError<L: LeafData> {
pub enum BlockCommitmentError<L: LeafData> {
#[error(transparent)]
ForestError(#[from] ForestError<L>),
}
2 changes: 1 addition & 1 deletion crates/committer/src/forest_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tokio::task::JoinError;
pub(crate) type ForestResult<T> = Result<T, ForestError<LeafDataImpl>>;

#[derive(Debug, Error)]
pub(crate) enum ForestError<L: LeafData> {
pub enum ForestError<L: LeafData> {
#[error(transparent)]
OriginalSkeleton(#[from] OriginalSkeletonTreeError),
#[error(transparent)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use thiserror::Error;
use crate::storage::errors::{DeserializationError, StorageError};

#[derive(Debug, Error)]
pub(crate) enum OriginalSkeletonTreeError {
pub enum OriginalSkeletonTreeError {
#[error(
"Failed to deserialize the storage value: {0:?} while building the original skeleton tree."
)]
Expand Down
2 changes: 1 addition & 1 deletion crates/committer/src/storage/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde_json;
use thiserror::Error;

#[derive(Debug, Error)]
pub(crate) enum StorageError {
pub enum StorageError {
#[error("The key {0:?} does not exist in storage.")]
MissingKey(StorageKey),
}
Expand Down
1 change: 1 addition & 0 deletions crates/committer_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ starknet-types-core.workspace = true
strum.workspace = true
strum_macros.workspace = true
thiserror.workspace = true
tokio.workspace = true
35 changes: 19 additions & 16 deletions crates/committer_cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::tests::python_tests::PythonTest;
use clap::{Args, Parser, Subcommand};
use std::path::Path;
use committer::block_committer::commit::commit_block;
use filled_tree_output::filled_forest::SerializedForest;
use parse_input::read::parse_input;
use std::io;

pub mod filled_tree_output;
pub mod parse_input;
Expand Down Expand Up @@ -43,28 +46,28 @@ enum Command {
#[derive(Debug, Args)]
struct GlobalOptions {}

#[tokio::main]
/// Main entry point of the committer CLI.
fn main() {
async fn main() {
let args = CommitterCliArgs::parse();

match args.command {
Command::Commit {
input_path,
output_path,
input_path: _input_path,
output_path: _output_path,
} => {
let input_file_name = Path::new(&input_path);
let output_file_name = Path::new(&output_path);
assert!(
input_file_name.is_absolute() && output_file_name.is_absolute(),
"Given paths must be absolute."
// TODO(Nimrod, 20/6/2024): Allow read/write from file path.
let input =
parse_input(io::read_to_string(io::stdin()).expect("Failed to read from stdin."))
.expect("Failed to parse the given input.");
let serialized_filled_forest = SerializedForest(
commit_block(input)
.await
.expect("Failed to commit the given block."),
);

// Business logic to be implemented here.
let output = std::fs::read(input_file_name)
.unwrap_or_else(|_| panic!("Failed to read input from file '{input_file_name:?}'"));

// Output to file.
std::fs::write(output_file_name, output).expect("Failed to write output");
serialized_filled_forest
.forest_to_python()
.expect("Failed to print new facts to python.");
}

Command::PythonTest { test_name, inputs } => {
Expand Down
Loading