diff --git a/protocols/v2/roles-logic-sv2/src/errors.rs b/protocols/v2/roles-logic-sv2/src/errors.rs index dc528ade4f..1d8625124b 100644 --- a/protocols/v2/roles-logic-sv2/src/errors.rs +++ b/protocols/v2/roles-logic-sv2/src/errors.rs @@ -50,6 +50,7 @@ pub enum Error { NoValidJob, NoValidTranslatorJob, NoTemplateForId, + NoValidTemplate(String), InvalidExtranonceSize(u16, u16), PoisonLock(String), InvalidBip34Bytes(Vec), @@ -140,7 +141,8 @@ impl Display for Error { NotFoundChannelId => write!(f, "No downstream has been registred for this channel id"), NoValidJob => write!(f, "Impossible to create a standard job for channelA cause no valid job has been received from upstream yet"), NoValidTranslatorJob => write!(f, "Impossible to create a extended job for channel cause no valid job has been received from upstream yet"), - NoTemplateForId => write!(f, "Impossible a template for the required job id"), + NoTemplateForId => write!(f, "Impossible to retrieve a template for the required job id"), + NoValidTemplate(e) => write!(f, "Impossible to retrieve a template for the required template id: {}", e), PoisonLock(e) => write!(f, "Poison lock: {}", e), InvalidBip34Bytes(e) => write!(f, "Invalid Bip34 bytes {:?}", e), JobNotUpdated(ds_job_id, us_job_id) => write!(f, "Channel Factory did not update job: Downstream job id = {}, Upstream job id = {}", ds_job_id, us_job_id), diff --git a/roles/jd-client/src/lib/template_receiver/message_handler.rs b/roles/jd-client/src/lib/template_receiver/message_handler.rs index e9231f4470..61311f850f 100644 --- a/roles/jd-client/src/lib/template_receiver/message_handler.rs +++ b/roles/jd-client/src/lib/template_receiver/message_handler.rs @@ -43,6 +43,18 @@ impl ParseServerTemplateDistributionMessages for TemplateRx { &mut self, _m: RequestTransactionDataError, ) -> Result { - todo!() + let m = RequestTransactionDataError { + template_id: _m.template_id, + error_code: _m.error_code.into_static(), + }; + let error_code_string = + std::str::from_utf8(m.error_code.as_ref()).unwrap_or("unknown error code"); + match error_code_string { + "template-id-not-found" => Err(Error::NoValidTemplate(error_code_string.to_string())), + "stale-template-id" => Ok(SendTo::None(Some( + TemplateDistribution::RequestTransactionDataError(m), + ))), + _ => Err(Error::NoValidTemplate(error_code_string.to_string())), + } } } diff --git a/roles/jd-client/src/lib/template_receiver/mod.rs b/roles/jd-client/src/lib/template_receiver/mod.rs index 43275fda85..aad2f1ac37 100644 --- a/roles/jd-client/src/lib/template_receiver/mod.rs +++ b/roles/jd-client/src/lib/template_receiver/mod.rs @@ -17,7 +17,7 @@ use setup_connection::SetupConnectionHandler; use std::{convert::TryInto, net::SocketAddr, sync::Arc}; use stratum_common::bitcoin::{consensus::Encodable, TxOut}; use tokio::task::AbortHandle; -use tracing::{error, info}; +use tracing::{error, info, warn}; mod message_handler; mod setup_connection; @@ -264,6 +264,9 @@ impl TemplateRx { .await; } } + Some(TemplateDistribution::RequestTransactionDataError(_)) => { + warn!("The prev_hash of the template requested to Template Provider no longer points to the latest tip. Continuing work on the updated template.") + } _ => { error!("{:?}", frame); error!("{:?}", frame.payload());