Skip to content

Commit

Permalink
Merge pull request #1309 from devworlds/feature/update-println-to-info
Browse files Browse the repository at this point in the history
feat: update println! and eprintln! to info using tracing cargo.
  • Loading branch information
plebhash authored Dec 19, 2024
2 parents 1351618 + 3ac79b1 commit fd1b488
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions roles/Cargo.lock

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

2 changes: 2 additions & 0 deletions roles/test-utils/mining-device-sv1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
11 changes: 6 additions & 5 deletions roles/test-utils/mining-device-sv1/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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<String>, 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();
}

Expand Down
2 changes: 2 additions & 0 deletions roles/test-utils/mining-device-sv1/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion roles/test-utils/mining-device-sv1/src/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
);
Expand Down

0 comments on commit fd1b488

Please sign in to comment.