Skip to content

Commit

Permalink
response types
Browse files Browse the repository at this point in the history
  • Loading branch information
S1nus committed Jan 17, 2025
1 parent e2bf052 commit 8c6fca4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
7 changes: 6 additions & 1 deletion service/proto/eqservice.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ message GetKeccakInclusionRequest {
message GetKeccakInclusionResponse {
enum Status {
WAITING = 0;
COMPLETE = 1;
COMPLETE = 1;
FAILED = 2;
}
Status status = 1;
oneof response_value {
string proof_id = 2; // Used when status is WAITING
bytes proof = 3; // Used when status is COMPLETE
string error_message = 4; // Used when status is FAILED
}
}
18 changes: 17 additions & 1 deletion service/src/generated/eqs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ pub struct GetKeccakInclusionRequest {
#[prost(uint64, tag = "3")]
pub height: u64,
}
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetKeccakInclusionResponse {
#[prost(enumeration = "get_keccak_inclusion_response::Status", tag = "1")]
pub status: i32,
#[prost(oneof = "get_keccak_inclusion_response::ResponseValue", tags = "2, 3, 4")]
pub response_value: ::core::option::Option<
get_keccak_inclusion_response::ResponseValue,
>,
}
/// Nested message and enum types in `GetKeccakInclusionResponse`.
pub mod get_keccak_inclusion_response {
Expand Down Expand Up @@ -57,6 +61,18 @@ pub mod get_keccak_inclusion_response {
}
}
}
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum ResponseValue {
/// Used when status is WAITING
#[prost(string, tag = "2")]
ProofId(::prost::alloc::string::String),
/// Used when status is COMPLETE
#[prost(bytes, tag = "3")]
Proof(::prost::alloc::vec::Vec<u8>),
/// Used when status is FAILED
#[prost(string, tag = "4")]
ErrorMessage(::prost::alloc::string::String),
}
}
/// Generated client implementations.
pub mod inclusion_client {
Expand Down
33 changes: 30 additions & 3 deletions service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod eqs {
include!("generated/eqs.rs");
}
use eqs::inclusion_server::{Inclusion, InclusionServer};
use eqs::{GetKeccakInclusionRequest, GetKeccakInclusionResponse};
use eqs::{GetKeccakInclusionRequest, GetKeccakInclusionResponse, get_keccak_inclusion_response::{ResponseValue, Status as ResponseStatus}};

use celestia_rpc::{BlobClient, Client, HeaderClient};
use celestia_types::nmt::{Namespace, NamespacedHashExt};
Expand Down Expand Up @@ -35,11 +35,13 @@ pub struct Job {

#[derive(Serialize, Deserialize)]
pub enum JobStatus {
Pending,
// The Succinct Network job ID
Pending(String),
// For now we'll use the SP1ProofWithPublicValues as the proof
// Ideally we only want the public values + whatever is needed to verify the proof
// They don't seem to provide a type for that.
Completed(SP1ProofWithPublicValues),
Failed(String),
}
pub struct InclusionService {
client: Arc<Client>,
Expand All @@ -62,6 +64,31 @@ impl Inclusion for InclusionService {
commitment: request.commitment.clone(),
}).map_err(|e| Status::internal(e.to_string()))?).map_err(|e| Status::internal(e.to_string()))?;

if let Some(job) = job_from_db {
let job: JobStatus = bincode::deserialize(&job)
.map_err(|e| Status::internal(e.to_string()))?;
match job {
JobStatus::Pending(job_id) => {
return Ok(Response::new(GetKeccakInclusionResponse {
status: ResponseStatus::Waiting as i32,
response_value: Some(ResponseValue::ProofId(job_id))
}));
}
JobStatus::Completed(proof) => {
return Ok(Response::new(GetKeccakInclusionResponse {
status: ResponseStatus::Complete as i32,
response_value: Some(ResponseValue::Proof(bincode::serialize(&proof).map_err(|e| Status::internal(e.to_string()))?))
}));
}
JobStatus::Failed(error) => {
return Ok(Response::new(GetKeccakInclusionResponse {
status: ResponseStatus::Failed as i32,
response_value: Some(ResponseValue::ErrorMessage(error))
}));
}
}
}

let height = request.height;
let commitment = Commitment::new(
request.commitment
Expand All @@ -87,7 +114,7 @@ impl Inclusion for InclusionService {
let inclusion_proof_input = create_inclusion_proof_input(&blob, &header, nmt_multiproofs)
.map_err(|e| Status::internal(e.to_string()))?;

Ok(Response::new(GetKeccakInclusionResponse { status: 0 }))
Ok(Response::new(GetKeccakInclusionResponse { status: 0, response_value: None }))
}
}

Expand Down

0 comments on commit 8c6fca4

Please sign in to comment.