-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathmod.rs
149 lines (136 loc) · 4.35 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
use axum::{response::IntoResponse, Json, Router};
use raiko_lib::{proof_type::ProofType, prover::Proof};
use raiko_tasks::TaskStatus;
use serde::{Deserialize, Serialize};
use utoipa::{OpenApi, ToSchema};
use utoipa_scalar::{Scalar, Servable};
use utoipa_swagger_ui::SwaggerUi;
use crate::server::api::v1::{self, GuestOutputDoc};
use raiko_reqactor::Actor;
pub mod proof;
#[derive(OpenApi)]
#[openapi(
info(
title = "Raiko Proverd Server API",
version = "2.0",
description = "Raiko Proverd Server API",
contact(
name = "API Support",
url = "https://community.taiko.xyz",
email = "[email protected]",
),
license(
name = "MIT",
url = "https://github.com/taikoxyz/raiko/blob/main/LICENSE"
),
),
components(
schemas(
raiko_core::interfaces::ProofRequestOpt,
raiko_core::interfaces::ProverSpecificOpts,
crate::interfaces::HostError,
GuestOutputDoc,
ProofResponse,
TaskStatus,
CancelStatus,
PruneStatus,
Proof,
Status,
)
),
tags(
(name = "Proving", description = "Routes that handle proving requests"),
(name = "Health", description = "Routes that report the server health status"),
(name = "Metrics", description = "Routes that give detailed insight into the server")
)
)]
/// The root API struct which is generated from the `OpenApi` derive macro.
pub struct Docs;
#[derive(Debug, Deserialize, Serialize, ToSchema)]
#[serde(untagged)]
pub enum ProofResponse {
Status {
/// The status of the submitted task.
status: TaskStatus,
},
Proof {
/// The proof.
proof: Proof,
},
}
#[derive(Debug, Deserialize, Serialize, ToSchema)]
#[serde(tag = "status", rename_all = "lowercase")]
pub enum Status {
Ok {
#[serde(with = "raiko_lib::proof_type::lowercase")]
proof_type: ProofType,
#[serde(skip_serializing_if = "Option::is_none")]
batch_id: Option<u64>,
data: ProofResponse,
},
Error {
error: String,
message: String,
},
}
impl IntoResponse for Status {
fn into_response(self) -> axum::response::Response {
Json(serde_json::to_value(self).unwrap()).into_response()
}
}
#[derive(Debug, Deserialize, Serialize, ToSchema)]
#[serde(tag = "status", rename_all = "lowercase")]
/// Status of cancellation request.
/// Can be `ok` for a successful cancellation or `error` with message and error type for errors.
pub enum CancelStatus {
/// Cancellation was successful.
Ok,
/// Cancellation failed.
Error { error: String, message: String },
}
impl IntoResponse for CancelStatus {
fn into_response(self) -> axum::response::Response {
Json(serde_json::to_value(self).unwrap()).into_response()
}
}
#[derive(Debug, Serialize, ToSchema, Deserialize)]
#[serde(tag = "status", rename_all = "lowercase")]
/// Status of prune request.
/// Can be `ok` for a successful prune or `error` with message and error type for errors.
pub enum PruneStatus {
/// Prune was successful.
Ok,
/// Prune failed.
Error { error: String, message: String },
}
impl IntoResponse for PruneStatus {
fn into_response(self) -> axum::response::Response {
Json(serde_json::to_value(self).unwrap()).into_response()
}
}
#[must_use]
pub fn create_docs() -> utoipa::openapi::OpenApi {
[
v1::health::create_docs(),
v1::metrics::create_docs(),
proof::create_docs(),
]
.into_iter()
.fold(Docs::openapi(), |mut doc, sub_doc| {
doc.merge(sub_doc);
doc
})
}
pub fn create_router() -> Router<Actor> {
let docs = create_docs();
Router::new()
// Only add the concurrency limit to the proof route. We want to still be able to call
// healthchecks and metrics to have insight into the system.
.nest("/proof", proof::create_router())
// TODO: Separate task or try to get it into /proof somehow? Probably separate
.nest("/aggregate", proof::create_router())
.nest("/health", v1::health::create_router())
.nest("/metrics", v1::metrics::create_router())
.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", docs.clone()))
.merge(Scalar::with_url("/scalar", docs))
}