diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index ef076133..8f647333 100644 --- a/deploy/docker-compose.yml +++ b/deploy/docker-compose.yml @@ -9,7 +9,6 @@ services: target: secrets.json env_file: .env environment: - RUST_LOG: "info" AGGREGATOR: "false" ADDRESS: "0xbDA5747bFD65F08deb54cb465eB87D40e51B197E" QUIC_PORT: 9091 @@ -29,7 +28,6 @@ services: target: secrets.json env_file: .env environment: - RUST_LOG: "info" AGGREGATOR: "false" ADDRESS: "0xdD2FD4581271e230360230F9337D5c0430Bf44C0" QUIC_PORT: 9092 @@ -49,7 +47,6 @@ services: target: secrets.json env_file: .env environment: - RUST_LOG: "info" AGGREGATOR: "false" ADDRESS: "0x2546BcD3c84621e976D8185a91A922aE77ECEc30" QUIC_PORT: 9093 @@ -71,7 +68,6 @@ services: target: secrets.json env_file: .env environment: - RUST_LOG: "info" AGGREGATOR: "true" ADDRESS: "0x8626a6940E2eb28930eFb4CeF49B2d1F2C9C1199" QUIC_PORT: 9094 diff --git a/packages/ciphernode/Dockerfile b/packages/ciphernode/Dockerfile index ab6b043b..d4782f46 100644 --- a/packages/ciphernode/Dockerfile +++ b/packages/ciphernode/Dockerfile @@ -80,7 +80,6 @@ COPY --from=ciphernode-builder --chmod=755 --chown=ciphernode:ciphernode /build/ # Environment variables for configuration ENV CONFIG_DIR=/home/ciphernode/.config/enclave ENV DATA_DIR=/home/ciphernode/.local/share/enclave -ENV RUST_LOG=info # Add entrypoint script ENTRYPOINT ["ciphernode-entrypoint.sh"] diff --git a/packages/ciphernode/README.md b/packages/ciphernode/README.md index 9e998890..e41c9a97 100644 --- a/packages/ciphernode/README.md +++ b/packages/ciphernode/README.md @@ -83,33 +83,27 @@ sequenceDiagram # Debugging -You can debug using the `RUST_LOG` environment var to alter what output is produced by the node +You can debug using the `-vvv` cli arguments to alter what output is produced by the node ``` -RUST_LOG=info enclave start +# Show INFO logging +enclave start ``` -if you supply a tag as an argument you can filter for that tag +``` +# Show DEBUG logging +enclave start -v +``` ``` -RUST_LOG="[sortition{id=cn1}]" enclave start --tag cn1 +# Show TRACE logging +enclave start -vv ``` -This helps filter noise during tests where you might have multiple instances running and you need to see the output of a specific one. +if you want to remove all output aside from errors you can use the `--quiet` argument. -In order to add tracing to a method or function it is recommended to use the `instrument` macro. -```rust -impl Sorition { - // ... - #[instrument(name="sortition", skip_all, fields(id = get_tag()))] - pub async fn attach( - bus: &Addr, - store: Repository, - ) -> Result> { - // ... - } -} ``` - +enclave --quiet +``` diff --git a/packages/ciphernode/ciphernode-entrypoint.sh b/packages/ciphernode/ciphernode-entrypoint.sh index 917b8411..9ed6f087 100644 --- a/packages/ciphernode/ciphernode-entrypoint.sh +++ b/packages/ciphernode/ciphernode-entrypoint.sh @@ -40,10 +40,10 @@ if [ "$AGGREGATOR" = "true" ]; then enclave wallet set --config "$CONFIG_FILE" --private-key "$PRIVATE_KEY" echo "Starting aggregator" - exec enclave aggregator start --config "$CONFIG_FILE" + exec enclave aggregator start -v --config "$CONFIG_FILE" else echo "Starting Ciphernode" - exec enclave start --config "$CONFIG_FILE" + exec enclave start -v --config "$CONFIG_FILE" fi diff --git a/packages/ciphernode/enclave/src/aggregator_start.rs b/packages/ciphernode/enclave/src/aggregator_start.rs index 326dc8cb..56d34107 100644 --- a/packages/ciphernode/enclave/src/aggregator_start.rs +++ b/packages/ciphernode/enclave/src/aggregator_start.rs @@ -1,12 +1,11 @@ use anyhow::*; use config::AppConfig; use enclave_core::{aggregator_start, listen_for_shutdown}; -use events::get_tag; use tracing::{info, instrument}; use crate::owo; -#[instrument(name="app", skip_all,fields(id = get_tag()))] +#[instrument(name = "app", skip_all)] pub async fn execute( config: AppConfig, pubkey_write_path: Option<&str>, diff --git a/packages/ciphernode/enclave/src/cli.rs b/packages/ciphernode/enclave/src/cli.rs index 72674d19..0f7abc00 100644 --- a/packages/ciphernode/enclave/src/cli.rs +++ b/packages/ciphernode/enclave/src/cli.rs @@ -5,10 +5,9 @@ use crate::wallet::WalletCommands; use crate::{aggregator, init, password, wallet}; use crate::{aggregator::AggregatorCommands, start}; use anyhow::Result; -use clap::{command, Parser, Subcommand}; +use clap::{command, ArgAction, Parser, Subcommand}; use config::load_config; -use events::get_tag; -use tracing::instrument; +use tracing::{instrument, Level}; #[derive(Parser, Debug)] #[command(name = "enclave")] @@ -21,12 +20,48 @@ pub struct Cli { #[command(subcommand)] command: Commands, - #[arg(short, long, global = true)] - tag: Option, + /// Indicate error levels by adding additional `-v` arguments. Eg. `enclave -vvv` will give you + /// trace level output + #[arg( + short, + long, + action = ArgAction::Count, + global = true + )] + pub verbose: u8, + + /// Silence all output. This argument cannot be used alongside `-v` + #[arg( + short, + long, + action = ArgAction::SetTrue, + conflicts_with = "verbose", + global = true + )] + quiet: bool, + + // NOTE: The --tag argument is being left here deliberately so that we can target the aggregator in our tests + // to be killed. We may wish to extend it later to other logging. + /// Tag is not currently used but may be used in the future. + #[arg(long, global = true)] + pub tag: Option, } impl Cli { - #[instrument(skip(self),fields(id = get_tag()))] + pub fn log_level(&self) -> Level { + if self.quiet { + Level::ERROR + } else { + match self.verbose { + 0 => Level::WARN, // + 1 => Level::INFO, // -v + 2 => Level::DEBUG, // -vv + _ => Level::TRACE, // -vvv + } + } + } + + #[instrument(skip(self))] pub async fn execute(self) -> Result<()> { let config_path = self.config.as_deref(); let config = load_config(config_path)?; @@ -59,14 +94,6 @@ impl Cli { Ok(()) } - - pub fn get_tag(&self) -> String { - if let Some(tag) = self.tag.clone() { - tag - } else { - "default".to_string() - } - } } #[derive(Subcommand, Debug)] diff --git a/packages/ciphernode/enclave/src/init.rs b/packages/ciphernode/enclave/src/init.rs index 0c36edd5..81c99cc9 100644 --- a/packages/ciphernode/enclave/src/init.rs +++ b/packages/ciphernode/enclave/src/init.rs @@ -1,7 +1,6 @@ use anyhow::Result; use dialoguer::{theme::ColorfulTheme, Input}; use enclave_core::init; -use events::get_tag; use tracing::instrument; use crate::net; @@ -9,7 +8,7 @@ use crate::net::NetCommands; use crate::password; use crate::password::PasswordCommands; -#[instrument(name = "app", skip_all, fields(id = get_tag()))] +#[instrument(name = "app", skip_all)] pub async fn execute( rpc_url: Option, eth_address: Option, diff --git a/packages/ciphernode/enclave/src/main.rs b/packages/ciphernode/enclave/src/main.rs index 8e344196..6e65ade9 100644 --- a/packages/ciphernode/enclave/src/main.rs +++ b/packages/ciphernode/enclave/src/main.rs @@ -1,7 +1,6 @@ use clap::Parser; use cli::Cli; -use events::set_tag; -use tracing::info; +use tracing::{info, Level}; use tracing_subscriber::EnvFilter; mod aggregator; @@ -43,18 +42,12 @@ pub fn owo() { #[actix::main] pub async fn main() { - tracing_subscriber::fmt() - .with_env_filter(EnvFilter::from_default_env()) - .init(); - info!("COMPILATION ID: '{}'", helpers::compile_id::generate_id()); let cli = Cli::parse(); - - // Set the tag for all future traces - if let Err(err) = set_tag(cli.get_tag()) { - eprintln!("{}", err); - } + tracing_subscriber::fmt() + .with_max_level(cli.log_level()) + .init(); // Execute the cli if let Err(err) = cli.execute().await { diff --git a/packages/ciphernode/enclave/src/password_create.rs b/packages/ciphernode/enclave/src/password_create.rs index 46d7ec94..43feb525 100644 --- a/packages/ciphernode/enclave/src/password_create.rs +++ b/packages/ciphernode/enclave/src/password_create.rs @@ -42,6 +42,7 @@ fn get_zeroizing_pw_vec(input: Option) -> Result>> { } pub async fn execute(config: &AppConfig, input: Option, overwrite: bool) -> Result<()> { + println!("Setting password..."); password_create::preflight(config, overwrite).await?; let pw = get_zeroizing_pw_vec(input)?; diff --git a/packages/ciphernode/enclave/src/start.rs b/packages/ciphernode/enclave/src/start.rs index 4a2abb03..79a89f79 100644 --- a/packages/ciphernode/enclave/src/start.rs +++ b/packages/ciphernode/enclave/src/start.rs @@ -2,10 +2,9 @@ use crate::owo; use anyhow::{anyhow, Result}; use config::AppConfig; use enclave_core::{listen_for_shutdown, start}; -use events::get_tag; use tracing::{info, instrument}; -#[instrument(name="app", skip_all,fields(id = get_tag()))] +#[instrument(name = "app", skip_all)] pub async fn execute(config: AppConfig) -> Result<()> { owo(); let Some(address) = config.address() else { diff --git a/packages/ciphernode/enclave_core/src/init.rs b/packages/ciphernode/enclave_core/src/init.rs index 7b949ec1..d4531cfe 100644 --- a/packages/ciphernode/enclave_core/src/init.rs +++ b/packages/ciphernode/enclave_core/src/init.rs @@ -3,7 +3,6 @@ use anyhow::{anyhow, bail, Result}; use config::load_config; use config::AppConfig; use config::RPC; -use events::get_tag; use std::fs; use tracing::instrument; @@ -31,7 +30,7 @@ pub fn validate_eth_address(address: &String) -> Result<()> { } } -#[instrument(name = "app", skip_all, fields(id = get_tag()))] +#[instrument(name = "app", skip_all)] pub async fn execute(rpc_url: String, eth_address: Option) -> Result { let config_dir = dirs::home_dir() .ok_or_else(|| anyhow!("Could not determine home directory"))? diff --git a/packages/ciphernode/enclave_core/src/start.rs b/packages/ciphernode/enclave_core/src/start.rs index cc94db08..2a76bd24 100644 --- a/packages/ciphernode/enclave_core/src/start.rs +++ b/packages/ciphernode/enclave_core/src/start.rs @@ -5,7 +5,7 @@ use config::AppConfig; use crypto::Cipher; use data::RepositoriesFactory; use e3_request::E3Router; -use events::{get_tag, EventBus}; +use events::EventBus; use evm::{ helpers::ProviderConfig, CiphernodeRegistryReaderRepositoryFactory, CiphernodeRegistrySol, EnclaveSolReader, EnclaveSolReaderRepositoryFactory, @@ -25,7 +25,7 @@ use tracing::instrument; use crate::helpers::datastore::setup_datastore; -#[instrument(name="app", skip_all,fields(id = get_tag()))] +#[instrument(name = "app", skip_all)] pub async fn execute( config: AppConfig, address: Address, diff --git a/packages/ciphernode/events/src/lib.rs b/packages/ciphernode/events/src/lib.rs index fa787cb2..13cf2c47 100644 --- a/packages/ciphernode/events/src/lib.rs +++ b/packages/ciphernode/events/src/lib.rs @@ -4,7 +4,6 @@ mod event_id; mod eventbus; mod ordered_set; mod seed; -mod tag; pub use e3id::*; pub use enclave_event::*; @@ -12,4 +11,3 @@ pub use event_id::*; pub use eventbus::*; pub use ordered_set::*; pub use seed::*; -pub use tag::*; diff --git a/packages/ciphernode/events/src/tag.rs b/packages/ciphernode/events/src/tag.rs deleted file mode 100644 index 7b67ebba..00000000 --- a/packages/ciphernode/events/src/tag.rs +++ /dev/null @@ -1,21 +0,0 @@ -//! Tag management for EVM event processing. -//! -//! This module provides thread-safe access to a global string tag that's used to -//! differentiate between different EVM contract instances during event processing. -//! The tag helps track and manage historical and live events for specific contracts. - -use std::sync::OnceLock; - -/// Global tag for contract event tracking with a default value of "_". -/// This tag is initialized once and remains constant throughout the lifecycle -/// of event processing to ensure consistent event tracking across restarts. -static TAG: OnceLock = OnceLock::new(); - -pub fn get_tag() -> String { - TAG.get().cloned().unwrap_or_else(|| String::from("_")) -} - -pub fn set_tag(new_tag: impl Into) -> Result<(), &'static str> { - TAG.set(new_tag.into()) - .map_err(|_| "Tag has already been initialized") -} diff --git a/packages/ciphernode/evm/src/event_reader.rs b/packages/ciphernode/evm/src/event_reader.rs index b279e126..1b873892 100644 --- a/packages/ciphernode/evm/src/event_reader.rs +++ b/packages/ciphernode/evm/src/event_reader.rs @@ -9,7 +9,7 @@ use alloy::rpc::types::Filter; use alloy::transports::{BoxTransport, Transport}; use anyhow::{anyhow, Result}; use data::{AutoPersist, Persistable, Repository}; -use events::{get_tag, BusError, EnclaveErrorType, EnclaveEvent, EventBus, EventId, Subscribe}; +use events::{BusError, EnclaveErrorType, EnclaveEvent, EventBus, EventId, Subscribe}; use futures_util::stream::StreamExt; use std::collections::HashSet; use tokio::select; @@ -35,8 +35,6 @@ impl EnclaveEvmEvent { pub type ExtractorFn = fn(&LogData, Option<&B256>, u64) -> Option; -pub type EventReader = EvmEventReader; - pub struct EvmEventReaderParams where P: Provider + Clone + 'static, @@ -151,7 +149,6 @@ where let contract_address = self.contract_address; let start_block = self.start_block; - let tag = get_tag(); ctx.spawn( async move { stream_from_evm( @@ -162,7 +159,6 @@ where shutdown, start_block, &bus, - &tag, ) .await } @@ -171,7 +167,7 @@ where } } -#[instrument(name = "evm_event_reader", skip_all, fields(id=id))] +#[instrument(name = "evm_event_reader", skip_all)] async fn stream_from_evm, T: Transport + Clone>( provider: WithChainId, contract_address: &Address, @@ -180,7 +176,6 @@ async fn stream_from_evm, T: Transport + Clone>( mut shutdown: oneshot::Receiver<()>, start_block: Option, bus: &Addr, - id: &str, ) { let chain_id = provider.get_chain_id(); let provider = provider.get_provider(); @@ -270,7 +265,7 @@ where { type Result = (); - #[instrument(name="evm_event_reader", skip_all, fields(id = get_tag()))] + #[instrument(name = "evm_event_reader", skip_all)] fn handle(&mut self, wrapped: EnclaveEvmEvent, _: &mut Self::Context) -> Self::Result { match self.state.try_mutate(|mut state| { let event_id = wrapped.get_id(); diff --git a/packages/ciphernode/sortition/src/sortition.rs b/packages/ciphernode/sortition/src/sortition.rs index c0b0f569..6dab3ff1 100644 --- a/packages/ciphernode/sortition/src/sortition.rs +++ b/packages/ciphernode/sortition/src/sortition.rs @@ -4,8 +4,8 @@ use alloy::primitives::Address; use anyhow::{anyhow, Result}; use data::{AutoPersist, Persistable, Repository}; use events::{ - get_tag, BusError, CiphernodeAdded, CiphernodeRemoved, EnclaveErrorType, EnclaveEvent, - EventBus, Seed, Subscribe, + BusError, CiphernodeAdded, CiphernodeRemoved, EnclaveErrorType, EnclaveEvent, EventBus, Seed, + Subscribe, }; use std::collections::HashSet; use tracing::{info, instrument}; @@ -104,7 +104,7 @@ impl Sortition { } } - #[instrument(name="sortition", skip_all, fields(id = get_tag()))] + #[instrument(name = "sortition", skip_all)] pub async fn attach( bus: &Addr, store: Repository, @@ -142,7 +142,7 @@ impl Handler for Sortition { impl Handler for Sortition { type Result = (); - #[instrument(name="sortition", skip_all, fields(id = get_tag()))] + #[instrument(name = "sortition", skip_all)] fn handle(&mut self, msg: CiphernodeAdded, _ctx: &mut Self::Context) -> Self::Result { info!("Adding node: {}", msg.address); match self.list.try_mutate(|mut list| { @@ -158,7 +158,7 @@ impl Handler for Sortition { impl Handler for Sortition { type Result = (); - #[instrument(name="sortition", skip_all, fields(id = get_tag()))] + #[instrument(name = "sortition", skip_all)] fn handle(&mut self, msg: CiphernodeRemoved, _ctx: &mut Self::Context) -> Self::Result { info!("Removing node: {}", msg.address); match self.list.try_mutate(|mut list| { @@ -174,7 +174,7 @@ impl Handler for Sortition { impl Handler for Sortition { type Result = bool; - #[instrument(name="sortition", skip_all, fields(id = get_tag()))] + #[instrument(name = "sortition", skip_all)] fn handle(&mut self, msg: GetHasNode, _ctx: &mut Self::Context) -> Self::Result { self.list .try_with(|list| list.contains(msg.seed, msg.size, msg.address)) diff --git a/tests/basic_integration/fns.sh b/tests/basic_integration/fns.sh index be24e90a..f44fee0b 100644 --- a/tests/basic_integration/fns.sh +++ b/tests/basic_integration/fns.sh @@ -38,6 +38,7 @@ NETWORK_PRIVATE_KEY_2="0x21a1e500a548b70d88184a1e042900c0ed6c57f8710bcc35dc8c85f NETWORK_PRIVATE_KEY_3="0x31a1e500a548b70d88184a1e042900c0ed6c57f8710bcc35dc8c85fa33d3f580" NETWORK_PRIVATE_KEY_4="0x41a1e500a548b70d88184a1e042900c0ed6c57f8710bcc35dc8c85fa33d3f580" +ENCLAVE_BIN=./packages/ciphernode/target/debug/enclave # Function to clean up background processes cleanup() { @@ -87,24 +88,28 @@ waiton-files() { set_password() { local name="$1" local password="$2" - yarn enclave password create \ + $ENCLAVE_BIN password create \ --config "$SCRIPT_DIR/lib/$name/config.yaml" \ --password "$password" } launch_ciphernode() { - local name="$1" - heading "Launch ciphernode $name" - yarn enclave start \ - --tag "$name" \ - --config "$SCRIPT_DIR/lib/$name/config.yaml" & echo $! > "/tmp/enclave.${ID}_${name}.pid" + local name="$1" + local log_file="${SCRIPT_DIR}/logs/${name}.log" + local log_dir="$(dirname "$log_file")" + heading "Launch ciphernode $name" + # Make sure the logs directory exists + mkdir -p "$log_dir" + $ENCLAVE_BIN start -v \ + --tag "$name" \ + --config "$SCRIPT_DIR/lib/$name/config.yaml" 2>&1 | tee "$log_file" & echo $! > "/tmp/enclave.${ID}_${name}.pid" } set_private_key() { local name="$1" local private_key="$2" - yarn enclave wallet set \ + $ENCLAVE_BIN wallet set \ --config "$SCRIPT_DIR/lib/$name/config.yaml" \ --private-key "$private_key" } @@ -113,22 +118,25 @@ set_network_private_key() { local name="$1" local private_key="$2" - yarn enclave net set-key \ + $ENCLAVE_BIN net set-key \ --config "$SCRIPT_DIR/lib/$name/config.yaml" \ --net-keypair "$private_key" } launch_aggregator() { - local name="$1" - heading "Launch aggregator $name" - - yarn enclave aggregator start \ - --tag "$name" \ - --config "$SCRIPT_DIR/lib/$name/config.yaml" \ - --pubkey-write-path "$SCRIPT_DIR/output/pubkey.bin" \ - --plaintext-write-path "$SCRIPT_DIR/output/plaintext.txt" & echo $! > "/tmp/enclave.${ID}_${name}.pid" - - ps aux | grep aggregator + local name="$1" + local suffix="${2:-}" # Optional suffix with empty default + local log_name="${name}${suffix:+_$suffix}" # Add suffix with underscore if provided + local log_file="${SCRIPT_DIR}/logs/${log_name}.log" + local log_dir="$(dirname "$log_file")" + heading "Launch aggregator $name" + # Make sure the logs directory exists + mkdir -p "$log_dir" + $ENCLAVE_BIN aggregator start -v \ + --tag "$name" \ + --config "$SCRIPT_DIR/lib/$name/config.yaml" \ + --pubkey-write-path "$SCRIPT_DIR/output/pubkey.bin" \ + --plaintext-write-path "$SCRIPT_DIR/output/plaintext.txt" 2>&1 | tee "$log_file" & echo $! > "/tmp/enclave.${ID}_${name}.pid" } kill_proc() { diff --git a/tests/basic_integration/lib/fake_encrypt.sh b/tests/basic_integration/lib/fake_encrypt.sh index 512a99ad..f8e8c6a1 100755 --- a/tests/basic_integration/lib/fake_encrypt.sh +++ b/tests/basic_integration/lib/fake_encrypt.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -cd packages/ciphernode && RUSTFLAGS="-A warnings" cargo run --bin fake_encrypt -- "$@" +./packages/ciphernode/target/debug/fake_encrypt "$@" diff --git a/tests/basic_integration/lib/prebuild.sh b/tests/basic_integration/lib/prebuild.sh index fb9bfe7c..33c7ce39 100755 --- a/tests/basic_integration/lib/prebuild.sh +++ b/tests/basic_integration/lib/prebuild.sh @@ -1,3 +1,3 @@ #!/usr/bin/env sh -cd packages/ciphernode && RUSTFLAGS="-A warnings" cargo build --bin fake_encrypt --bin enclave --bin pack_e3_params; +cd packages/ciphernode && cargo build --bin fake_encrypt --bin enclave --bin pack_e3_params; diff --git a/tests/basic_integration/logs/.gitignore b/tests/basic_integration/logs/.gitignore new file mode 100644 index 00000000..397b4a76 --- /dev/null +++ b/tests/basic_integration/logs/.gitignore @@ -0,0 +1 @@ +*.log diff --git a/tests/basic_integration/persist.sh b/tests/basic_integration/persist.sh index 6372e6ee..6f795e20 100755 --- a/tests/basic_integration/persist.sh +++ b/tests/basic_integration/persist.sh @@ -68,7 +68,7 @@ kill_proc ag sleep 2 # relaunch the aggregator -launch_aggregator ag +launch_aggregator ag relaunch sleep 2