Skip to content

Commit

Permalink
Handle unwrap when shutting down JDC server
Browse files Browse the repository at this point in the history
..This should prevent the code from panicing if a signal
to shutdown is sent the JDC server

As a result, MAJOR is pumped for `roles-logic-sv2` crate as new property
was added to public `Error` struct.
  • Loading branch information
jbesraa committed Jan 22, 2025
1 parent a5d3714 commit 151befc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion protocols/v2/roles-logic-sv2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "roles_logic_sv2"
version = "1.2.3"
version = "2.0.0"
authors = ["The Stratum V2 Developers"]
edition = "2018"
description = "Common handlers for use within SV2 roles"
Expand Down
8 changes: 8 additions & 0 deletions protocols/v2/roles-logic-sv2/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub enum Error {
LogicErrorMessage(std::boxed::Box<AllMessages<'static>>),
/// JD server cannot propagate the block due to missing transactions
JDSMissingTransactions,
IoError(std::io::Error),
}

impl From<BinarySv2Error> for Error {
Expand All @@ -121,6 +122,12 @@ impl From<BinarySv2Error> for Error {
}
}

impl From<std::io::Error> for Error {
fn from(v: std::io::Error) -> Error {
Error::IoError(v)
}
}

impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
use Error::*;
Expand Down Expand Up @@ -205,6 +212,7 @@ impl Display for Error {
HashrateError(e) => write!(f, "Impossible to get Hashrate: {:?}", e),
LogicErrorMessage(e) => write!(f, "Message is well formatted but can not be handled: {:?}", e),
JDSMissingTransactions => write!(f, "JD server cannot propagate the block: missing transactions"),
IoError(e) => write!(f, "IO error: {:?}", e),
}
}
}
2 changes: 1 addition & 1 deletion roles/Cargo.lock

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

2 changes: 1 addition & 1 deletion roles/jd-client/src/lib/downstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ pub async fn listen_for_downstream_mining(
jd: Option<Arc<Mutex<JobDeclarator>>>,
) -> Result<Arc<Mutex<DownstreamMiningNode>>, Error> {
info!("Listening for downstream mining connections on {}", address);
let listner = TcpListener::bind(address).await.unwrap();
let listner = TcpListener::bind(address).await?;

if let Ok((stream, _)) = listner.accept().await {
let responder = Responder::from_authority_kp(
Expand Down
7 changes: 5 additions & 2 deletions roles/jd-client/src/lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl JobDeclaratorClient {
};

// Wait for downstream to connect
let downstream = downstream::listen_for_downstream_mining(
let downstream = match downstream::listen_for_downstream_mining(
downstream_addr,
Some(upstream),
send_solution,
Expand All @@ -351,7 +351,10 @@ impl JobDeclaratorClient {
Some(jd.clone()),
)
.await
.unwrap();
{
Ok(d) => d,
Err(_e) => return,
};

TemplateRx::connect(
SocketAddr::new(IpAddr::from_str(ip_tp.as_str()).unwrap(), port_tp),
Expand Down

0 comments on commit 151befc

Please sign in to comment.