Skip to content

Commit abbb8d0

Browse files
committed
Clear shares only on success
1 parent 0fa0b24 commit abbb8d0

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

src/monitor/shares.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use roles_logic_sv2::utils::Mutex;
22
use std::sync::Arc;
3-
use tracing::{debug, error};
3+
use tracing::{error, info, warn};
44

55
use crate::{
66
monitor::{shares_server_endpoint, MonitorAPI},
@@ -39,19 +39,19 @@ impl ShareInfo {
3939

4040
#[derive(Debug, Clone)]
4141
pub struct SharesMonitor {
42-
pending_shares: Arc<Mutex<Vec<ShareInfo>>>,
42+
shares: Arc<Mutex<Vec<ShareInfo>>>,
4343
}
4444

4545
impl SharesMonitor {
4646
pub fn new() -> Self {
4747
SharesMonitor {
48-
pending_shares: Arc::new(Mutex::new(Vec::new())),
48+
shares: Arc::new(Mutex::new(Vec::new())),
4949
}
5050
}
5151

5252
/// Inserts a new share into the pending shares list.
5353
pub fn insert_share(&self, share: ShareInfo) {
54-
self.pending_shares
54+
self.shares
5555
.safe_lock(|event| {
5656
event.push(share);
5757
})
@@ -62,8 +62,8 @@ impl SharesMonitor {
6262
}
6363

6464
/// Retrieves the list of pending shares.
65-
fn get_pending_shares(&self) -> Vec<ShareInfo> {
66-
self.pending_shares
65+
fn get_next_shares(&self) -> Vec<ShareInfo> {
66+
self.shares
6767
.safe_lock(|event| event.clone())
6868
.unwrap_or_else(|e| {
6969
error!("Failed to lock pending shares: {:?}", e);
@@ -73,8 +73,8 @@ impl SharesMonitor {
7373
}
7474

7575
/// Clears the list of pending shares.
76-
fn clear_pending_shares(&self) {
77-
self.pending_shares
76+
fn clear_next_shares(&self) {
77+
self.shares
7878
.safe_lock(|event| {
7979
event.clear();
8080
})
@@ -84,26 +84,29 @@ impl SharesMonitor {
8484
});
8585
}
8686

87-
/// Monitors the pending shares and sends them to the monitoring server in batches.
8887
pub async fn monitor(&self) {
8988
let api = MonitorAPI::new(shares_server_endpoint());
90-
let mut interval = tokio::time::interval(std::time::Duration::from_secs(60)); // Check every 60 seconds
91-
interval.tick().await; // Skip the first tick to avoid unnecessary error log
89+
let mut interval = tokio::time::interval(std::time::Duration::from_secs(60));
90+
// First tick completes immediately
91+
interval.tick().await;
9292
loop {
9393
interval.tick().await;
94-
let shares_to_send = self.get_pending_shares();
94+
let shares_to_send = self.get_next_shares();
9595
if !shares_to_send.is_empty() {
9696
match api.send_shares(shares_to_send.clone()).await {
9797
Ok(_) => {
98-
debug!("Successfully sent Shares: {:?} to API", &shares_to_send);
98+
info!(
99+
"Saved {} shares to the monitoring server",
100+
shares_to_send.len()
101+
);
102+
self.clear_next_shares();
99103
}
100104
Err(err) => {
101-
error!("Failed to send shares: {}", err);
105+
warn!("Failed to send shares, this does not affect mining but may cause issues with monitoring: {:?}", err);
102106
}
103107
}
104-
self.clear_pending_shares(); // Clear after sending
105108
} else {
106-
error!("No pending shares to send");
109+
warn!("No pending shares to send. If this happens frequently, check your miner.");
107110
}
108111
}
109112
}

0 commit comments

Comments
 (0)