Skip to content

Commit

Permalink
chore: explicitly express the types of Message
Browse files Browse the repository at this point in the history
  • Loading branch information
keroro520 committed Nov 21, 2024
1 parent c388242 commit 1141221
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 28 deletions.
18 changes: 0 additions & 18 deletions host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AggregationOnlyRequest> for Message {
fn from(value: AggregationOnlyRequest) -> Self {
Self::Aggregate(value)
}
}

impl ProverState {
pub fn init() -> HostResult<Self> {
// Read the command line arguments;
Expand Down
4 changes: 3 additions & 1 deletion host/src/server/api/v2/proof/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions host/src/server/api/v2/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
};
Expand All @@ -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())
}
Expand Down
4 changes: 2 additions & 2 deletions host/src/server/api/v3/proof/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};

Expand All @@ -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))
}
Expand Down
4 changes: 3 additions & 1 deletion host/src/server/api/v3/proof/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
12 changes: 8 additions & 4 deletions host/src/server/api/v3/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;
Expand Down Expand Up @@ -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));
};

Expand All @@ -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))
}
Expand Down

0 comments on commit 1141221

Please sign in to comment.