diff --git a/src/jd_client/mining_upstream/upstream.rs b/src/jd_client/mining_upstream/upstream.rs index 53ac13e8..08370315 100644 --- a/src/jd_client/mining_upstream/upstream.rs +++ b/src/jd_client/mining_upstream/upstream.rs @@ -578,7 +578,7 @@ impl ParseUpstreamMiningMessages Result, RolesLogicError> { + let error_code = std::str::from_utf8(&m.error_code.to_vec()) + .unwrap_or("unparsable error code") + .to_string(); + + if let Some(template_id) = self.template_to_job_id.take_template_id(m.request_id) { + error!( + "SetCustomMiningJobError for template {} (request_id={}, channel_id={}): {}", + template_id, m.request_id, m.channel_id, error_code, + ); + } else { + warn!( + "SetCustomMiningJobError with unknown request_id {} (channel_id={}): {}", + m.request_id, m.channel_id, error_code, + ); + } + IS_CUSTOM_JOB_SET.store(true, std::sync::atomic::Ordering::Release); Ok(SendTo::None(None)) } @@ -639,3 +655,47 @@ impl ParseUpstreamMiningMessages { + | Mining::UpdateChannelError(_) => { todo!(); } + //| Mining::SubmitSharesError(_) + //| Mining::SetCustomMiningJobError(_) // impossible state: handle_message_mining only returns // the above 3 messages in the Ok(SendTo::None(Some(m))) case to be sent // to the bridge for translation. @@ -867,12 +867,19 @@ impl ParseUpstreamMiningMessages Result, RolesLogicError> { - unimplemented!() + let error_code = std::str::from_utf8(&m.error_code.to_vec()) + .unwrap_or("unparsable error code") + .to_string(); + error!( + "Upstream rejected SetCustomMiningJob (request_id={}, channel_id={}): {}", + m.request_id, m.channel_id, error_code, + ); + Ok(SendTo::None(None)) } /// Handles the SV2 `SetTarget` message which updates the Downstream role(s) target @@ -1102,4 +1109,24 @@ mod tests { drop(diff_manager_abortable); drop(main_loop_abortable); } + + #[tokio::test] + async fn set_custom_mining_job_error_does_not_panic() { + use binary_sv2::Str0255; + use roles_logic_sv2::handlers::mining::ParseUpstreamMiningMessages; + use roles_logic_sv2::mining_sv2::SetCustomMiningJobError; + + let upstream = test_upstream().await; + let err = SetCustomMiningJobError { + channel_id: 1, + request_id: 0, + error_code: Str0255::try_from(String::from("invalid-mining-job-token")).unwrap(), + }; + + let result = upstream + .safe_lock(|u| u.handle_set_custom_mining_job_error(err)) + .unwrap(); + + assert!(matches!(result, Ok(SendTo::None(None)))); + } }