diff --git a/service/api b/service/api index f2516cf2..8cdaf63d 160000 --- a/service/api +++ b/service/api @@ -1 +1 @@ -Subproject commit f2516cf212831b08fc1e9b84df6679d0eccf5b05 +Subproject commit 8cdaf63db88df84fb8aa40cb4ec5d52c53000561 diff --git a/service/build.rs b/service/build.rs index e66f81ca..a08fbf3c 100644 --- a/service/build.rs +++ b/service/build.rs @@ -1,10 +1,12 @@ use std::{env, path::PathBuf}; fn main() -> Result<(), Box> { + tonic_build::configure().compile(&["api/spacemesh/v1/post.proto"], &["api"])?; + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); tonic_build::configure() - .file_descriptor_set_path(out_dir.join("post_descriptor.bin")) - .compile(&["api/spacemesh/v1/post.proto"], &["api"])?; + .file_descriptor_set_path(out_dir.join("service_descriptor.bin")) + .compile(&["api/post/v1/service.proto"], &["api"])?; Ok(()) } diff --git a/service/src/operator.rs b/service/src/operator.rs index 3aa62603..3edc563b 100644 --- a/service/src/operator.rs +++ b/service/src/operator.rs @@ -9,13 +9,13 @@ use tokio::net::TcpListener; use tokio_stream::wrappers::TcpListenerStream; use tonic::{transport::Server, Request, Response, Status}; -use spacemesh_v1::post_service_operator_server::{PostServiceOperator, PostServiceOperatorServer}; -use spacemesh_v1::{PostServiceStatusRequest, PostServiceStatusResponse}; +use post_v1::operator_service_server::OperatorServiceServer; +use post_v1::{OperatorStatusRequest, OperatorStatusResponse}; -pub mod spacemesh_v1 { - tonic::include_proto!("spacemesh.v1"); +pub mod post_v1 { + tonic::include_proto!("post.v1"); pub(crate) const FILE_DESCRIPTOR_SET: &[u8] = - tonic::include_file_descriptor_set!("post_descriptor"); + tonic::include_file_descriptor_set!("service_descriptor"); } pub enum ServiceState { @@ -36,19 +36,21 @@ pub struct OperatorService { } #[tonic::async_trait] -impl PostServiceOperator for OperatorService { +impl post_v1::operator_service_server::OperatorService + for OperatorService +{ async fn status( &self, - request: Request, - ) -> Result, Status> { + request: Request, + ) -> Result, Status> { log::debug!("got a request from {:?}", request.remote_addr()); let status = match self.service.status() { - ServiceState::Idle => spacemesh_v1::post_service_status_response::Status::Idle, - ServiceState::Proving => spacemesh_v1::post_service_status_response::Status::Proving, + ServiceState::Idle => post_v1::operator_status_response::Status::Idle, + ServiceState::Proving => post_v1::operator_status_response::Status::Proving, }; - Ok(Response::new(PostServiceStatusResponse { + Ok(Response::new(OperatorStatusResponse { status: status as _, })) } @@ -65,10 +67,10 @@ impl OperatorServer { log::info!("running operator service on {}", listener.local_addr()?); let reflection_service = tonic_reflection::server::Builder::configure() - .register_encoded_file_descriptor_set(spacemesh_v1::FILE_DESCRIPTOR_SET) + .register_encoded_file_descriptor_set(post_v1::FILE_DESCRIPTOR_SET) .build()?; - let operator_service = PostServiceOperatorServer::new(OperatorService { service }); + let operator_service = OperatorServiceServer::new(OperatorService { service }); Server::builder() .add_service(reflection_service) @@ -85,9 +87,9 @@ mod tests { use tokio::net::TcpListener; - use super::spacemesh_v1::post_service_operator_client::PostServiceOperatorClient; - use super::spacemesh_v1::post_service_status_response::Status; - use super::spacemesh_v1::PostServiceStatusRequest; + use super::post_v1::operator_service_client::OperatorServiceClient; + use super::post_v1::operator_status_response::Status; + use super::post_v1::OperatorStatusRequest; #[tokio::test] async fn test_status() { @@ -104,14 +106,14 @@ mod tests { tokio::spawn(super::OperatorServer::run(listener, Arc::new(svc))); - let mut client = PostServiceOperatorClient::connect(format!("http://{addr}")) + let mut client = OperatorServiceClient::connect(format!("http://{addr}")) .await .unwrap(); - let response = client.status(PostServiceStatusRequest {}).await.unwrap(); + let response = client.status(OperatorStatusRequest {}).await.unwrap(); assert_eq!(response.into_inner().status(), Status::Idle); - let response = client.status(PostServiceStatusRequest {}).await.unwrap(); + let response = client.status(OperatorStatusRequest {}).await.unwrap(); assert_eq!(response.into_inner().status(), Status::Proving); } } diff --git a/service/tests/test_operator.rs b/service/tests/test_operator.rs index e957f300..9d172a56 100644 --- a/service/tests/test_operator.rs +++ b/service/tests/test_operator.rs @@ -11,9 +11,9 @@ use post::{ use post_service::{ client::spacemesh_v1::{service_response, GenProofStatus}, operator::{ - spacemesh_v1::{ - post_service_operator_client::PostServiceOperatorClient, - post_service_status_response::Status, PostServiceStatusRequest, + post_v1::{ + operator_service_client::OperatorServiceClient, operator_status_response::Status, + OperatorStatusRequest, }, OperatorServer, }, @@ -55,18 +55,16 @@ async fn test_gen_proof_in_progress() { let listener = TcpListener::bind("localhost:0").await.unwrap(); let operator_addr = format!("http://{}", listener.local_addr().unwrap()); tokio::spawn(OperatorServer::run(listener, service)); - let mut client = PostServiceOperatorClient::connect(operator_addr) - .await - .unwrap(); + let mut client = OperatorServiceClient::connect(operator_addr).await.unwrap(); // It starts in idle state - let response = client.status(PostServiceStatusRequest {}).await.unwrap(); + let response = client.status(OperatorStatusRequest {}).await.unwrap(); assert_eq!(response.into_inner().status(), Status::Idle); // It transforms to Proving when a proof generation starts let connected = test_server.connected.recv().await.unwrap(); TestServer::generate_proof(&connected, vec![0xCA; 32]).await; - let response = client.status(PostServiceStatusRequest {}).await.unwrap(); + let response = client.status(OperatorStatusRequest {}).await.unwrap(); assert_eq!(response.into_inner().status(), Status::Proving); loop { @@ -89,6 +87,6 @@ async fn test_gen_proof_in_progress() { } // It transforms back to Idle when the proof generation finishes - let response = client.status(PostServiceStatusRequest {}).await.unwrap(); + let response = client.status(OperatorStatusRequest {}).await.unwrap(); assert_eq!(response.into_inner().status(), Status::Idle); }