Skip to content

Commit

Permalink
Merge pull request #1055 from lorbax/jdc-gets-stuck-in-fallback-to-so…
Browse files Browse the repository at this point in the history
…lo-mining

Fix JDC fallback to solo-mining
  • Loading branch information
plebhash authored Aug 17, 2024
2 parents da6023d + cd493ee commit 51c0330
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
6 changes: 3 additions & 3 deletions benches/Cargo.lock

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

26 changes: 18 additions & 8 deletions roles/jd-client/src/lib/downstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct DownstreamMiningNode {
miner_coinbase_output: Vec<TxOut>,
// used to retreive the job id of the share that we send upstream
last_template_id: u64,
jd: Option<Arc<Mutex<JobDeclarator>>>,
pub jd: Option<Arc<Mutex<JobDeclarator>>>,
}

#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -376,12 +376,13 @@ impl DownstreamMiningNode {
let to_send = to_send.into_values();
for message in to_send {
let message = if let Mining::NewExtendedMiningJob(job) = message {
let jd = self_mutex.safe_lock(|s| s.jd.clone()).unwrap().unwrap();
jd.safe_lock(|jd| jd.coinbase_tx_prefix = job.coinbase_tx_prefix.clone())
.unwrap();
jd.safe_lock(|jd| jd.coinbase_tx_suffix = job.coinbase_tx_suffix.clone())
if let Some(jd) = self_mutex.safe_lock(|s| s.jd.clone()).unwrap() {
jd.safe_lock(|jd| {
jd.coinbase_tx_prefix = job.coinbase_tx_prefix.clone();
jd.coinbase_tx_suffix = job.coinbase_tx_suffix.clone();
})
.unwrap();

}
Mining::NewExtendedMiningJob(job)
} else {
message
Expand Down Expand Up @@ -514,15 +515,24 @@ impl

fn handle_update_channel(
&mut self,
_: UpdateChannel,
m: UpdateChannel,
) -> Result<SendTo<UpstreamMiningNode>, Error> {
if !self.status.is_solo_miner() {
// Safe unwrap alreay checked if it cointains upstream with is_solo_miner
Ok(SendTo::RelaySameMessageToRemote(
self.status.get_upstream().unwrap(),
))
} else {
todo!()
let maximum_target =
roles_logic_sv2::utils::hash_rate_to_target(m.nominal_hash_rate.into(), 10.0)?;
self.status
.get_channel()
.update_target_for_channel(m.channel_id, maximum_target.clone().into());
let set_target = SetTarget {
channel_id: m.channel_id,
maximum_target,
};
Ok(SendTo::Respond(Mining::SetTarget(set_target)))
}
}

Expand Down
13 changes: 10 additions & 3 deletions roles/jd-client/src/lib/template_receiver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,16 @@ impl TemplateRx {
test_only_do_not_send_solution_to_tp: bool,
) {
let mut encoded_outputs = vec![];
miner_coinbase_outputs
.consensus_encode(&mut encoded_outputs)
.expect("Invalid coinbase output in config");
// jd is set to None in initialize_jd_as_solo_miner (in this case we need to take the first output as done by JDS)
if jd.is_none() {
miner_coinbase_outputs[0]
.consensus_encode(&mut encoded_outputs)
.expect("Invalid coinbase output in config");
} else {
miner_coinbase_outputs
.consensus_encode(&mut encoded_outputs)
.expect("Invalid coinbase output in config");
}
let stream = tokio::net::TcpStream::connect(address).await.unwrap();

let initiator = match authority_public_key {
Expand Down

0 comments on commit 51c0330

Please sign in to comment.