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
  • Loading branch information
jbesraa committed Jan 16, 2025
1 parent feee603 commit cd958d0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions protocols/v2/roles-logic-sv2/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub enum Error {
HashrateError(InputError),
LogicErrorMessage(std::boxed::Box<AllMessages<'static>>),
JDSMissingTransactions,
IoError(std::io::Error),
}

impl From<BinarySv2Error> for Error {
Expand Down Expand Up @@ -153,6 +154,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),
}
}
}
4 changes: 3 additions & 1 deletion roles/jd-client/src/lib/downstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,9 @@ 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
.map_err(|e| Error::IoError(e))?;

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 cd958d0

Please sign in to comment.