Skip to content

Commit

Permalink
Merge pull request #776 from plebhash/no-downstreams-connected
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlenex committed Mar 12, 2024
2 parents 55fe7d4 + d7b1dc2 commit 361f12b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion roles/pool/src/lib/mining_pool/setup_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl SetupConnectionHandler {
)?;

let message = response.into_message().ok_or(PoolError::RolesLogic(
roles_logic_sv2::Error::UnexpectedMessage(message_type),
roles_logic_sv2::Error::NoDownstreamsConnected,
))?;

let sv2_frame: StdFrame = PoolMessages::Common(message.clone()).try_into()?;
Expand Down
27 changes: 20 additions & 7 deletions roles/pool/src/lib/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,22 @@ async fn send_status(
.unwrap_or(());
}
},
Sender::DownstreamListener(tx) => {
tx.send(Status {
state: State::DownstreamShutdown(e),
})
.await
.unwrap_or(());
}
Sender::DownstreamListener(tx) => match e {
PoolError::RolesLogic(roles_logic_sv2::Error::NoDownstreamsConnected) => {
tx.send(Status {
state: State::Healthy("No Downstreams Connected".to_string()),
})
.await
.unwrap_or(());
}
_ => {
tx.send(Status {
state: State::DownstreamShutdown(e),
})
.await
.unwrap_or(());
}
},
Sender::Upstream(tx) => {
tx.send(Status {
state: State::TemplateProviderShutdown(e),
Expand All @@ -101,6 +110,7 @@ async fn send_status(
}

// this is called by `error_handling::handle_result!`
// todo: as described in issue #777, we should replace every generic *(_) with specific errors and cover every possible combination
pub async fn handle_error(sender: &Sender, e: PoolError) -> error_handling::ErrorBranch {
tracing::debug!("Error: {:?}", &e);
match e {
Expand All @@ -117,6 +127,9 @@ pub async fn handle_error(sender: &Sender, e: PoolError) -> error_handling::Erro
PoolError::BinarySv2(_) => send_status(sender, e, error_handling::ErrorBranch::Break).await,
PoolError::Codec(_) => send_status(sender, e, error_handling::ErrorBranch::Break).await,
PoolError::Noise(_) => send_status(sender, e, error_handling::ErrorBranch::Continue).await,
PoolError::RolesLogic(roles_logic_sv2::Error::NoDownstreamsConnected) => {
send_status(sender, e, error_handling::ErrorBranch::Continue).await
}
PoolError::RolesLogic(_) => {
send_status(sender, e, error_handling::ErrorBranch::Break).await
}
Expand Down

0 comments on commit 361f12b

Please sign in to comment.