Skip to content

Commit

Permalink
Remove tag and set info as default (#232)
Browse files Browse the repository at this point in the history
* Remove tag

* Update docs

* Update comment

* Use binaries instead of running through cargo

* Extract logs to separate files

* Update warnings
  • Loading branch information
ryardley authored Dec 31, 2024
1 parent 76b76e1 commit 72e4a57
Show file tree
Hide file tree
Showing 21 changed files with 105 additions and 118 deletions.
4 changes: 0 additions & 4 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ services:
target: secrets.json
env_file: .env
environment:
RUST_LOG: "info"
AGGREGATOR: "false"
ADDRESS: "0xbDA5747bFD65F08deb54cb465eB87D40e51B197E"
QUIC_PORT: 9091
Expand All @@ -29,7 +28,6 @@ services:
target: secrets.json
env_file: .env
environment:
RUST_LOG: "info"
AGGREGATOR: "false"
ADDRESS: "0xdD2FD4581271e230360230F9337D5c0430Bf44C0"
QUIC_PORT: 9092
Expand All @@ -49,7 +47,6 @@ services:
target: secrets.json
env_file: .env
environment:
RUST_LOG: "info"
AGGREGATOR: "false"
ADDRESS: "0x2546BcD3c84621e976D8185a91A922aE77ECEc30"
QUIC_PORT: 9093
Expand All @@ -71,7 +68,6 @@ services:
target: secrets.json
env_file: .env
environment:
RUST_LOG: "info"
AGGREGATOR: "true"
ADDRESS: "0x8626a6940E2eb28930eFb4CeF49B2d1F2C9C1199"
QUIC_PORT: 9094
Expand Down
1 change: 0 additions & 1 deletion packages/ciphernode/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
30 changes: 12 additions & 18 deletions packages/ciphernode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<EventBus>,
store: Repository<SortitionModule>,
) -> Result<Addr<Sortition>> {
// ...
}
}
```

enclave --quiet
```
4 changes: 2 additions & 2 deletions packages/ciphernode/ciphernode-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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


3 changes: 1 addition & 2 deletions packages/ciphernode/enclave/src/aggregator_start.rs
Original file line number Diff line number Diff line change
@@ -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>,
Expand Down
55 changes: 41 additions & 14 deletions packages/ciphernode/enclave/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -21,12 +20,48 @@ pub struct Cli {
#[command(subcommand)]
command: Commands,

#[arg(short, long, global = true)]
tag: Option<String>,
/// 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<String>,
}

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)?;
Expand Down Expand Up @@ -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)]
Expand Down
3 changes: 1 addition & 2 deletions packages/ciphernode/enclave/src/init.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use anyhow::Result;
use dialoguer::{theme::ColorfulTheme, Input};
use enclave_core::init;
use events::get_tag;
use tracing::instrument;

use crate::net;
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<String>,
eth_address: Option<String>,
Expand Down
15 changes: 4 additions & 11 deletions packages/ciphernode/enclave/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions packages/ciphernode/enclave/src/password_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fn get_zeroizing_pw_vec(input: Option<String>) -> Result<Zeroizing<Vec<u8>>> {
}

pub async fn execute(config: &AppConfig, input: Option<String>, overwrite: bool) -> Result<()> {
println!("Setting password...");
password_create::preflight(config, overwrite).await?;

let pw = get_zeroizing_pw_vec(input)?;
Expand Down
3 changes: 1 addition & 2 deletions packages/ciphernode/enclave/src/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions packages/ciphernode/enclave_core/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String>) -> Result<AppConfig> {
let config_dir = dirs::home_dir()
.ok_or_else(|| anyhow!("Could not determine home directory"))?
Expand Down
4 changes: 2 additions & 2 deletions packages/ciphernode/enclave_core/src/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions packages/ciphernode/events/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ mod event_id;
mod eventbus;
mod ordered_set;
mod seed;
mod tag;

pub use e3id::*;
pub use enclave_event::*;
pub use event_id::*;
pub use eventbus::*;
pub use ordered_set::*;
pub use seed::*;
pub use tag::*;
21 changes: 0 additions & 21 deletions packages/ciphernode/events/src/tag.rs

This file was deleted.

11 changes: 3 additions & 8 deletions packages/ciphernode/evm/src/event_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,8 +35,6 @@ impl EnclaveEvmEvent {

pub type ExtractorFn<E> = fn(&LogData, Option<&B256>, u64) -> Option<E>;

pub type EventReader = EvmEventReader<ReadonlyProvider>;

pub struct EvmEventReaderParams<P, T>
where
P: Provider<T> + Clone + 'static,
Expand Down Expand Up @@ -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(
Expand All @@ -162,7 +159,6 @@ where
shutdown,
start_block,
&bus,
&tag,
)
.await
}
Expand All @@ -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<P: Provider<T>, T: Transport + Clone>(
provider: WithChainId<P, T>,
contract_address: &Address,
Expand All @@ -180,7 +176,6 @@ async fn stream_from_evm<P: Provider<T>, T: Transport + Clone>(
mut shutdown: oneshot::Receiver<()>,
start_block: Option<u64>,
bus: &Addr<EventBus>,
id: &str,
) {
let chain_id = provider.get_chain_id();
let provider = provider.get_provider();
Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 72e4a57

Please sign in to comment.