Skip to content

Commit e2b19c1

Browse files
GitGab19plebhash
authored andcommitted
add HashMap of prevhashes in Sv1ServerData
1 parent a4a7fcf commit e2b19c1

File tree

4 files changed

+180
-131
lines changed

4 files changed

+180
-131
lines changed

miner-apps/translator/src/lib/sv1/sv1_server/data.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ pub struct Sv1ServerData {
2626
pub downstreams: HashMap<DownstreamId, Arc<Downstream>>,
2727
pub request_id_to_downstream_id: HashMap<RequestId, DownstreamId>,
2828
pub vardiff: HashMap<DownstreamId, Arc<RwLock<VardiffState>>>,
29-
pub prevhash: Option<SetNewPrevHash<'static>>,
29+
/// HashMap to store the SetNewPrevHash for each channel
30+
/// Used in both aggregated and non-aggregated mode
31+
pub prevhashes: HashMap<ChannelId, SetNewPrevHash<'static>>,
3032
pub downstream_id_factory: AtomicUsize,
3133
pub request_id_factory: AtomicU32,
3234
/// Job storage for aggregated mode - all Sv1 downstreams share the same jobs
@@ -52,7 +54,7 @@ impl Sv1ServerData {
5254
downstreams: HashMap::new(),
5355
request_id_to_downstream_id: HashMap::new(),
5456
vardiff: HashMap::new(),
55-
prevhash: None,
57+
prevhashes: HashMap::new(),
5658
downstream_id_factory: AtomicUsize::new(1),
5759
request_id_factory: AtomicU32::new(1),
5860
aggregated_valid_jobs: aggregate_channels.then(Vec::new),
@@ -87,6 +89,16 @@ impl Sv1ServerData {
8789
job_id.contains(KEEPALIVE_JOB_ID_DELIMITER)
8890
}
8991

92+
/// Gets the prevhash for a given channel.
93+
pub fn get_prevhash(&self, channel_id: u32) -> Option<SetNewPrevHash<'static>> {
94+
self.prevhashes.get(&channel_id).cloned()
95+
}
96+
97+
/// Sets the prevhash for a given channel.
98+
pub fn set_prevhash(&mut self, channel_id: u32, prevhash: SetNewPrevHash<'static>) {
99+
self.prevhashes.insert(channel_id, prevhash);
100+
}
101+
90102
/// Gets the last job from the jobs storage.
91103
/// In aggregated mode, returns the last job from the shared job list.
92104
/// In non-aggregated mode, returns the last job for the specified channel.

miner-apps/translator/src/lib/sv1/sv1_server/sv1_server.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,9 @@ impl Sv1Server {
576576
"Received NewExtendedMiningJob for channel id: {}",
577577
m.channel_id
578578
);
579-
if let Some(prevhash) = self.sv1_server_data.super_safe_lock(|v| v.prevhash.clone())
579+
if let Some(prevhash) = self
580+
.sv1_server_data
581+
.super_safe_lock(|v| v.get_prevhash(m.channel_id))
580582
{
581583
let clean_jobs = m.job_id == prevhash.job_id;
582584
let notify =
@@ -616,7 +618,7 @@ impl Sv1Server {
616618
Mining::SetNewPrevHash(m) => {
617619
debug!("Received SetNewPrevHash for channel id: {}", m.channel_id);
618620
self.sv1_server_data
619-
.super_safe_lock(|v| v.prevhash = Some(m.clone().into_static()));
621+
.super_safe_lock(|v| v.set_prevhash(m.channel_id, m.clone().into_static()));
620622
}
621623

622624
Mining::SetTarget(m) => {

miner-apps/translator/src/lib/sv2/channel_manager/channel_manager.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
channel::ChannelState,
66
data::{ChannelManagerData, ChannelMode},
77
},
8-
utils::ShutdownMessage,
8+
utils::{ShutdownMessage, AGGREGATED_CHANNEL_ID},
99
};
1010
use async_channel::{Receiver, Sender};
1111
use std::sync::{Arc, RwLock};
@@ -404,6 +404,10 @@ impl ChannelManager {
404404
}
405405
});
406406

407+
// set the channel id to the aggregated channel id
408+
// before sending the message to the SV1Server
409+
job.channel_id = AGGREGATED_CHANNEL_ID;
410+
407411
self.channel_state
408412
.sv1_server_sender
409413
.send((Mining::NewExtendedMiningJob(job.clone()), None))

0 commit comments

Comments
 (0)