Skip to content

Commit

Permalink
chore: add logs (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
amosStarkware authored Aug 7, 2024
1 parent c0b085a commit a40cb09
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
11 changes: 8 additions & 3 deletions crates/committer/src/block_committer/commit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use tracing::warn;
use tracing::{info, warn};

use crate::block_committer::errors::BlockCommitmentError;
use crate::block_committer::input::{Config, ConfigImpl, ContractAddress, Input, StateDiff};
Expand Down Expand Up @@ -40,6 +40,7 @@ pub async fn commit_block(input: Input<ConfigImpl>) -> BlockCommitmentResult<Fil
&forest_sorted_indices,
&input.config,
)?;
info!("Original skeleton forest created successfully.");

if input.config.warn_on_trivial_modifications() {
check_trivial_nonce_and_class_hash_updates(
Expand All @@ -57,16 +58,20 @@ pub async fn commit_block(input: Input<ConfigImpl>) -> BlockCommitmentResult<Fil
&input.state_diff.address_to_class_hash,
&input.state_diff.address_to_nonce,
)?;
info!("Updated skeleton forest created successfully.");

Ok(FilledForest::create::<TreeHashFunctionImpl>(
let filled_forest = FilledForest::create::<TreeHashFunctionImpl>(
updated_forest,
actual_storage_updates,
actual_classes_updates,
&original_contracts_trie_leaves,
&input.state_diff.address_to_class_hash,
&input.state_diff.address_to_nonce,
)
.await?)
.await?;
info!("Filled forest created successfully.");

Ok(filled_forest)
}

/// Compares the previous state's nonce and class hash with the given in the state diff.
Expand Down
11 changes: 11 additions & 0 deletions crates/committer_cli/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use committer::block_committer::commit::commit_block;
use committer::block_committer::input::{Config, ConfigImpl, Input};
use tracing::info;
use tracing::level_filters::LevelFilter;
use tracing_subscriber::reload::Handle;
use tracing_subscriber::Registry;
Expand All @@ -13,6 +14,11 @@ pub async fn parse_and_commit(
log_filter_handle: Handle<LevelFilter, Registry>,
) {
let input = parse_input(input_string).expect("Failed to parse the given input.");
info!(
"Parsed committer input successfully. Original Contracts Trie Root Hash: {:?},
Original Classes Trie Root Hash: {:?}",
input.contracts_trie_root_hash, input.classes_trie_root_hash,
);
// Set the given log level if handle is passed.
log_filter_handle
.modify(|filter| *filter = input.config.logger_level())
Expand All @@ -25,4 +31,9 @@ pub async fn commit(input: Input<ConfigImpl>, output_path: String) {
SerializedForest(commit_block(input).await.expect("Failed to commit the given block."));
let output = serialized_filled_forest.forest_to_output();
write_to_file(&output_path, &output);
info!(
"Successfully committed given block. Updated Contracts Trie Root Hash: {:?},
Updated Classes Trie Root Hash: {:?}",
output.contract_storage_root_hash, output.compiled_class_root_hash,
);
}
5 changes: 3 additions & 2 deletions crates/committer_cli/src/filled_tree_output/filled_forest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ pub struct SerializedForest(pub FilledForest);
pub struct Output {
// New fact storage.
storage: MapStorage,
// TODO(Amos, 1/8/2024): Rename to `contracts_trie_root_hash` & `classes_trie_root_hash`.
// New contract storage root.
contract_storage_root_hash: String,
pub contract_storage_root_hash: String,
// New compiled class root.
compiled_class_root_hash: String,
pub compiled_class_root_hash: String,
}

impl SerializedForest {
Expand Down
7 changes: 6 additions & 1 deletion crates/committer_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use starknet_api::block_hash::block_hash_calculator::{
calculate_block_commitments,
calculate_block_hash,
};
use tracing::info;

/// Committer CLI.
#[derive(Debug, Parser)]
Expand All @@ -28,7 +29,6 @@ enum Command {
#[clap(long, short = 'o', default_value = "stdout")]
output_path: String,
},
/// Given previous state tree skeleton and a state diff, computes the new commitment.
/// Calculates commitments needed for the block hash.
BlockHashCommitments {
/// File path to output.
Expand Down Expand Up @@ -63,6 +63,7 @@ async fn main() {
let log_filter_handle = configure_tracing();

let args = CommitterCliArgs::parse();
info!("Starting committer-cli with args: \n{:?}", args);

match args.command {
Command::Commit { output_path } => {
Expand All @@ -88,19 +89,23 @@ async fn main() {

Command::BlockHash { output_path } => {
let block_hash_input: BlockHashInput = load_from_stdin();
info!("Successfully loaded block hash input.");
let block_hash =
calculate_block_hash(block_hash_input.header, block_hash_input.block_commitments);
write_to_file(&output_path, &block_hash);
info!("Successfully computed block hash {:?}.", block_hash);
}

Command::BlockHashCommitments { output_path } => {
let commitments_input: BlockCommitmentsInput = load_from_stdin();
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,
);
write_to_file(&output_path, &commitments);
info!("Successfully computed block hash commitment: \n{:?}", commitments);
}
}
}

0 comments on commit a40cb09

Please sign in to comment.