From bc5245ecbabdf3d837abf53b31746a2ec608d796 Mon Sep 17 00:00:00 2001 From: Matt Stam Date: Fri, 18 Oct 2024 13:29:03 -0700 Subject: [PATCH] chore(sdk): update network-v2 proto (#1669) --- crates/sdk/src/network-v2/client.rs | 16 +- crates/sdk/src/network-v2/proto/artifact.rs | 4 +- crates/sdk/src/network-v2/proto/network.rs | 312 ++++++++++++++++++-- crates/sdk/src/network-v2/prover.rs | 2 +- 4 files changed, 295 insertions(+), 39 deletions(-) diff --git a/crates/sdk/src/network-v2/client.rs b/crates/sdk/src/network-v2/client.rs index 362d7a08c5..e3f9907495 100644 --- a/crates/sdk/src/network-v2/client.rs +++ b/crates/sdk/src/network-v2/client.rs @@ -63,7 +63,6 @@ impl NetworkClient { // Check if the URL scheme is HTTPS and configure TLS. if rpc_url.starts_with("https://") { - println!("Using TLS"); let tls_config = ClientTlsConfig::new().with_enabled_roots(); endpoint = endpoint.tls_config(tls_config)?; } @@ -79,7 +78,6 @@ impl NetworkClient { // Check if the URL scheme is HTTPS and configure TLS. if rpc_url.starts_with("https://") { - println!("Using TLS"); let tls_config = ClientTlsConfig::new().with_enabled_roots(); endpoint = endpoint.tls_config(tls_config)?; } @@ -118,7 +116,7 @@ impl NetworkClient { }) .await? .into_inner(); - let status = ProofStatus::try_from(res.status)?; + let status = ProofStatus::try_from(res.proof_status)?; let proof = match status { ProofStatus::Fulfilled => { log::info!("Proof request fulfilled"); @@ -138,14 +136,18 @@ impl NetworkClient { /// Get all the proof requests for a given status. Also filter by version if provided. pub async fn get_filtered_proof_requests( &self, - status: ProofStatus, - version: Option<&str>, + version: Option, + proof_status: Option, + execution_status: Option, + limit: Option, ) -> Result { let mut rpc = self.get_rpc().await?; let res = rpc .get_filtered_proof_requests(GetFilteredProofRequestsRequest { - status: status.into(), - version: version.map(|v| v.to_string()).unwrap_or_default(), + version, + proof_status, + execution_status, + limit, }) .await? .into_inner(); diff --git a/crates/sdk/src/network-v2/proto/artifact.rs b/crates/sdk/src/network-v2/proto/artifact.rs index f35dcdf8e3..f635654c39 100644 --- a/crates/sdk/src/network-v2/proto/artifact.rs +++ b/crates/sdk/src/network-v2/proto/artifact.rs @@ -98,7 +98,7 @@ pub mod artifact_store_client { self.inner = self.inner.max_encoding_message_size(limit); self } - /// / Creates an artifact that can be used for proof requests. + /// Creates an artifact that can be used for proof requests. pub async fn create_artifact( &mut self, request: impl tonic::IntoRequest, @@ -127,7 +127,7 @@ pub mod artifact_store_server { /// Generated trait containing gRPC methods that should be implemented for use with ArtifactStoreServer. #[async_trait] pub trait ArtifactStore: std::marker::Send + std::marker::Sync + 'static { - /// / Creates an artifact that can be used for proof requests. + /// Creates an artifact that can be used for proof requests. async fn create_artifact( &self, request: tonic::Request, diff --git a/crates/sdk/src/network-v2/proto/network.rs b/crates/sdk/src/network-v2/proto/network.rs index 9b7a1a89ec..52d72ae958 100644 --- a/crates/sdk/src/network-v2/proto/network.rs +++ b/crates/sdk/src/network-v2/proto/network.rs @@ -1,12 +1,19 @@ // This file is @generated by prost-build. #[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)] pub struct GetFilteredProofRequestsRequest { - /// The status of the proof requests to filter for. - #[prost(enumeration = "ProofStatus", tag = "1")] - pub status: i32, - /// The version of the proof requests to filter for. - #[prost(string, tag = "2")] - pub version: ::prost::alloc::string::String, + /// The optional version of the proof requests to filter for. + #[prost(string, optional, tag = "1")] + pub version: ::core::option::Option<::prost::alloc::string::String>, + /// The optional proof status of the proof requests to filter for. + #[prost(enumeration = "ProofStatus", optional, tag = "2")] + pub proof_status: ::core::option::Option, + /// The optional execution status of the proof requests to filter for. + #[prost(enumeration = "ExecutionStatus", optional, tag = "3")] + pub execution_status: ::core::option::Option, + /// The optional maximum number of proof requests to return (default is 10, + /// maximum is 100). + #[prost(uint32, optional, tag = "4")] + pub limit: ::core::option::Option, } #[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)] pub struct ProofRequest { @@ -34,11 +41,14 @@ pub struct ProofRequest { /// The cycle limit for the proof. #[prost(uint64, tag = "9")] pub cycle_limit: u64, - /// The status of the proof request. + /// The proof status of the proof request. #[prost(enumeration = "ProofStatus", tag = "10")] - pub status: i32, + pub proof_status: i32, + /// The execution status of the proof request. + #[prost(enumeration = "ExecutionStatus", tag = "11")] + pub execution_status: i32, /// The requester address. - #[prost(bytes = "vec", tag = "11")] + #[prost(bytes = "vec", tag = "12")] pub requester: ::prost::alloc::vec::Vec, } #[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)] @@ -88,10 +98,10 @@ pub struct RequestProofRequestBody { } #[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)] pub struct RequestProofResponse { - /// / The transaction hash. + /// The transaction hash. #[prost(bytes = "vec", tag = "1")] pub tx_hash: ::prost::alloc::vec::Vec, - /// / The body of the response. + /// The body of the response. #[prost(message, optional, tag = "2")] pub body: ::core::option::Option, } @@ -124,16 +134,56 @@ pub struct FulfillProofRequestBody { } #[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)] pub struct FulfillProofResponse { - /// / The transaction hash. + /// The transaction hash. #[prost(bytes = "vec", tag = "1")] pub tx_hash: ::prost::alloc::vec::Vec, - /// / The body of the response. + /// The body of the response. #[prost(message, optional, tag = "2")] pub body: ::core::option::Option, } #[derive(serde::Serialize, serde::Deserialize, Clone, Copy, PartialEq, ::prost::Message)] pub struct FulfillProofResponseBody {} #[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)] +pub struct ExecuteProofRequest { + /// The signature of the sender. + #[prost(bytes = "vec", tag = "1")] + pub signature: ::prost::alloc::vec::Vec, + /// The body of the request. + #[prost(message, optional, tag = "3")] + pub body: ::core::option::Option, +} +#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)] +pub struct ExecuteProofRequestBody { + /// The nonce of the request. + #[prost(uint64, tag = "1")] + pub nonce: u64, + /// The identifier for the proof request. + #[prost(bytes = "vec", tag = "2")] + pub request_id: ::prost::alloc::vec::Vec, + /// The execution status of the request. + #[prost(enumeration = "ExecutionStatus", tag = "3")] + pub execution_status: i32, + /// The optional public values hash of the request execution, only included if + /// the request is valid. + #[prost(bytes = "vec", optional, tag = "4")] + pub public_values_hash: ::core::option::Option<::prost::alloc::vec::Vec>, + /// The optional cycles of the request execution, only included if the request + /// is valid. + #[prost(uint64, optional, tag = "5")] + pub cycles: ::core::option::Option, +} +#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)] +pub struct ExecuteProofResponse { + /// The transaction hash. + #[prost(bytes = "vec", tag = "1")] + pub tx_hash: ::prost::alloc::vec::Vec, + /// The body of the response. + #[prost(message, optional, tag = "2")] + pub body: ::core::option::Option, +} +#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, PartialEq, ::prost::Message)] +pub struct ExecuteProofResponseBody {} +#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)] pub struct GetBalanceRequest { /// The address of the account. #[prost(bytes = "vec", tag = "1")] @@ -141,11 +191,43 @@ pub struct GetBalanceRequest { } #[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)] pub struct GetBalanceResponse { - /// The amount of the token owned by the account. + /// The amount of credits owned by the account. #[prost(string, tag = "1")] pub amount: ::prost::alloc::string::String, } #[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)] +pub struct AddCreditRequest { + /// The signature of the sender. + #[prost(bytes = "vec", tag = "1")] + pub signature: ::prost::alloc::vec::Vec, + /// The body of the request. + #[prost(message, optional, tag = "3")] + pub body: ::core::option::Option, +} +#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)] +pub struct AddCreditRequestBody { + /// The nonce of the request. + #[prost(uint64, tag = "1")] + pub nonce: u64, + /// The address of the account to add credits to. + #[prost(bytes = "vec", tag = "2")] + pub address: ::prost::alloc::vec::Vec, + /// The amount of credits to add. + #[prost(string, tag = "3")] + pub amount: ::prost::alloc::string::String, +} +#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)] +pub struct AddCreditResponse { + /// The transaction hash. + #[prost(bytes = "vec", tag = "1")] + pub tx_hash: ::prost::alloc::vec::Vec, + /// The body of the response. + #[prost(message, optional, tag = "2")] + pub body: ::core::option::Option, +} +#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, PartialEq, ::prost::Message)] +pub struct AddCreditResponseBody {} +#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, ::prost::Message)] pub struct GetNonceRequest { /// The address of the account. #[prost(bytes = "vec", tag = "1")] @@ -167,23 +249,26 @@ pub struct GetProofRequestStatusRequest { pub struct GetProofRequestStatusResponse { /// The status of the proof request. #[prost(enumeration = "ProofStatus", tag = "1")] - pub status: i32, + pub proof_status: i32, + /// The execution status of the proof request. + #[prost(enumeration = "ExecutionStatus", tag = "2")] + pub execution_status: i32, /// The transaction hash of the proof request. - #[prost(bytes = "vec", tag = "2")] + #[prost(bytes = "vec", tag = "3")] pub request_tx_hash: ::prost::alloc::vec::Vec, - /// The optional transaction hash of the proof fulfill. Only included if the proof request has a - /// status of FULFILLED. - #[prost(bytes = "vec", optional, tag = "3")] + /// The optional transaction hash of the proof fulfill. Only included if the + /// proof request has a status of FULFILLED. + #[prost(bytes = "vec", optional, tag = "4")] pub fulfill_tx_hash: ::core::option::Option<::prost::alloc::vec::Vec>, - /// The optional proof URI, where you can download the result of the proof request. Only included - /// if the proof has a status of FULFILLED. - #[prost(string, optional, tag = "4")] + /// The optional proof URI, where you can download the result of the proof + /// request. Only included if the proof has a status of FULFILLED. + #[prost(string, optional, tag = "5")] pub proof_uri: ::core::option::Option<::prost::alloc::string::String>, /// The optional error status code, if the request failed. - #[prost(uint32, optional, tag = "5")] + #[prost(uint32, optional, tag = "6")] pub error_code: ::core::option::Option, /// The optional error description details, if the request failed. - #[prost(string, optional, tag = "6")] + #[prost(string, optional, tag = "7")] pub error_description: ::core::option::Option<::prost::alloc::string::String>, } #[derive( @@ -286,7 +371,7 @@ impl ProofStrategy { )] #[repr(i32)] pub enum ProofStatus { - UnspecifiedStatus = 0, + UnspecifiedProofStatus = 0, Requested = 1, Assigned = 2, Fulfilled = 3, @@ -298,7 +383,7 @@ impl ProofStatus { /// (if the ProtoBuf definition does not change) and safe for programmatic use. pub fn as_str_name(&self) -> &'static str { match self { - Self::UnspecifiedStatus => "UNSPECIFIED_STATUS", + Self::UnspecifiedProofStatus => "UNSPECIFIED_PROOF_STATUS", Self::Requested => "REQUESTED", Self::Assigned => "ASSIGNED", Self::Fulfilled => "FULFILLED", @@ -307,7 +392,7 @@ impl ProofStatus { /// Creates an enum from field names used in the ProtoBuf definition. pub fn from_str_name(value: &str) -> ::core::option::Option { match value { - "UNSPECIFIED_STATUS" => Some(Self::UnspecifiedStatus), + "UNSPECIFIED_PROOF_STATUS" => Some(Self::UnspecifiedProofStatus), "REQUESTED" => Some(Self::Requested), "ASSIGNED" => Some(Self::Assigned), "FULFILLED" => Some(Self::Fulfilled), @@ -315,6 +400,50 @@ impl ProofStatus { } } } +#[derive( + serde::Serialize, + serde::Deserialize, + Clone, + Copy, + Debug, + PartialEq, + Eq, + Hash, + PartialOrd, + Ord, + ::prost::Enumeration, +)] +#[repr(i32)] +pub enum ExecutionStatus { + UnspecifiedExecutionStatus = 0, + Unexecuted = 1, + Executed = 2, + Failed = 3, +} +impl ExecutionStatus { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Self::UnspecifiedExecutionStatus => "UNSPECIFIED_EXECUTION_STATUS", + Self::Unexecuted => "UNEXECUTED", + Self::Executed => "EXECUTED", + Self::Failed => "FAILED", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "UNSPECIFIED_EXECUTION_STATUS" => Some(Self::UnspecifiedExecutionStatus), + "UNEXECUTED" => Some(Self::Unexecuted), + "EXECUTED" => Some(Self::Executed), + "FAILED" => Some(Self::Failed), + _ => None, + } + } +} /// Generated client implementations. pub mod prover_network_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] @@ -435,6 +564,24 @@ pub mod prover_network_client { req.extensions_mut().insert(GrpcMethod::new("network.ProverNetwork", "FulfillProof")); self.inner.unary(req, path, codec).await } + /// Execute a proof. + pub async fn execute_proof( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result, tonic::Status> + { + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static("/network.ProverNetwork/ExecuteProof"); + let mut req = request.into_request(); + req.extensions_mut().insert(GrpcMethod::new("network.ProverNetwork", "ExecuteProof")); + self.inner.unary(req, path, codec).await + } /// Get the proof requests the meet the filter criteria. pub async fn get_filtered_proof_requests( &mut self, @@ -479,7 +626,7 @@ pub mod prover_network_client { .insert(GrpcMethod::new("network.ProverNetwork", "GetProofRequestStatus")); self.inner.unary(req, path, codec).await } - /// Get the balance of the account. + /// Get the balance of an account. pub async fn get_balance( &mut self, request: impl tonic::IntoRequest, @@ -497,6 +644,23 @@ pub mod prover_network_client { req.extensions_mut().insert(GrpcMethod::new("network.ProverNetwork", "GetBalance")); self.inner.unary(req, path, codec).await } + /// Add credit to an account. + pub async fn add_credit( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result, tonic::Status> { + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static("/network.ProverNetwork/AddCredit"); + let mut req = request.into_request(); + req.extensions_mut().insert(GrpcMethod::new("network.ProverNetwork", "AddCredit")); + self.inner.unary(req, path, codec).await + } /// Get the nonce of the account. pub async fn get_nonce( &mut self, @@ -533,6 +697,11 @@ pub mod prover_network_server { &self, request: tonic::Request, ) -> std::result::Result, tonic::Status>; + /// Execute a proof. + async fn execute_proof( + &self, + request: tonic::Request, + ) -> std::result::Result, tonic::Status>; /// Get the proof requests the meet the filter criteria. async fn get_filtered_proof_requests( &self, @@ -546,11 +715,16 @@ pub mod prover_network_server { &self, request: tonic::Request, ) -> std::result::Result, tonic::Status>; - /// Get the balance of the account. + /// Get the balance of an account. async fn get_balance( &self, request: tonic::Request, ) -> std::result::Result, tonic::Status>; + /// Add credit to an account. + async fn add_credit( + &self, + request: tonic::Request, + ) -> std::result::Result, tonic::Status>; /// Get the nonce of the account. async fn get_nonce( &self, @@ -712,6 +886,47 @@ pub mod prover_network_server { }; Box::pin(fut) } + "/network.ProverNetwork/ExecuteProof" => { + #[allow(non_camel_case_types)] + struct ExecuteProofSvc(pub Arc); + impl tonic::server::UnaryService + for ExecuteProofSvc + { + type Response = super::ExecuteProofResponse; + type Future = BoxFuture, tonic::Status>; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::execute_proof(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let method = ExecuteProofSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } "/network.ProverNetwork/GetFilteredProofRequests" => { #[allow(non_camel_case_types)] struct GetFilteredProofRequestsSvc(pub Arc); @@ -837,6 +1052,45 @@ pub mod prover_network_server { }; Box::pin(fut) } + "/network.ProverNetwork/AddCredit" => { + #[allow(non_camel_case_types)] + struct AddCreditSvc(pub Arc); + impl tonic::server::UnaryService for AddCreditSvc { + type Response = super::AddCreditResponse; + type Future = BoxFuture, tonic::Status>; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + ::add_credit(&inner, request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let method = AddCreditSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } "/network.ProverNetwork/GetNonce" => { #[allow(non_camel_case_types)] struct GetNonceSvc(pub Arc); diff --git a/crates/sdk/src/network-v2/prover.rs b/crates/sdk/src/network-v2/prover.rs index 19746b71bb..5b5b903dfc 100644 --- a/crates/sdk/src/network-v2/prover.rs +++ b/crates/sdk/src/network-v2/prover.rs @@ -123,7 +123,7 @@ impl NetworkProver { let (status, maybe_proof) = self.client.get_proof_request_status::

(request_id).await?; - match status.status() { + match status.proof_status() { ProofStatus::Fulfilled => { return Ok(maybe_proof.unwrap()); }