From 1141221e84e2661f78a86443a36d5b667c0d37cd Mon Sep 17 00:00:00 2001 From: "keroroxx520@gmail.com" Date: Thu, 21 Nov 2024 23:32:00 +0800 Subject: [PATCH] chore: explicitly express the types of Message --- host/src/lib.rs | 18 ------------------ host/src/server/api/v2/proof/cancel.rs | 4 +++- host/src/server/api/v2/proof/mod.rs | 4 ++-- host/src/server/api/v3/proof/aggregate.rs | 4 ++-- host/src/server/api/v3/proof/cancel.rs | 4 +++- host/src/server/api/v3/proof/mod.rs | 12 ++++++++---- 6 files changed, 18 insertions(+), 28 deletions(-) diff --git a/host/src/lib.rs b/host/src/lib.rs index 6445d6f2..b50c955d 100644 --- a/host/src/lib.rs +++ b/host/src/lib.rs @@ -167,24 +167,6 @@ pub enum Message { Aggregate(AggregationOnlyRequest), } -impl From<&ProofRequest> for Message { - fn from(value: &ProofRequest) -> Self { - Self::Task(value.clone()) - } -} - -impl From<&ProofTaskDescriptor> for Message { - fn from(value: &ProofTaskDescriptor) -> Self { - Self::Cancel(value.clone()) - } -} - -impl From for Message { - fn from(value: AggregationOnlyRequest) -> Self { - Self::Aggregate(value) - } -} - impl ProverState { pub fn init() -> HostResult { // Read the command line arguments; diff --git a/host/src/server/api/v2/proof/cancel.rs b/host/src/server/api/v2/proof/cancel.rs index 6ecc92f0..a941df4d 100644 --- a/host/src/server/api/v2/proof/cancel.rs +++ b/host/src/server/api/v2/proof/cancel.rs @@ -49,7 +49,9 @@ async fn cancel_handler( proof_request.prover.clone().to_string(), )); - prover_state.task_channel.try_send(Message::from(&key))?; + prover_state + .task_channel + .try_send(Message::Cancel(key.clone()))?; let mut manager = prover_state.task_manager(); diff --git a/host/src/server/api/v2/proof/mod.rs b/host/src/server/api/v2/proof/mod.rs index 1f3473ec..05b31f50 100644 --- a/host/src/server/api/v2/proof/mod.rs +++ b/host/src/server/api/v2/proof/mod.rs @@ -71,7 +71,7 @@ async fn proof_handler( prover_state .task_channel - .try_send(Message::from(&proof_request))?; + .try_send(Message::Task(proof_request))?; return Ok(TaskStatus::Registered.into()); }; @@ -88,7 +88,7 @@ async fn proof_handler( prover_state .task_channel - .try_send(Message::from(&proof_request))?; + .try_send(Message::Task(proof_request))?; Ok(TaskStatus::Registered.into()) } diff --git a/host/src/server/api/v3/proof/aggregate.rs b/host/src/server/api/v3/proof/aggregate.rs index 4416034a..a346c204 100644 --- a/host/src/server/api/v3/proof/aggregate.rs +++ b/host/src/server/api/v3/proof/aggregate.rs @@ -64,7 +64,7 @@ async fn aggregation_handler( prover_state .task_channel - .try_send(Message::from(aggregation_request.clone()))?; + .try_send(Message::Aggregate(aggregation_request))?; return Ok(Status::from(TaskStatus::Registered)); }; @@ -84,7 +84,7 @@ async fn aggregation_handler( prover_state .task_channel - .try_send(Message::from(aggregation_request))?; + .try_send(Message::Aggregate(aggregation_request))?; Ok(Status::from(TaskStatus::Registered)) } diff --git a/host/src/server/api/v3/proof/cancel.rs b/host/src/server/api/v3/proof/cancel.rs index ff19a5ed..36dcb976 100644 --- a/host/src/server/api/v3/proof/cancel.rs +++ b/host/src/server/api/v3/proof/cancel.rs @@ -52,7 +52,9 @@ async fn cancel_handler( proof_request.prover.clone().to_string(), )); - prover_state.task_channel.try_send(Message::from(&key))?; + prover_state + .task_channel + .try_send(Message::Cancel(key.clone()))?; let mut manager = prover_state.task_manager(); diff --git a/host/src/server/api/v3/proof/mod.rs b/host/src/server/api/v3/proof/mod.rs index 5429f421..d39a30ae 100644 --- a/host/src/server/api/v3/proof/mod.rs +++ b/host/src/server/api/v3/proof/mod.rs @@ -88,7 +88,9 @@ async fn proof_handler( // If there are no tasks with provided config, create a new one. manager.enqueue_task(key).await?; - prover_state.task_channel.try_send(Message::from(req))?; + prover_state + .task_channel + .try_send(Message::Task(req.to_owned()))?; is_registered = true; continue; }; @@ -103,7 +105,9 @@ async fn proof_handler( .update_task_progress(key.clone(), TaskStatus::Registered, None) .await?; - prover_state.task_channel.try_send(Message::from(req))?; + prover_state + .task_channel + .try_send(Message::Task(req.to_owned()))?; is_registered = true; is_success = false; @@ -155,7 +159,7 @@ async fn proof_handler( prover_state .task_channel - .try_send(Message::from(aggregation_request.clone()))?; + .try_send(Message::Aggregate(aggregation_request))?; return Ok(Status::from(TaskStatus::Registered)); }; @@ -175,7 +179,7 @@ async fn proof_handler( prover_state .task_channel - .try_send(Message::from(aggregation_request))?; + .try_send(Message::Aggregate(aggregation_request))?; Ok(Status::from(TaskStatus::Registered)) }