Skip to content

Commit 106e6c5

Browse files
authored
Merge pull request dmnd-pool#83 from jbesraa/2025-06-18/improve-logs
Improve logs across codebase
2 parents 69f095e + 36ebea8 commit 106e6c5

14 files changed

Lines changed: 185 additions & 76 deletions

File tree

src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55
net::{SocketAddr, ToSocketAddrs},
66
path::PathBuf,
77
};
8-
use tracing::{error, info, warn};
8+
use tracing::{debug, error, info, warn};
99

1010
use crate::{HashUnit, DEFAULT_SV1_HASHPOWER};
1111
lazy_static! {
@@ -190,6 +190,7 @@ impl Configuration {
190190
.token
191191
.or(config.token)
192192
.or_else(|| std::env::var("TOKEN").ok());
193+
debug!("User Token: {:?}", token);
193194

194195
let tp_address = args
195196
.tp_address

src/ingress/sv1_ingress.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@ use tracing::{error, info, warn};
1818
pub fn start_listen_for_downstream(
1919
downstreams: Sender<(Sender<String>, Receiver<String>, IpAddr)>,
2020
) -> AbortOnDrop {
21-
info!("Starting downstream listner");
2221
tokio::task::spawn(async move {
2322
let down_addr: String = crate::SV1_DOWN_LISTEN_ADDR.to_string();
2423
let downstream_addr: SocketAddr = down_addr.parse().expect("Invalid listen address");
24+
info!(
25+
"Trying to bind to address {} for downstream(miner) connections",
26+
downstream_addr
27+
);
2528
let downstream_listener = TcpListener::bind(downstream_addr)
2629
.await
2730
.expect("impossible to bind downstream");
31+
info!(
32+
"Listening for downstream connections on {:?}",
33+
downstream_addr
34+
);
2835
while let Ok((stream, addr)) = downstream_listener.accept().await {
2936
info!("Try to connect {:#?}", addr);
3037
Downstream::initialize(

src/jd_client/task_manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33
use crate::shared::utils::AbortOnDrop;
44
use roles_logic_sv2::utils::Mutex;
55
use tokio::sync::mpsc;
6-
use tracing::warn;
6+
use tracing::debug;
77

88
#[derive(Debug)]
99
#[allow(dead_code)]
@@ -29,11 +29,11 @@ impl TaskManager {
2929
while let Some(task) = receiver.recv().await {
3030
tasks.push(task);
3131
}
32-
warn!("Share accounter main task manager stopped, keep alive tasks");
3332
loop {
3433
tokio::time::sleep(std::time::Duration::from_secs(1000)).await;
3534
}
3635
});
36+
debug!("Share Accounter Task Manager initialized");
3737
Arc::new(Mutex::new(Self {
3838
send_task: sender,
3939
abort: Some(handle.into()),

src/main.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async fn main() {
8888
}
8989

9090
if Configuration::test() {
91-
info!("Connecting to test endpoint...");
91+
info!("Package is running in test mode");
9292
}
9393

9494
let auth_pub_k: Secp256k1PublicKey = AUTH_PUB_KEY.parse().expect("Invalid public key");
@@ -117,21 +117,18 @@ async fn initialize_proxy(
117117
epsilon: Duration,
118118
) {
119119
loop {
120-
// Initial setup for the proxy
121120
let stats_sender = api::stats::StatsSender::new();
122-
123121
let (send_to_pool, recv_from_pool, pool_connection_abortable) =
124122
match router.connect_pool(pool_addr).await {
125123
Ok(connection) => connection,
126124
Err(_) => {
127-
error!("No upstream available. Retrying...");
128-
warn!("Are you using the correct TOKEN??");
129-
let mut secs = 10;
130-
while secs > 0 {
131-
tracing::warn!("Retrying in {} seconds...", secs);
132-
tokio::time::sleep(Duration::from_secs(1)).await;
133-
secs -= 1;
134-
}
125+
error!("No upstream available. Retrying in 5 seconds...");
126+
warn!(
127+
"Please make sure the your token {} is correct",
128+
Configuration::token().expect("Token is not set")
129+
);
130+
let secs = 5;
131+
tokio::time::sleep(Duration::from_secs(secs)).await;
135132
// Restart loop, esentially restarting proxy
136133
continue;
137134
}
@@ -347,7 +344,7 @@ fn check_update_proxy() {
347344
match updater.update_extended() {
348345
Ok(status) => match status {
349346
UpdateStatus::UpToDate => {
350-
info!("Starting latest version of DMND-PROXY.");
347+
info!("Package is up to date");
351348
}
352349
UpdateStatus::Updated(release) => {
353350
info!(

src/minin_pool_connection/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ pub async fn connect_pool(
4444
> {
4545
let socket = loop {
4646
match TcpStream::connect(address).await {
47-
Ok(socket) => break socket,
47+
Ok(socket) => {
48+
info!("Socket initialized with Pool at {}", address);
49+
break socket;
50+
}
4851
Err(e) => {
4952
error!(
5053
"Failed to connect to Upstream role at {}, retrying in 5s: {}",
@@ -55,14 +58,9 @@ pub async fn connect_pool(
5558
}
5659
};
5760

61+
info!("Performing SV2 Handshake with Pool at {}", address);
5862
let initiator =
5963
Initiator::from_raw_k(authority_public_key.into_bytes()).expect("Invalid authority key");
60-
61-
info!(
62-
"PROXY SERVER - ACCEPTING FROM UPSTREAM: {}",
63-
socket.peer_addr().expect("Failed to get peer address")
64-
);
65-
6664
// Channel to send and receive messages to the SV2 Upstream role
6765
let (mut receiver, mut sender, _, _) =
6866
Connection::new(socket, HandshakeRole::Initiator(initiator))
@@ -71,6 +69,8 @@ pub async fn connect_pool(
7169
error!("Failed to create connection");
7270
Error::SV2Connection(e)
7371
})?;
72+
info!("SV2 Handshake with Pool at {} completed", address);
73+
info!("Sending SetupConnection message to Pool at {}", address);
7474
let setup_connection_msg =
7575
setup_connection_msg.unwrap_or(get_mining_setup_connection_msg(true));
7676
match mining_setup_connection(

src/minin_pool_connection/task_manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33
use crate::shared::utils::AbortOnDrop;
44
use roles_logic_sv2::utils::Mutex;
55
use tokio::sync::mpsc;
6-
use tracing::warn;
6+
use tracing::debug;
77

88
#[derive(Debug)]
99
#[allow(dead_code)]
@@ -25,11 +25,11 @@ impl TaskManager {
2525
while let Some(task) = receiver.recv().await {
2626
tasks.push(task);
2727
}
28-
warn!("Ingress task manager stopped, keep alive tasks");
2928
loop {
3029
tokio::time::sleep(std::time::Duration::from_secs(1000)).await;
3130
}
3231
});
32+
debug!("Mining Pool Task Manager initialized");
3333
Arc::new(Mutex::new(Self {
3434
send_task: sender,
3535
abort: Some(handle.into()),

src/router/mod.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,23 @@ impl Router {
7979

8080
/// Select the best pool for connection
8181
pub async fn select_pool_connect(&self) -> Option<SocketAddr> {
82-
info!("Selecting the best upstream ");
82+
info!("Selecting best Pool for connection");
83+
if self.pool_addresses.is_empty() {
84+
error!("No pool addresses provided");
85+
return None;
86+
}
87+
if self.pool_addresses.len() == 1 {
88+
info!(
89+
"Only one pool address available, using: {:?}",
90+
self.pool_addresses[0]
91+
);
92+
return Some(self.pool_addresses[0]);
93+
}
8394
if let Some((pool, latency)) = self.select_pool().await {
84-
info!("Latency for upstream {:?} is {:?}", pool, latency);
95+
info!("Latency for Pool {:?} is {:?}", pool, latency);
8596
self.latency_tx.send_replace(Some(latency)); // update latency
8697
Some(pool)
8798
} else {
88-
//info!("No available pool");
8999
None
90100
}
91101
}
@@ -147,7 +157,7 @@ impl Router {
147157
};
148158
self.current_pool = Some(pool);
149159

150-
info!("Upstream {:?} selected", pool);
160+
info!("Trying to connect to Pool {:?}", pool);
151161

152162
match minin_pool_connection::connect_pool(
153163
pool,
@@ -166,6 +176,10 @@ impl Router {
166176
error!("Pool address Mutex corrupt");
167177
crate::proxy_state::ProxyState::update_inconsistency(Some(1));
168178
});
179+
info!(
180+
"Completed Handshake And SetupConnection with Pool at {:?}",
181+
pool
182+
);
169183

170184
Ok((send_to_pool, recv_from_pool, pool_connection_abortable))
171185
}

src/translator/downstream/accept_connection.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use tokio::sync::{
1414
mpsc::{Receiver, Sender},
1515
};
1616
use tokio::task;
17-
use tracing::{error, info};
17+
use tracing::{debug, error, info};
1818

1919
pub async fn start_accept_connection(
2020
task_manager: Arc<Mutex<TaskManager>>,
@@ -33,23 +33,42 @@ pub async fn start_accept_connection(
3333
let _s = tx_mining_notify.subscribe();
3434
while let Some((send, recv, addr)) = downstreams.recv().await {
3535
info!("Translator opening connection for ip {}", addr);
36-
3736
// The initial difficulty is derived from the formula: difficulty = hash_rate / (shares_per_second * 2^32)
3837
let initial_hash_rate = *crate::EXPECTED_SV1_HASHPOWER;
38+
info!(
39+
"Translator initial hash rate for ip {} is {} H/s",
40+
addr, initial_hash_rate
41+
);
3942
let share_per_second = crate::SHARE_PER_MIN / 60.0;
40-
let initial_difficulty =
41-
dbg!(initial_hash_rate / (share_per_second * 2f32.powf(32.0)));
43+
info!(
44+
"Translator share per second for ip {} is {} shares/s",
45+
addr, share_per_second
46+
);
47+
let initial_difficulty = initial_hash_rate / (share_per_second * 2f32.powf(32.0));
4248
let initial_difficulty =
4349
crate::translator::downstream::diff_management::nearest_power_of_10(
4450
initial_difficulty,
4551
);
46-
52+
info!(
53+
"Translator initial difficulty for ip {} is {}",
54+
addr, initial_difficulty
55+
);
4756
// Formula: expected_hash_rate = (shares_per_second) * initial_difficulty * 2^32, where shares_per_second = SHARE_PER_MIN / 60
4857
let expected_hash_rate =
4958
(crate::SHARE_PER_MIN / 60.0) * initial_difficulty * 2f32.powf(32.0);
50-
if Bridge::ready(&bridge).await.is_err() {
51-
error!("Bridge not ready");
52-
break;
59+
info!(
60+
"Translator expected hash rate for ip {} is {} H/s",
61+
addr, expected_hash_rate
62+
);
63+
64+
match Bridge::ready(&bridge).await {
65+
Ok(_) => {
66+
debug!("Bridge is ready, proceeding with connection");
67+
}
68+
Err(_) => {
69+
error!("Bridge not ready");
70+
break;
71+
}
5372
};
5473
let open_sv1_downstream =
5574
match bridge.safe_lock(|s| s.on_new_sv1_connection(expected_hash_rate)) {

src/translator/downstream/downstream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl IsServer<'static> for Downstream {
434434
/// Only [Submit](client_to_server::Submit) requests for authorized user names can be submitted.
435435
fn handle_submit(&self, request: &client_to_server::Submit<'static>) -> bool {
436436
info!(
437-
"Downstream {}: Handling mining.submit for job_id {}",
437+
"Handling mining.submit for for downstream with connection id {} and job_id {}",
438438
self.connection_id, request.job_id
439439
);
440440

0 commit comments

Comments
 (0)