Skip to content

Commit

Permalink
style: Replace print with use of logger
Browse files Browse the repository at this point in the history
The application should only write to the user through the use of the
logger and should not write with `print` except for in tests.
  • Loading branch information
Sword-Smith committed Oct 15, 2024
1 parent b4d1623 commit 1f570ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
25 changes: 13 additions & 12 deletions src/models/proof_abstractions/tasm/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use tasm_lib::triton_vm::prelude::*;
use tasm_lib::triton_vm::vm::VMState;
use tasm_lib::twenty_first::math::b_field_element::BFieldElement;
use tasm_lib::Digest;
use tracing::debug;

use super::environment;

Expand Down Expand Up @@ -50,7 +51,7 @@ where
input: &PublicInput,
nondeterminism: NonDeterminism,
) -> Result<Vec<BFieldElement>, ConsensusError> {
println!(
debug!(
"Running consensus program with input: {}",
input.individual_tokens.iter().map(|b| b.value()).join(",")
);
Expand Down Expand Up @@ -79,7 +80,7 @@ where
match result {
Ok(output) => Ok(output),
Err(error) => {
println!("VM State:\n{}\n\n", error);
debug!("VM State:\n{}\n\n", error);
Err(ConsensusError::TritonVMPanic(
format!("Triton VM failed.\nVMState:\n{}", error),
error.source,
Expand Down Expand Up @@ -241,20 +242,20 @@ pub mod test {
let name = proof_filename(claim);
match try_load_proof_from_disk(claim) {
Some(proof) => {
println!(" - Loaded proof from disk: {name}.");
debug!(" - Loaded proof from disk: {name}.");
proof
}
None => {
println!("Proof not found on disk.");
debug!("Proof not found on disk.");
match try_fetch_and_verify_proof_from_server(claim) {
Some(proof) => proof,
None => {
println!("Proof not found on proof servers - Proving locally ... ");
debug!("Proof not found on proof servers - Proving locally ... ");
stdout().flush().expect("could not flush terminal");
let tick = SystemTime::now();
let proof = produce_and_save_proof(claim, program, nondeterminism);
let duration = SystemTime::now().duration_since(tick).unwrap();
println!(
debug!(
"success! Proof time: {:?}. Proof stored to disk: {name}",
duration
);
Expand All @@ -269,23 +270,23 @@ pub mod test {
fn try_load_proof_from_disk(claim: &Claim) -> Option<Proof> {
let path = proof_path(claim);
let Ok(mut input_file) = File::open(path.clone()) else {
println!(
debug!(
"cannot open file '{}' -- might not exist",
path.to_string_lossy()
);
return None;
};
let mut file_contents = vec![];
if input_file.read_to_end(&mut file_contents).is_err() {
println!("cannot read file '{}'", path.to_string_lossy());
debug!("cannot read file '{}'", path.to_string_lossy());
return None;
}
let mut proof_data = vec![];
for ch in file_contents.chunks(8) {
if let Ok(eight_bytes) = TryInto::<[u8; 8]>::try_into(ch) {
proof_data.push(BFieldElement::new(u64::from_be_bytes(eight_bytes)));
} else {
println!("cannot cast chunk to eight bytes");
debug!("cannot cast chunk to eight bytes");
return None;
}
}
Expand All @@ -299,19 +300,19 @@ pub mod test {
server_list_path.push(TEST_DATA_DIR);
server_list_path.push(Path::new("proof_servers").with_extension("txt"));
let Ok(mut input_file) = File::open(server_list_path.clone()) else {
println!(
debug!(
"cannot proof-server list '{}' -- file might not exist",
server_list_path.to_string_lossy()
);
return vec![];
};
let mut file_contents = vec![];
if input_file.read_to_end(&mut file_contents).is_err() {
println!("cannot read file '{}'", server_list_path.to_string_lossy());
debug!("cannot read file '{}'", server_list_path.to_string_lossy());
return vec![];
}
let Ok(file_as_string) = String::from_utf8(file_contents) else {
println!(
debug!(
"cannot parse file '{}' -- is it valid utf8?",
server_list_path.to_string_lossy()
);
Expand Down
4 changes: 2 additions & 2 deletions src/models/state/networking_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::net::SocketAddr;
use anyhow::Result;
use num_traits::Zero;
use sysinfo::System;
use tracing::info;

use super::tx_proving_capability::TxProvingCapability;
use crate::config_models::data_directory::DataDirectory;
Expand Down Expand Up @@ -50,10 +51,9 @@ impl NetworkingState {
syncing: bool,
tx_proving_capability: Option<TxProvingCapability>,
) -> Self {
println!("{tx_proving_capability:?}");
let tx_proving_capability =
tx_proving_capability.unwrap_or_else(Self::estimate_proving_power);
println!("{tx_proving_capability:?}");
info!("transaction proving capability set to {tx_proving_capability:?}");
Self {
peer_map,
peer_databases,
Expand Down

0 comments on commit 1f570ec

Please sign in to comment.