Skip to content

Commit

Permalink
feat(host,provers,tasks): handle local job cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
petarvujovic98 committed Aug 15, 2024
1 parent 5ea0c33 commit 65e9fcd
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion host/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl ProofActor {
)
.await
.or_else(|e| {
if e.to_string().contains("no id found") {
if e.to_string().contains("No data for query") {
warn!("Task already cancelled or not yet started!");
Ok(())
} else {
Expand Down
11 changes: 10 additions & 1 deletion provers/risc0/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,16 @@ impl Prover for Risc0Prover {
}

async fn cancel(key: ProofKey, id_store: Box<&mut dyn IdStore>) -> ProverResult<()> {
let uuid = id_store.read_id(key).await?;
let uuid = match id_store.read_id(key).await {
Ok(uuid) => uuid,
Err(e) => {
if e.to_string().contains("No data for query") {
return Ok(());
} else {
return Err(ProverError::GuestError(e.to_string()));
}
}
};
cancel_proof(uuid)
.await
.map_err(|e| ProverError::GuestError(e.to_string()))?;
Expand Down
11 changes: 10 additions & 1 deletion provers/sp1/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,16 @@ impl Prover for Sp1Prover {
}

async fn cancel(key: ProofKey, id_store: Box<&mut dyn IdStore>) -> ProverResult<()> {
let proof_id = id_store.read_id(key).await?;
let proof_id = match id_store.read_id(key).await {
Ok(proof_id) => proof_id,
Err(e) => {
if e.to_string().contains("No data for query") {
return Ok(());
} else {
return Err(ProverError::GuestError(e.to_string()));
}
}
};
let private_key = env::var("SP1_PRIVATE_KEY").map_err(|_| {
ProverError::GuestError("SP1_PRIVATE_KEY must be set for remote proving".to_owned())
})?;
Expand Down
12 changes: 10 additions & 2 deletions tasks/src/adv_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,14 +824,22 @@ impl TaskDb {
1;
"#,
)?;
let query = statement.query_row(
let query = match statement.query_row(
named_params! {
":chain_id": chain_id,
":blockhash": blockhash.to_vec(),
":proofsys_id": proof_key,
},
|row| row.get::<_, String>(0),
)?;
) {
Ok(q) => q,
Err(e) => {
return match e {
rusqlite::Error::QueryReturnedNoRows => TaskManagerError::NoData,
e => e.into(),
}
}
};

Ok(query)
}
Expand Down
2 changes: 2 additions & 0 deletions tasks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub enum TaskManagerError {
IOError(IOErrorKind),
#[error("SQL Error {0}")]
SqlError(String),
#[error("No data for query")]
NoData,
#[error("Anyhow error: {0}")]
Anyhow(String),
}
Expand Down
2 changes: 1 addition & 1 deletion tasks/src/mem_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl InMemoryTaskDb {
self.store
.get(&key)
.cloned()
.ok_or_else(|| TaskManagerError::SqlError("no id found".to_owned()))
.ok_or_else(|| TaskManagerError::NoData)
}
}

Expand Down

0 comments on commit 65e9fcd

Please sign in to comment.