Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JDC fallback to solo-mining #1055

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
})
GitGab19 marked this conversation as resolved.
Show resolved Hide resolved
.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
Loading