diff --git a/roles/Cargo.lock b/roles/Cargo.lock index 20c738898d..9f8aa5417d 100644 --- a/roles/Cargo.lock +++ b/roles/Cargo.lock @@ -1579,6 +1579,8 @@ dependencies = [ "serde_json", "stratum-common", "sv1_api", + "tracing", + "tracing-subscriber", ] [[package]] diff --git a/roles/test-utils/mining-device-sv1/Cargo.toml b/roles/test-utils/mining-device-sv1/Cargo.toml index ae4fe64ee1..d4495062f7 100644 --- a/roles/test-utils/mining-device-sv1/Cargo.toml +++ b/roles/test-utils/mining-device-sv1/Cargo.toml @@ -27,3 +27,5 @@ serde_json = { version = "1.0.64", default-features = false, features = ["alloc" v1 = { path="../../../protocols/v1", package="sv1_api" } num-bigint = "0.4.3" num-traits = "0.2.15" +tracing = "0.1.41" +tracing-subscriber = "0.3.19" diff --git a/roles/test-utils/mining-device-sv1/src/client.rs b/roles/test-utils/mining-device-sv1/src/client.rs index 4934bae449..3396ccdf64 100644 --- a/roles/test-utils/mining-device-sv1/src/client.rs +++ b/roles/test-utils/mining-device-sv1/src/client.rs @@ -7,6 +7,7 @@ use num_bigint::BigUint; use num_traits::FromPrimitive; use roles_logic_sv2::utils::Mutex; use std::{sync::Arc, time}; +use tracing::{error, info, warn}; use stratum_common::bitcoin::util::uint::Uint256; use v1::{ @@ -105,17 +106,17 @@ impl Client { match message { Ok(msg) => { if let Err(e) = sender_incoming.send(msg).await { - eprintln!("Failed to send message to receiver_incoming: {:?}", e); + error!("Failed to send message to receiver_incoming: {:?}", e); break; // Exit the loop if sending fails } } Err(e) => { - eprintln!("Error reading from socket: {:?}", e); + error!("Error reading from socket: {:?}", e); break; // Exit the loop on read failure } } } - eprintln!("Reader task terminated."); + warn!("Reader task terminated."); }); // Waits to receive a message from `sender_outgoing` and writes it to the socket for the @@ -234,7 +235,7 @@ impl Client { ) { // If we have a line (1 line represents 1 sv1 incoming message), then handle that message if let Ok(line) = incoming_message { - println!( + info!( "CLIENT {} - Received: {}", self_.safe_lock(|s| s.client_id).unwrap(), line @@ -254,7 +255,7 @@ impl Client { /// Send SV1 messages to the receiver_outgoing which writes to the socket (aka Upstream node) async fn send_message(sender: Sender, msg: json_rpc::Message) { let msg = format!("{}\n", serde_json::to_string(&msg).unwrap()); - println!(" - Send: {}", &msg); + info!(" - Send: {}", &msg); sender.send(msg).await.unwrap(); } diff --git a/roles/test-utils/mining-device-sv1/src/main.rs b/roles/test-utils/mining-device-sv1/src/main.rs index f34df28d54..a822068190 100644 --- a/roles/test-utils/mining-device-sv1/src/main.rs +++ b/roles/test-utils/mining-device-sv1/src/main.rs @@ -7,6 +7,8 @@ pub(crate) use client::Client; #[async_std::main] async fn main() { + tracing_subscriber::fmt().init(); + const ADDR: &str = "127.0.0.1:34255"; Client::connect( 80, diff --git a/roles/test-utils/mining-device-sv1/src/miner.rs b/roles/test-utils/mining-device-sv1/src/miner.rs index c63af5a966..65844d9441 100644 --- a/roles/test-utils/mining-device-sv1/src/miner.rs +++ b/roles/test-utils/mining-device-sv1/src/miner.rs @@ -6,6 +6,7 @@ use stratum_common::bitcoin::{ hashes::{sha256d::Hash as DHash, Hash}, util::uint::Uint256, }; +use tracing::info; /// A mock representation of a Mining Device that produces block header hashes to be submitted by /// the `Client` to the Upstream node (either a SV1 Pool server or a SV1 <-> SV2 Translator Proxy @@ -75,7 +76,7 @@ impl Miner { hash.reverse(); let hash = Uint256::from_be_bytes(hash); if hash < *self.target.as_ref().ok_or(())? { - println!( + info!( "Found share with nonce: {}, for target: {:?}, hash: {:?}", header.nonce, self.target, hash );