Skip to content

Commit

Permalink
Replace println with tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
ryardley committed Oct 10, 2024
1 parent fe4a927 commit 1c1dd5a
Show file tree
Hide file tree
Showing 29 changed files with 121 additions and 143 deletions.
7 changes: 7 additions & 0 deletions packages/ciphernode/Cargo.lock

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

1 change: 1 addition & 0 deletions packages/ciphernode/aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ bincode = { workspace = true }
enclave-core = { path = "../core" }
fhe = { path = "../fhe" }
sortition = { path = "../sortition" }
tracing = { workspace = true }
7 changes: 4 additions & 3 deletions packages/ciphernode/aggregator/src/plaintext_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use enclave_core::{
use fhe::{Fhe, GetAggregatePlaintext};
use sortition::{GetHasNode, Sortition};
use std::sync::Arc;
use tracing::error;

#[derive(Debug, Clone)]
pub enum PlaintextAggregatorState {
Expand Down Expand Up @@ -124,7 +125,7 @@ impl Handler<DecryptionshareCreated> for PlaintextAggregator {
threshold_m, seed, ..
} = self.state
else {
println!("Aggregator has been closed for collecting.");
error!(state=?self.state, "Aggregator has been closed for collecting.");
return Box::pin(fut::ready(Ok(())));
};

Expand All @@ -144,12 +145,12 @@ impl Handler<DecryptionshareCreated> for PlaintextAggregator {
.map(move |res, act, ctx| {
let has_node = res?;
if !has_node {
println!("Node not found in committee"); // TODO: log properly
error!("Node not found in committee");
return Ok(());
}

if e3_id != act.e3_id {
println!("Wrong e3_id sent to aggregator. This should not happen.");
error!("Wrong e3_id sent to aggregator. This should not happen.");
return Ok(());
}

Expand Down
8 changes: 4 additions & 4 deletions packages/ciphernode/aggregator/src/publickey_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use enclave_core::{
use fhe::{Fhe, GetAggregatePublicKey};
use sortition::{GetHasNode, GetNodes, Sortition};
use std::sync::Arc;
use tracing::error;

#[derive(Debug, Clone)]
pub enum PublicKeyAggregatorState {
Expand Down Expand Up @@ -132,8 +133,7 @@ impl Handler<KeyshareCreated> for PublicKeyAggregator {
threshold_m, seed, ..
} = self.state.clone()
else {
println!("Aggregator has been closed for collecting keyshares."); // TODO: log properly

error!(state=?self.state, "Aggregator has been closed for collecting keyshares.");
return Box::pin(fut::ready(Ok(())));
};

Expand All @@ -155,12 +155,12 @@ impl Handler<KeyshareCreated> for PublicKeyAggregator {
// we will not be doing a send
let has_node = res?;
if !has_node {
println!("Node not found in committee"); // TODO: log properly
error!("Node not found in committee");
return Ok(());
}

if e3_id != act.e3_id {
println!("Wrong e3_id sent to aggregator. This should not happen.");
error!("Wrong e3_id sent to aggregator. This should not happen.");
return Ok(());
}

Expand Down
1 change: 1 addition & 0 deletions packages/ciphernode/core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ pub enum EnclaveErrorType {
IO,
PlaintextAggregation,
Decryption,
Sortition
}

impl EnclaveError {
Expand Down
1 change: 1 addition & 0 deletions packages/ciphernode/enclave/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ actix-rt = { workspace = true }
tokio = { workspace = true }
config = "0.14.0"
tracing-subscriber = { workspace = true }
tracing = { workspace = true }
3 changes: 2 additions & 1 deletion packages/ciphernode/enclave/src/bin/aggregator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::Parser;
use enclave::load_config;
use enclave_node::MainAggregator;
use tracing::info;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand All @@ -20,7 +21,7 @@ struct Args {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
let args = Args::parse();
println!("LAUNCHING AGGREGATOR");
info!("LAUNCHING AGGREGATOR");
let config = load_config(&args.config)?;
let (_, handle) = MainAggregator::attach(
config,
Expand Down
3 changes: 2 additions & 1 deletion packages/ciphernode/enclave/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use alloy::primitives::Address;
use clap::Parser;
use enclave::load_config;
use enclave_node::MainCiphernode;
use tracing::info;

const OWO: &str = r#"
___ ___ ___ ___ ___
Expand Down Expand Up @@ -34,7 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("\n\n\n\n");
let args = Args::parse();
let address = Address::parse_checksummed(&args.address, None).expect("Invalid address");
println!("LAUNCHING CIPHERNODE: ({})", address);
info!("LAUNCHING CIPHERNODE: ({})", address);
let config = load_config(&args.config)?;
let (_, handle) = MainCiphernode::attach(config, address).await?;
let _ = tokio::join!(handle);
Expand Down
68 changes: 0 additions & 68 deletions packages/ciphernode/enclave_node/src/main.rs

This file was deleted.

1 change: 1 addition & 0 deletions packages/ciphernode/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ enclave-core = { path = "../core" }
futures-util = { workspace = true }
sortition = { path = "../sortition" }
tokio = { workspace = true }
tracing = { workspace = true }
14 changes: 9 additions & 5 deletions packages/ciphernode/evm/src/ciphernode_registry_sol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use alloy::{
};
use anyhow::Result;
use enclave_core::{EnclaveEvent, EventBus};
use tracing::{error, info, trace};

use crate::helpers::{self, create_readonly_provider, ReadonlyProvider};

Expand Down Expand Up @@ -69,22 +70,25 @@ fn extractor(data: &LogData, topic: Option<&B256>, _: u64) -> Option<EnclaveEven
Some(&ICiphernodeRegistry::CiphernodeAdded::SIGNATURE_HASH) => {
let Ok(event) = ICiphernodeRegistry::CiphernodeAdded::decode_log_data(data, true)
else {
println!("Error parsing event CiphernodeAdded"); // TODO: provide more info
error!("Error parsing event CiphernodeAdded after topic was matched!");
return None;
};
Some(EnclaveEvent::from(event))
}
Some(&ICiphernodeRegistry::CiphernodeRemoved::SIGNATURE_HASH) => {
let Ok(event) = ICiphernodeRegistry::CiphernodeRemoved::decode_log_data(data, true)
else {
println!("Error parsing event CiphernodeRemoved"); // TODO: provide more info
error!("Error parsing event CiphernodeRemoved after topic was matched!");
return None;
};
Some(EnclaveEvent::from(event))
}

_ => {
println!("Unknown event");
_topic => {
trace!(
topic=?_topic,
"Unknown event was received by Enclave.sol parser buut was ignored"
);
return None;
}
}
Expand Down Expand Up @@ -122,7 +126,7 @@ impl CiphernodeRegistrySolReader {
.await?
.start();

println!("CiphernodeRegistrySol is listening to {}", contract_address);
info!(address=%contract_address, "CiphernodeRegistrySol is listening to address");
Ok(addr)
}
}
Expand Down
14 changes: 9 additions & 5 deletions packages/ciphernode/evm/src/enclave_sol_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use alloy::{
};
use anyhow::Result;
use enclave_core::{EnclaveEvent, EventBus};
use tracing::{error, info, trace};

sol!(
#[sol(rpc)]
Expand Down Expand Up @@ -55,21 +56,24 @@ fn extractor(data: &LogData, topic: Option<&B256>, chain_id: u64) -> Option<Encl
match topic {
Some(&IEnclave::E3Requested::SIGNATURE_HASH) => {
let Ok(event) = IEnclave::E3Requested::decode_log_data(data, true) else {
println!("Error parsing event E3Requested"); // TODO: provide more info
error!("Error parsing event E3Requested after topic matched!");
return None;
};
Some(EnclaveEvent::from(E3RequestedWithChainId(event, chain_id)))
}
Some(&IEnclave::CiphertextOutputPublished::SIGNATURE_HASH) => {
let Ok(event) = IEnclave::CiphertextOutputPublished::decode_log_data(data, true) else {
println!("Error parsing event CiphertextOutputPublished"); // TODO: provide more info
error!("Error parsing event CiphertextOutputPublished after topic matched!"); // TODO: provide more info
return None;
};
Some(EnclaveEvent::from(event))
}

_ => {
println!("Unknown event");
_topic => {
trace!(
topic=?_topic,
"Unknown event was received by Enclave.sol parser buut was ignored"
);
return None;
}
}
Expand Down Expand Up @@ -105,7 +109,7 @@ impl EnclaveSolReader {
.await?
.start();

println!("Evm is listening to {}", contract_address);
info!(address=%contract_address, "Evm is listening to address");
Ok(addr)
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/ciphernode/evm/src/enclave_sol_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use alloy::{
use anyhow::Result;
use enclave_core::{BusError, E3id, EnclaveErrorType, PlaintextAggregated, Subscribe};
use enclave_core::{EnclaveEvent, EventBus};
use tracing::info;

sol!(
#[sol(rpc)]
Expand Down Expand Up @@ -93,7 +94,7 @@ impl Handler<PlaintextAggregated> for EnclaveSolWriter {
.await;
match result {
Ok(receipt) => {
println!("tx:{}", receipt.transaction_hash)
info!(tx=%receipt.transaction_hash, "tx")
}
Err(err) => bus.err(EnclaveErrorType::Evm, err),
}
Expand Down
4 changes: 4 additions & 0 deletions packages/ciphernode/evm/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use alloy::{
use anyhow::{Context, Result};
use enclave_core::{BusError, EnclaveErrorType, EnclaveEvent};
use futures_util::stream::StreamExt;
use tracing::{info, trace};

pub async fn stream_from_evm<P: Provider>(
provider: WithChainId<P>,
Expand All @@ -31,10 +32,13 @@ pub async fn stream_from_evm<P: Provider>(
Ok(subscription) => {
let mut stream = subscription.into_stream();
while let Some(log) = stream.next().await {
trace!("Received log from EVM");
let Some(event) = extractor(log.data(), log.topic0(), provider.get_chain_id())
else {
trace!("Failed to extract log from EVM");
continue;
};
info!("Extracted log from evm sending now.");
bus.do_send(event);
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/ciphernode/evm/src/registry_filter_sol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use enclave_core::{
BusError, E3id, EnclaveErrorType, EnclaveEvent, EventBus, OrderedSet, PublicKeyAggregated,
Subscribe,
};
use tracing::info;
use std::sync::Arc;

sol!(
Expand Down Expand Up @@ -92,7 +93,7 @@ impl Handler<PublicKeyAggregated> for RegistryFilterSolWriter {
publish_committee(provider, contract_address, e3_id, nodes, pubkey).await;
match result {
Ok(receipt) => {
println!("tx:{}", receipt.transaction_hash);
info!(tx=%receipt.transaction_hash,"tx");
}
Err(err) => bus.err(EnclaveErrorType::Evm, err),
}
Expand Down
Loading

0 comments on commit 1c1dd5a

Please sign in to comment.