-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: complete v3 Aggregation APIs (#424)
* feat(host): complete the aggregation API * feat(tasks): complete aggregation task APIs Write in-memory implementation Stub out sqlite implementation * feat(host): update v3 Aggregation Cancel API All of theses changes were commentted and discussed at #387 1. Remove checking of empty proof of Aggregation Cancel request. For this case, querying task status will return None, and we will response with NotFound error directly. See also #387 (comment) 2. Remove metrics recording to maintain consistency with v1 and v2 See also #387 (comment) 3. Check task status before signal cancel to prover --------- Co-authored-by: Petar Vujovic <[email protected]> Co-authored-by: smtmfft <[email protected]>
- Loading branch information
1 parent
32bc6a9
commit 5dade7a
Showing
6 changed files
with
249 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
use crate::{ | ||
interfaces::{HostError, HostResult}, | ||
server::api::v2::CancelStatus, | ||
Message, ProverState, | ||
}; | ||
use axum::{debug_handler, extract::State, routing::post, Json, Router}; | ||
use raiko_core::interfaces::AggregationOnlyRequest; | ||
use raiko_tasks::{TaskManager, TaskStatus}; | ||
use utoipa::OpenApi; | ||
|
||
#[utoipa::path(post, path = "/proof/aggregate/cancel", | ||
tag = "Proving", | ||
request_body = AggregationOnlyRequest, | ||
responses ( | ||
(status = 200, description = "Successfully cancelled proof aggregation task", body = CancelStatus) | ||
) | ||
)] | ||
#[debug_handler(state = ProverState)] | ||
/// Cancel a proof aggregation task with requested config. | ||
/// | ||
/// Accepts a proof aggregation request and cancels a proving task with the specified guest prover. | ||
/// The guest provers currently available are: | ||
/// - native - constructs a block and checks for equality | ||
/// - sgx - uses the sgx environment to construct a block and produce proof of execution | ||
/// - sp1 - uses the sp1 prover | ||
/// - risc0 - uses the risc0 prover | ||
async fn cancel_handler( | ||
State(prover_state): State<ProverState>, | ||
Json(mut aggregation_request): Json<AggregationOnlyRequest>, | ||
) -> HostResult<CancelStatus> { | ||
// Override the existing proof request config from the config file and command line | ||
// options with the request from the client. | ||
aggregation_request.merge(&prover_state.request_config())?; | ||
|
||
let status = prover_state | ||
.task_manager() | ||
.get_aggregation_task_proving_status(&aggregation_request) | ||
.await?; | ||
|
||
let Some((latest_status, ..)) = status.0.last() else { | ||
return Err(HostError::Io(std::io::ErrorKind::NotFound.into())); | ||
}; | ||
|
||
let mut should_signal_cancel = false; | ||
let returning_cancel_status = match latest_status { | ||
/* Task is already cancelled, so we don't need further action */ | ||
TaskStatus::Cancelled | ||
| TaskStatus::Cancelled_Aborted | ||
| TaskStatus::Cancelled_NeverStarted | ||
| TaskStatus::CancellationInProgress => CancelStatus::Ok, | ||
|
||
/* Task is not completed, so we need to signal the prover to cancel */ | ||
TaskStatus::Registered | TaskStatus::WorkInProgress => { | ||
should_signal_cancel = true; | ||
CancelStatus::Ok | ||
} | ||
|
||
/* Task is completed with failure, so we don't need further action, but in case of | ||
* retry we safe to signal the prover to cancel */ | ||
TaskStatus::ProofFailure_Generic | ||
| TaskStatus::ProofFailure_OutOfMemory | ||
| TaskStatus::NetworkFailure(_) | ||
| TaskStatus::IoFailure(_) | ||
| TaskStatus::AnyhowError(_) | ||
| TaskStatus::GuestProverFailure(_) | ||
| TaskStatus::InvalidOrUnsupportedBlock | ||
| TaskStatus::UnspecifiedFailureReason | ||
| TaskStatus::TaskDbCorruption(_) => { | ||
should_signal_cancel = true; | ||
CancelStatus::Error { | ||
error: "Task already completed".to_string(), | ||
message: format!("Task already completed, status: {:?}", latest_status), | ||
} | ||
} | ||
|
||
/* Task is completed with success, so we return an error */ | ||
TaskStatus::Success => CancelStatus::Error { | ||
error: "Task already completed".to_string(), | ||
message: format!("Task already completed, status: {:?}", latest_status), | ||
}, | ||
}; | ||
|
||
if should_signal_cancel { | ||
prover_state | ||
.task_channel | ||
.try_send(Message::CancelAggregate(aggregation_request.clone()))?; | ||
|
||
let mut manager = prover_state.task_manager(); | ||
|
||
manager | ||
.update_aggregation_task_progress(&aggregation_request, TaskStatus::Cancelled, None) | ||
.await?; | ||
} | ||
|
||
Ok(returning_cancel_status) | ||
} | ||
|
||
#[derive(OpenApi)] | ||
#[openapi(paths(cancel_handler))] | ||
struct Docs; | ||
|
||
pub fn create_docs() -> utoipa::openapi::OpenApi { | ||
Docs::openapi() | ||
} | ||
|
||
pub fn create_router() -> Router<ProverState> { | ||
Router::new().route("/", post(cancel_handler)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use axum::{debug_handler, extract::State, routing::post, Router}; | ||
use raiko_tasks::TaskManager; | ||
use utoipa::OpenApi; | ||
|
||
use crate::{interfaces::HostResult, server::api::v2::PruneStatus, ProverState}; | ||
|
||
#[utoipa::path(post, path = "/proof/aggregate/prune", | ||
tag = "Proving", | ||
responses ( | ||
(status = 200, description = "Successfully pruned all aggregation tasks", body = PruneStatus) | ||
) | ||
)] | ||
#[debug_handler(state = ProverState)] | ||
/// Prune all aggregation tasks. | ||
async fn prune_handler(State(prover_state): State<ProverState>) -> HostResult<PruneStatus> { | ||
let mut manager = prover_state.task_manager(); | ||
|
||
manager.prune_aggregation_db().await?; | ||
|
||
Ok(PruneStatus::Ok) | ||
} | ||
|
||
#[derive(OpenApi)] | ||
#[openapi(paths(prune_handler))] | ||
struct Docs; | ||
|
||
pub fn create_docs() -> utoipa::openapi::OpenApi { | ||
Docs::openapi() | ||
} | ||
|
||
pub fn create_router() -> Router<ProverState> { | ||
Router::new().route("/", post(prune_handler)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use axum::{debug_handler, extract::State, routing::get, Json, Router}; | ||
use raiko_tasks::{AggregationTaskReport, TaskManager}; | ||
use utoipa::OpenApi; | ||
|
||
use crate::{interfaces::HostResult, ProverState}; | ||
|
||
#[utoipa::path(post, path = "/proof/aggregate/report", | ||
tag = "Proving", | ||
responses ( | ||
(status = 200, description = "Successfully retrieved a report of all aggregation tasks", body = AggregationTaskReport) | ||
) | ||
)] | ||
#[debug_handler(state = ProverState)] | ||
/// List all aggregation tasks. | ||
/// | ||
/// Retrieve a list of aggregation task reports. | ||
async fn report_handler( | ||
State(prover_state): State<ProverState>, | ||
) -> HostResult<Json<Vec<AggregationTaskReport>>> { | ||
let mut manager = prover_state.task_manager(); | ||
|
||
let task_report = manager.list_all_aggregation_tasks().await?; | ||
|
||
Ok(Json(task_report)) | ||
} | ||
|
||
#[derive(OpenApi)] | ||
#[openapi(paths(report_handler))] | ||
struct Docs; | ||
|
||
pub fn create_docs() -> utoipa::openapi::OpenApi { | ||
Docs::openapi() | ||
} | ||
|
||
pub fn create_router() -> Router<ProverState> { | ||
Router::new().route("/", get(report_handler)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters