From 0199000cbab8ed97305258480f10e77c55da84fe Mon Sep 17 00:00:00 2001 From: jfldde <168934971+jfldde@users.noreply.github.com> Date: Tue, 8 Oct 2024 13:51:25 +0100 Subject: [PATCH 1/3] Log using tracing --- Cargo.toml | 1 + src/bitcoin.rs | 13 +++++++------ src/citrea_config/mod.rs | 4 ++-- src/client.rs | 3 ++- src/docker.rs | 10 ++++------ src/framework.rs | 23 ++++++++++++----------- src/node.rs | 3 ++- src/traits.rs | 3 ++- src/utils.rs | 3 ++- 9 files changed, 34 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f9557b5..611438b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ tempfile = "3.8" tokio = { version = "1.39", features = ["full"] } toml = "0.8.0" which = "6.0.1" +tracing = { version = "0.1.40", default-features = false } # Citrea dependencies sov-ledger-rpc = { git = "https://github.com/chainwayxyz/citrea", rev = "82bf52d", default-features = false, features = ["client"] } diff --git a/src/bitcoin.rs b/src/bitcoin.rs index 39194a9..0e2489b 100644 --- a/src/bitcoin.rs +++ b/src/bitcoin.rs @@ -11,6 +11,7 @@ use bitcoin::Address; use bitcoincore_rpc::{json::AddressType::Bech32m, Auth, Client, RpcApi}; use futures::TryStreamExt; use tokio::{process::Command, sync::OnceCell, time::sleep}; +use tracing::{debug, info, trace}; use super::{ config::BitcoinConfig, @@ -105,7 +106,7 @@ impl BitcoinNode { while start.elapsed() < timeout_duration { if !self.is_process_running().await? { - println!("Bitcoin daemon has stopped successfully"); + info!("Bitcoin daemon has stopped successfully"); return Ok(()); } sleep(Duration::from_millis(200)).await; @@ -182,7 +183,7 @@ impl NodeT for BitcoinNode { fn spawn(config: &Self::Config) -> Result { let args = config.args(); - println!("Running bitcoind with args : {args:?}"); + debug!("Running bitcoind with args : {args:?}"); Command::new("bitcoind") .args(&args) @@ -198,7 +199,7 @@ impl NodeT for BitcoinNode { } async fn wait_for_ready(&self, timeout: Option) -> Result<()> { - println!("Waiting for ready"); + trace!("Waiting for ready"); let start = Instant::now(); let timeout = timeout.unwrap_or(Duration::from_secs(30)); while start.elapsed() < timeout { @@ -210,7 +211,7 @@ impl NodeT for BitcoinNode { } tokio::time::sleep(Duration::from_millis(500)).await; } - anyhow::bail!("Node failed to become ready within the specified timeout") + bail!("Node failed to become ready within the specified timeout") } fn client(&self) -> &Self::Client { @@ -249,7 +250,7 @@ impl Restart for BitcoinNode { .try_collect::>() .await?; env.docker.remove_container(&output.id, None).await?; - println!("Docker container {} succesfully removed", output.id); + info!("Docker container {} succesfully removed", output.id); Ok(()) } } @@ -361,5 +362,5 @@ async fn wait_for_rpc_ready(client: &Client, timeout: Option) -> Resul Err(_) => sleep(Duration::from_millis(500)).await, } } - Err(anyhow::anyhow!("Timeout waiting for RPC to be ready")) + bail!("Timeout waiting for RPC to be ready") } diff --git a/src/citrea_config/mod.rs b/src/citrea_config/mod.rs index 7a9ecf2..687682f 100644 --- a/src/citrea_config/mod.rs +++ b/src/citrea_config/mod.rs @@ -21,8 +21,8 @@ pub fn from_toml_path, R: serde::de::DeserializeOwned> let mut file = File::open(path)?; file.read_to_string(&mut contents)?; } - log::debug!("Config file size: {} bytes", contents.len()); - log::trace!("Config file contents: {}", &contents); + tracing::debug!("Config file size: {} bytes", contents.len()); + tracing::trace!("Config file contents: {}", &contents); let result: R = toml::from_str(&contents)?; diff --git a/src/client.rs b/src/client.rs index a8d3633..d040989 100644 --- a/src/client.rs +++ b/src/client.rs @@ -12,6 +12,7 @@ use sov_rollup_interface::rpc::{ SequencerCommitmentResponse, SoftConfirmationResponse, VerifiedProofResponse, }; use tokio::time::sleep; +use tracing::trace; pub struct Client { client: HttpClient, @@ -97,7 +98,7 @@ impl Client { let start = SystemTime::now(); let timeout = timeout.unwrap_or(Duration::from_secs(30)); // Default 30 seconds timeout loop { - debug!("Waiting for soft confirmation {}", num); + trace!("Waiting for soft confirmation {}", num); let latest_block = self.client.get_head_soft_confirmation_height().await?; if latest_block >= num { diff --git a/src/docker.rs b/src/docker.rs index f30eaec..65f4c5c 100644 --- a/src/docker.rs +++ b/src/docker.rs @@ -17,6 +17,7 @@ use bollard::{ }; use futures::StreamExt; use tokio::{fs::File, io::AsyncWriteExt, task::JoinHandle}; +use tracing::{debug, info}; use super::{config::DockerConfig, traits::SpawnOutput, utils::generate_test_id}; use crate::traits::ContainerSpawnOutput; @@ -91,7 +92,7 @@ impl DockerEnv { } pub async fn spawn(&self, config: DockerConfig) -> Result { - println!("Spawning docker with config {config:#?}"); + debug!("Spawning docker with config {config:#?}"); let exposed_ports: HashMap> = config .ports .iter() @@ -146,9 +147,6 @@ impl DockerEnv { .context("Image not specified in config")?; self.ensure_image_exists(image).await?; - // println!("options :{options:?}"); - // println!("config :{container_config:?}"); - let container = self .docker .create_container::(None, container_config) @@ -196,7 +194,7 @@ impl DockerEnv { return Ok(()); } - println!("Pulling image: {image}"); + info!("Pulling image: {image}..."); let options = Some(CreateImageOptions { from_image: image, ..Default::default() @@ -214,7 +212,7 @@ impl DockerEnv { Err(e) => return Err(anyhow::anyhow!("Failed to pull image: {}", e)), } } - println!("Image succesfully pulled"); + info!("Image succesfully pulled"); Ok(()) } diff --git a/src/framework.rs b/src/framework.rs index a56a480..db39187 100644 --- a/src/framework.rs +++ b/src/framework.rs @@ -1,6 +1,7 @@ use std::{future::Future, sync::Arc}; use bitcoincore_rpc::RpcApi; +use tracing::{debug, info}; use super::{ bitcoin::BitcoinNodeCluster, @@ -119,13 +120,13 @@ impl TestFramework { pub fn show_log_paths(&self) { if self.show_logs { - println!( + info!( "Logs available at {}", self.ctx.config.test_case.dir.display() ); for node in self.get_nodes_as_log_provider() { - println!( + info!( "{} logs available at : {}", node.kind(), node.log_path().display() @@ -135,14 +136,14 @@ impl TestFramework { } pub fn dump_log(&self) -> Result<()> { - println!("Dumping logs:"); + debug!("Dumping logs:"); let n_lines = std::env::var("TAIL_N_LINES") .ok() .and_then(|v| v.parse::().ok()) .unwrap_or(25); for node in self.get_nodes_as_log_provider() { - println!("{} logs (last {n_lines} lines):", node.kind()); + debug!("{} logs (last {n_lines} lines):", node.kind()); if let Err(e) = tail_file(&node.log_path(), n_lines) { eprint!("{e}"); } @@ -151,34 +152,34 @@ impl TestFramework { } pub async fn stop(&mut self) -> Result<()> { - println!("Stopping framework..."); + info!("Stopping framework..."); if let Some(sequencer) = &mut self.sequencer { let _ = sequencer.stop().await; - println!("Successfully stopped sequencer"); + info!("Successfully stopped sequencer"); } if let Some(batch_prover) = &mut self.batch_prover { let _ = batch_prover.stop().await; - println!("Successfully stopped batch_prover"); + info!("Successfully stopped batch_prover"); } if let Some(light_client_prover) = &mut self.light_client_prover { let _ = light_client_prover.stop().await; - println!("Successfully stopped light_client_prover"); + info!("Successfully stopped light_client_prover"); } if let Some(full_node) = &mut self.full_node { let _ = full_node.stop().await; - println!("Successfully stopped full_node"); + info!("Successfully stopped full_node"); } let _ = self.bitcoin_nodes.stop_all().await; - println!("Successfully stopped bitcoin nodes"); + info!("Successfully stopped bitcoin nodes"); if let Some(docker) = self.ctx.docker.as_ref() { let _ = docker.cleanup().await; - println!("Successfully cleaned docker"); + info!("Successfully cleaned docker"); } Ok(()) diff --git a/src/node.rs b/src/node.rs index b6f5d55..b5e4961 100644 --- a/src/node.rs +++ b/src/node.rs @@ -14,6 +14,7 @@ use tokio::{ process::Command, time::{sleep, Instant}, }; +use tracing::trace; use crate::{ client::Client, @@ -130,7 +131,7 @@ impl Node { let start = SystemTime::now(); let timeout = timeout.unwrap_or(Duration::from_secs(30)); // Default 30 seconds timeout loop { - debug!("Waiting for soft confirmation {}", num); + trace!("Waiting for soft confirmation {}", num); let latest_block = self .client .ledger_get_head_soft_confirmation_height() diff --git a/src/traits.rs b/src/traits.rs index ad897fe..7942401 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -4,6 +4,7 @@ use anyhow::Context; use async_trait::async_trait; use bollard::{container::StopContainerOptions, Docker}; use tokio::process::Child; +use tracing::info; use super::Result; use crate::node::NodeKind; @@ -45,7 +46,7 @@ pub trait NodeT: Send { Ok(()) } SpawnOutput::Container(ContainerSpawnOutput { id, .. }) => { - println!("Stopping container {id}"); + info!("Stopping container {id}"); let docker = Docker::connect_with_local_defaults().context("Failed to connect to Docker")?; docker diff --git a/src/utils.rs b/src/utils.rs index e05b683..84582f7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -8,6 +8,7 @@ use std::{ }; use rand::{distributions::Alphanumeric, thread_rng, Rng}; +use tracing::debug; use which::which; use super::Result; @@ -100,7 +101,7 @@ pub fn tail_file(path: &Path, lines: usize) -> Result<()> { } for line in last_lines { - println!("{line}"); + debug!("{line}"); } Ok(()) From a3cb73acc9c79e3b8ddbafe40991e2fbcf02fd99 Mon Sep 17 00:00:00 2001 From: jfldde <168934971+jfldde@users.noreply.github.com> Date: Tue, 8 Oct 2024 13:54:03 +0100 Subject: [PATCH 2/3] Clippy --- Cargo.toml | 1 - src/client.rs | 1 - src/light_client_prover.rs | 2 +- src/node.rs | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 611438b..04f5a32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,6 @@ bollard = { version = "0.17.1" } futures = "0.3" hex = { version = "0.4.3", default-features = false, features = ["serde"] } jsonrpsee = { version = "0.24.2", features = ["http-client", "ws-client"] } -log = "0.4" rand = "0.8" serde = { version = "1.0.192", default-features = false, features = ["alloc", "derive"] } serde_json = { version = "1.0", default-features = false } diff --git a/src/client.rs b/src/client.rs index d040989..06feefb 100644 --- a/src/client.rs +++ b/src/client.rs @@ -6,7 +6,6 @@ use jsonrpsee::{ http_client::{HttpClient, HttpClientBuilder}, rpc_params, }; -use log::debug; use sov_ledger_rpc::client::RpcClient; use sov_rollup_interface::rpc::{ SequencerCommitmentResponse, SoftConfirmationResponse, VerifiedProofResponse, diff --git a/src/light_client_prover.rs b/src/light_client_prover.rs index b97e9f7..47c0bda 100644 --- a/src/light_client_prover.rs +++ b/src/light_client_prover.rs @@ -1,8 +1,8 @@ use std::time::SystemTime; use anyhow::bail; -use log::debug; use tokio::time::{sleep, Duration}; +use tracing::debug; use super::{config::FullLightClientProverConfig, Result}; use crate::node::Node; diff --git a/src/node.rs b/src/node.rs index b5e4961..72e5860 100644 --- a/src/node.rs +++ b/src/node.rs @@ -8,7 +8,6 @@ use std::{ use anyhow::{bail, Context}; use async_trait::async_trait; -use log::debug; use serde::Serialize; use tokio::{ process::Command, From bb01f33f818b4f5087bea26519ffc58a54786463 Mon Sep 17 00:00:00 2001 From: jfldde <168934971+jfldde@users.noreply.github.com> Date: Tue, 8 Oct 2024 13:59:53 +0100 Subject: [PATCH 3/3] Add missing file --- src/batch_prover.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/batch_prover.rs b/src/batch_prover.rs index c7f33df..f7b427c 100644 --- a/src/batch_prover.rs +++ b/src/batch_prover.rs @@ -1,8 +1,8 @@ use std::time::SystemTime; use anyhow::bail; -use log::debug; use tokio::time::{sleep, Duration}; +use tracing::debug; use super::{config::FullBatchProverConfig, Result}; use crate::node::Node;