Skip to content

Commit 43d18da

Browse files
authored
Merge pull request dmnd-pool#62 from Priceless-P/feat/accept-last-two-job
Feat/accept last two job
2 parents 0efb89b + 875cdb7 commit 43d18da

11 files changed

Lines changed: 152 additions & 112 deletions

File tree

Cargo.lock

Lines changed: 27 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "demand-cli"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
edition = "2021"
55

66
[dependencies]
@@ -23,7 +23,6 @@ axum = {version = "0.8.1"}
2323
serde = { version = "1.0.219", features = ["derive"] }
2424
sysinfo = {version = "0.33.1"}
2525
primitive-types = { version = "0.13.1" }
26-
hex={version = "*"}
2726
#roles_logic_sv2 = "1.2.1"
2827
#sv1_api = "1.0.1"
2928
#demand-sv2-connection = "0.0.3"

src/jd_client/mining_downstream/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,11 @@ impl
613613
header_nonce: share.nonce,
614614
coinbase_tx: coinbase.try_into()?,
615615
};
616-
// The below channel should never be full is ok to block
617-
solution_sender
618-
.blocking_send(solution)
619-
.map_err(|_| Error::DownstreamDown)?; // Better Error to return here?
616+
tokio::spawn(async move {
617+
if solution_sender.send(solution).await.is_err() {
618+
error!("Downstream channel closed, couldn't send solution");
619+
}
620+
});
620621
if !self.status.is_solo_miner() {
621622
{
622623
let jd = self.jd.clone();

src/jd_client/mining_upstream/upstream.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ impl ParseUpstreamMiningMessages<Downstream, NullDownstreamMiningSelector, NoRou
403403

404404
let extranonces = ExtendedExtranonce::new(range_0, range_1, range_2);
405405
let creator = roles_logic_sv2::job_creator::JobsCreators::new(total_len as u8);
406-
let share_per_min = 1.0;
407406
let channel_kind =
408407
roles_logic_sv2::channel_logic::channel_factory::ExtendedChannelKind::ProxyJd {
409408
upstream_target: m.target.clone().into(),
@@ -412,7 +411,7 @@ impl ParseUpstreamMiningMessages<Downstream, NullDownstreamMiningSelector, NoRou
412411
ids,
413412
extranonces,
414413
creator,
415-
share_per_min,
414+
crate::SHARE_PER_MIN,
416415
channel_kind,
417416
vec![],
418417
vec![],

src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ const CHANNEL_DIFF_UPDTATE_INTERVAL: u32 = 10;
3434
const MAX_LEN_DOWN_MSG: u32 = 10000;
3535
const MAIN_POOL_ADDRESS: &str = "mining.dmnd.work:2000";
3636
//const TEST_POOL_ADDRESS: &str = "127.0.0.1:20000";
37-
const TEST_POOL_ADDRESS: &str =
38-
"k8s-default-pool-de2d9b37ea-6bc40843aed871f2.elb.eu-central-1.amazonaws.com:2000";
37+
const TEST_POOL_ADDRESS: &str = "18.193.252.132:2000";
3938
const MAIN_AUTH_PUB_KEY: &str = "9bQHWXsQ2J9TRFTaxRh3KjoxdyLRfWVEy25YHtKF8y8gotLoCZZ";
4039
const TEST_AUTH_PUB_KEY: &str = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72";
4140
//const TP_ADDRESS: &str = "127.0.0.1:8442";
@@ -168,7 +167,7 @@ async fn initialize_proxy(
168167
Ok(connection) => connection,
169168
Err(_) => {
170169
error!("No upstream available. Retrying...");
171-
error!("Are you using the correct TOKEN??");
170+
warn!("Are you using the correct TOKEN??");
172171
let mut secs = 10;
173172
while secs > 0 {
174173
tracing::warn!("Retrying in {} seconds...", secs);

src/translator/downstream/diff_management.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{Downstream, DownstreamMessages, SetDownstreamTarget};
22
use pid::Pid;
33
use roles_logic_sv2::{self, utils::from_u128_to_u256};
4-
use sv1_api::{self, methods::server_to_client::SetDifficulty, server_to_client::Notify};
4+
use sv1_api::{self, methods::server_to_client::SetDifficulty};
55

66
use super::super::error::{Error, ProxyResult};
77
use primitive_types::U256;
@@ -47,7 +47,8 @@ impl Downstream {
4747
});
4848
stats_sender.update_diff(connection_id, diff);
4949
stats_sender.update_hashrate(connection_id, estimated_hashrate);
50-
tokio::spawn(crate::translator::utils::check_share_rate_limit());
50+
let downstream = self_.clone();
51+
tokio::spawn(crate::translator::utils::check_share_rate_limit(downstream));
5152

5253
Ok(())
5354
}
@@ -79,15 +80,14 @@ impl Downstream {
7980
/// downstream and the bridge.
8081
pub async fn try_update_difficulty_settings(
8182
self_: &Arc<Mutex<Self>>,
82-
last_notify: Option<Notify<'static>>,
8383
) -> ProxyResult<'static, ()> {
8484
let channel_id = self_
8585
.clone()
8686
.safe_lock(|d| (d.connection_id))
8787
.map_err(|_e| Error::TranslatorDiffConfigMutexPoisoned)?;
8888

8989
if let Some(new_diff) = Self::update_difficulty_and_hashrate(self_)? {
90-
Self::update_diff_setting(self_, channel_id, new_diff.into(), last_notify).await?;
90+
Self::update_diff_setting(self_, channel_id, new_diff.into()).await?;
9191
}
9292
Ok(())
9393
}
@@ -100,13 +100,17 @@ impl Downstream {
100100
self_: &Arc<Mutex<Self>>,
101101
channel_id: u32,
102102
new_diff: f64,
103-
last_notify: Option<Notify<'static>>,
104103
) -> ProxyResult<'static, ()> {
105104
// Send messages downstream
106105
let (message, target) = diff_to_sv1_message(new_diff)?;
107106
Downstream::send_message_downstream(self_.clone(), message).await;
108107

109-
if let Some(notify) = last_notify {
108+
// Get the last notify
109+
let recent_notify = self_
110+
.safe_lock(|d| d.recent_notifies.back().cloned())
111+
.map_err(|_| Error::TranslatorDiffConfigMutexPoisoned)?;
112+
113+
if let Some(notify) = recent_notify {
110114
Downstream::send_message_downstream(self_.clone(), notify.into()).await;
111115
}
112116

@@ -459,7 +463,7 @@ mod test {
459463
while elapsed <= total_run_time {
460464
mock_mine(initial_target.clone().into(), &mut share);
461465
Downstream::save_share(downstream.clone()).unwrap();
462-
let _ = Downstream::try_update_difficulty_settings(&downstream, None).await;
466+
let _ = Downstream::try_update_difficulty_settings(&downstream).await;
463467
initial_target = downstream
464468
.safe_lock(|d| {
465469
match roles_logic_sv2::utils::hash_rate_to_target(

src/translator/downstream/downstream.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub struct Downstream {
104104
pub(super) difficulty_mgmt: DownstreamDifficultyConfig,
105105
pub(super) upstream_difficulty_config: Arc<Mutex<UpstreamDifficultyConfig>>,
106106
pub last_call_to_update_hr: u128,
107-
pub(super) last_notify: Option<server_to_client::Notify<'static>>,
107+
pub(super) recent_notifies: VecDeque<server_to_client::Notify<'static>>,
108108
pub(super) stats_sender: StatsSender,
109109
}
110110

@@ -167,6 +167,11 @@ impl Downstream {
167167
initial_difficulty,
168168
};
169169

170+
let mut recent_notifies = VecDeque::with_capacity(2);
171+
if let Some(notify) = last_notify.clone() {
172+
recent_notifies.push_back(notify);
173+
}
174+
170175
let downstream = Arc::new(Mutex::new(Downstream {
171176
connection_id,
172177
authorized_names: vec![],
@@ -180,7 +185,7 @@ impl Downstream {
180185
difficulty_mgmt,
181186
upstream_difficulty_config,
182187
last_call_to_update_hr: 0,
183-
last_notify: last_notify.clone(),
188+
recent_notifies: recent_notifies.clone(),
184189
stats_sender,
185190
}));
186191

@@ -213,7 +218,7 @@ impl Downstream {
213218
task_manager.clone(),
214219
downstream.clone(),
215220
rx_sv1_notify,
216-
last_notify,
221+
recent_notifies,
217222
host.clone(),
218223
connection_id,
219224
)
@@ -354,7 +359,7 @@ impl Downstream {
354359
difficulty_mgmt,
355360
upstream_difficulty_config,
356361
last_call_to_update_hr: 0,
357-
last_notify: None,
362+
recent_notifies: VecDeque::with_capacity(2),
358363
stats_sender,
359364
}
360365
}
@@ -417,7 +422,10 @@ impl IsServer<'static> for Downstream {
417422
/// When miner find the job which meets requested difficulty, it can submit share to the server.
418423
/// Only [Submit](client_to_server::Submit) requests for authorized user names can be submitted.
419424
fn handle_submit(&self, request: &client_to_server::Submit<'static>) -> bool {
420-
info!("Down: Handling mining.submit: {:?}", &request);
425+
info!(
426+
"Downstream {}: Handling mining.submit for job_id {}",
427+
self.connection_id, request.job_id
428+
);
421429

422430
// check first job received
423431
if !self.first_job_received {
@@ -427,7 +435,7 @@ impl IsServer<'static> for Downstream {
427435
//check allowed to send shares
428436
match allow_submit_share() {
429437
Ok(true) => {
430-
let Some(job) = &self.last_notify else {
438+
if self.recent_notifies.is_empty() {
431439
error!("Share rejected: No last job found");
432440
self.stats_sender.update_rejected_shares(self.connection_id);
433441
return false;
@@ -436,7 +444,7 @@ impl IsServer<'static> for Downstream {
436444
//check share is valid
437445
if validate_share(
438446
request,
439-
job,
447+
&self.recent_notifies,
440448
self.difficulty_mgmt.current_difficulty,
441449
self.extranonce1.clone(),
442450
self.version_rolling_mask.clone(),

0 commit comments

Comments
 (0)