Skip to content

Commit

Permalink
avoid JDS dropping connection on SubmitSolution with missing txs
Browse files Browse the repository at this point in the history
this is the actual fix for stratum-mining#912

use handle_result! macro

following suggestion by @lorbax stratum-mining#1025 (comment)

the implementation diverged a bit from the suggestion, but it was still a good reminder that we should leverage `handle_result!` macro here
  • Loading branch information
plebhash authored and fi3 committed Nov 26, 2024
1 parent 6e8f958 commit 3ff1df7
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions roles/jd-server/src/lib/job_declarator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,23 +280,18 @@ impl JobDeclaratorDownstream {
match Self::collect_txs_in_job(self_mutex.clone()) {
Ok(_) => {
info!("All transactions in downstream job are recognized correctly by the JD Server");
let hexdata =
match JobDeclaratorDownstream::get_block_hex(
self_mutex.clone(),
message,
) {
Ok(inner) => inner,
Err(e) => {
error!(
"Received solution but encountered error: {:?}",
e
);
recv.close();
//TODO should we brake it?
break;
}
};
let _ = new_block_sender.send(hexdata).await;
match JobDeclaratorDownstream::get_block_hex(
self_mutex.clone(),
message,
) {
Ok(hexdata) => {
let _ =
new_block_sender.send(hexdata).await;
}
Err(e) => {
handle_result!(tx_status, Err(*e))
}
};
}
Err(error) => {
error!("Missing transactions: {:?}", error);
Expand All @@ -316,22 +311,20 @@ impl JobDeclaratorDownstream {
.unwrap();
tokio::select! {
_ = JDsMempool::add_tx_data_to_mempool(mempool, retrieve_transactions) => {
let hexdata = match JobDeclaratorDownstream::get_block_hex(
match JobDeclaratorDownstream::get_block_hex(
self_mutex.clone(),
message.clone(),
) {
Ok(inner) => inner,
Ok(hexdata) => {
let _ = new_block_sender.send(hexdata).await;
},
Err(e) => {
error!(
"Error retrieving transactions: {:?}",
e
handle_result!(
tx_status,
Err(*e)
);
recv.close();
//TODO should we brake it?
break;
}
};
let _ = new_block_sender.send(hexdata).await;
}
_ = tokio::time::sleep(Duration::from_secs(60)) => {}
};
Expand Down

0 comments on commit 3ff1df7

Please sign in to comment.