-
Notifications
You must be signed in to change notification settings - Fork 168
BM-1547: move lift to join #1079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zeroecco
wants to merge
5
commits into
main
Choose a base branch
from
zeroecco/keydb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+298
−215
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f7ae9bd
move lift to join
zeroecco 6a974d1
Merge branch 'main' into zeroecco/keydb
zeroecco e9d8361
Merge branch 'main' into zeroecco/keydb
zeroecco d37d79a
Merge branch 'main' into zeroecco/keydb
zeroecco c235f70
Merge branch 'main' into zeroecco/keydb
zeroecco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ use crate::{ | |
| tasks::{RECUR_RECEIPT_PATH, deserialize_obj, serialize_obj}, | ||
| }; | ||
| use anyhow::{Context, Result}; | ||
| use risc0_zkvm::{ReceiptClaim, SuccinctReceipt}; | ||
| use risc0_zkvm::{ReceiptClaim, SegmentReceipt, SuccinctReceipt}; | ||
| use uuid::Uuid; | ||
| use workflow_common::JoinReq; | ||
|
|
||
|
|
@@ -23,15 +23,52 @@ pub async fn join(agent: &Agent, job_id: &Uuid, request: &JoinReq) -> Result<()> | |
| let left_path_key = format!("{recur_receipts_prefix}:{}", request.left); | ||
| let right_path_key = format!("{recur_receipts_prefix}:{}", request.right); | ||
|
|
||
| let (left_receipt, right_receipt): (Vec<u8>, Vec<u8>) = | ||
| let (left_receipt_data, right_receipt_data): (Vec<u8>, Vec<u8>) = | ||
| conn.mget::<_, (Vec<u8>, Vec<u8>)>(&[&left_path_key, &right_path_key]).await.with_context( | ||
| || format!("failed to get receipts for keys: {left_path_key}, {right_path_key}"), | ||
| )?; | ||
|
|
||
| let left_receipt: SuccinctReceipt<ReceiptClaim> = | ||
| deserialize_obj(&left_receipt).context("Failed to deserialize left receipt")?; | ||
| let right_receipt: SuccinctReceipt<ReceiptClaim> = | ||
| deserialize_obj(&right_receipt).context("Failed to deserialize right receipt")?; | ||
| // Handle each receipt independently - they could be mixed types | ||
| let prover = agent.prover.as_ref().context("Missing prover from resolve task")?; | ||
| let left_idx = request.left; | ||
| let right_idx = request.right; | ||
|
|
||
| let (left_receipt, right_receipt) = tokio::try_join!( | ||
| async { | ||
| match deserialize_obj::<SegmentReceipt>(&left_receipt_data) { | ||
| Ok(segment) => { | ||
| let receipt = prover | ||
| .lift(&segment) | ||
| .with_context(|| format!("Failed to lift segment {left_idx}"))?; | ||
| tracing::debug!("lifting complete {job_id} - {left_idx}"); | ||
| Ok::<_, anyhow::Error>(receipt) | ||
| } | ||
| Err(_) => { | ||
| let receipt: SuccinctReceipt<ReceiptClaim> = | ||
| deserialize_obj(&left_receipt_data) | ||
| .context("Failed to deserialize left receipt")?; | ||
| Ok(receipt) | ||
| } | ||
| } | ||
| }, | ||
| async { | ||
| match deserialize_obj::<SegmentReceipt>(&right_receipt_data) { | ||
| Ok(segment) => { | ||
| let receipt = prover | ||
| .lift(&segment) | ||
| .with_context(|| format!("Failed to lift segment {right_idx}"))?; | ||
| tracing::debug!("lifting complete {job_id} - {right_idx}"); | ||
| Ok::<_, anyhow::Error>(receipt) | ||
| } | ||
| Err(_) => { | ||
| let receipt: SuccinctReceipt<ReceiptClaim> = | ||
| deserialize_obj(&right_receipt_data) | ||
| .context("Failed to deserialize right receipt")?; | ||
| Ok(receipt) | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+37
to
+70
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: duplication here and in join_povw could be removed if you want: diff --git a/bento/crates/workflow/src/tasks/join.rs b/bento/crates/workflow/src/tasks/join.rs
index 2758570c..240518b9 100644
--- a/bento/crates/workflow/src/tasks/join.rs
+++ b/bento/crates/workflow/src/tasks/join.rs
@@ -3,16 +3,40 @@
// Use of this source code is governed by the Business Source License
// as found in the LICENSE-BSL file.
+use std::rc::Rc;
+
use crate::{
Agent,
redis::{self, AsyncCommands},
tasks::{RECUR_RECEIPT_PATH, deserialize_obj, serialize_obj},
};
use anyhow::{Context, Result};
-use risc0_zkvm::{ReceiptClaim, SegmentReceipt, SuccinctReceipt};
+use risc0_zkvm::{ProverServer, ReceiptClaim, SegmentReceipt, SuccinctReceipt};
use uuid::Uuid;
use workflow_common::JoinReq;
+/// Lifts a receipt if it's a segment receipt, otherwise returns it as-is
+async fn lift_or_deserialize_receipt(
+ prover: &Rc<dyn ProverServer>,
+ receipt_data: &[u8],
+ idx: usize,
+ job_id: &Uuid,
+) -> Result<SuccinctReceipt<ReceiptClaim>> {
+ match deserialize_obj::<SegmentReceipt>(receipt_data) {
+ Ok(segment) => {
+ let receipt =
+ prover.lift(&segment).with_context(|| format!("Failed to lift segment {idx}"))?;
+ tracing::debug!("lifting complete {job_id} - {idx}");
+ Ok(receipt)
+ }
+ Err(_) => {
+ let receipt: SuccinctReceipt<ReceiptClaim> = deserialize_obj(receipt_data)
+ .with_context(|| format!("Failed to deserialize receipt {idx}"))?;
+ Ok(receipt)
+ }
+ }
+}
+
/// Run the join operation
pub async fn join(agent: &Agent, job_id: &Uuid, request: &JoinReq) -> Result<()> {
let mut conn = agent.redis_pool.get().await?;
@@ -29,45 +53,11 @@ pub async fn join(agent: &Agent, job_id: &Uuid, request: &JoinReq) -> Result<()>
)?;
// Handle each receipt independently - they could be mixed types
- let prover = agent.prover.as_ref().context("Missing prover from resolve task")?;
- let left_idx = request.left;
- let right_idx = request.right;
+ let prover = agent.prover.as_ref().context("Missing prover from join task")?;
let (left_receipt, right_receipt) = tokio::try_join!(
- async {
- match deserialize_obj::<SegmentReceipt>(&left_receipt_data) {
- Ok(segment) => {
- let receipt = prover
- .lift(&segment)
- .with_context(|| format!("Failed to lift segment {left_idx}"))?;
- tracing::debug!("lifting complete {job_id} - {left_idx}");
- Ok::<_, anyhow::Error>(receipt)
- }
- Err(_) => {
- let receipt: SuccinctReceipt<ReceiptClaim> =
- deserialize_obj(&left_receipt_data)
- .context("Failed to deserialize left receipt")?;
- Ok(receipt)
- }
- }
- },
- async {
- match deserialize_obj::<SegmentReceipt>(&right_receipt_data) {
- Ok(segment) => {
- let receipt = prover
- .lift(&segment)
- .with_context(|| format!("Failed to lift segment {right_idx}"))?;
- tracing::debug!("lifting complete {job_id} - {right_idx}");
- Ok::<_, anyhow::Error>(receipt)
- }
- Err(_) => {
- let receipt: SuccinctReceipt<ReceiptClaim> =
- deserialize_obj(&right_receipt_data)
- .context("Failed to deserialize right receipt")?;
- Ok(receipt)
- }
- }
- }
+ lift_or_deserialize_receipt(prover, &left_receipt_data, request.left, job_id),
+ lift_or_deserialize_receipt(prover, &right_receipt_data, request.right, job_id)
)?;
tracing::trace!("Joining {job_id} - {} + {} -> {}", request.left, request.right, request.idx);
diff --git a/bento/crates/workflow/src/tasks/join_povw.rs b/bento/crates/workflow/src/tasks/join_povw.rs
index ea5e4b1b..0408c848 100644
--- a/bento/crates/workflow/src/tasks/join_povw.rs
+++ b/bento/crates/workflow/src/tasks/join_povw.rs
@@ -3,16 +3,42 @@
// Use of this source code is governed by the Business Source License
// as found in the LICENSE-BSL file.
+use std::rc::Rc;
+
use crate::{
Agent,
redis::{self, AsyncCommands},
tasks::{RECUR_RECEIPT_PATH, deserialize_obj, serialize_obj},
};
use anyhow::{Context, Result};
-use risc0_zkvm::{ReceiptClaim, SegmentReceipt, SuccinctReceipt, WorkClaim};
+use risc0_zkvm::{ProverServer, ReceiptClaim, SegmentReceipt, SuccinctReceipt, WorkClaim};
use uuid::Uuid;
use workflow_common::JoinReq;
+/// Lifts a receipt to POVW if it's a segment receipt, otherwise returns it as-is
+async fn lift_or_deserialize_povw_receipt(
+ prover: &Rc<dyn ProverServer>,
+ receipt_data: &[u8],
+ idx: usize,
+ job_id: &Uuid,
+) -> Result<SuccinctReceipt<WorkClaim<ReceiptClaim>>> {
+ match deserialize_obj::<SegmentReceipt>(receipt_data) {
+ Ok(segment_receipt) => {
+ let povw_receipt = prover
+ .lift_povw(&segment_receipt)
+ .with_context(|| format!("Failed to lift segment {idx} to POVW"))?;
+ tracing::debug!("POVW lifting complete {job_id} - {idx}");
+ Ok(povw_receipt)
+ }
+ Err(_) => {
+ let povw_receipt: SuccinctReceipt<WorkClaim<ReceiptClaim>> =
+ deserialize_obj(receipt_data)
+ .with_context(|| format!("Failed to deserialize POVW receipt {idx}"))?;
+ Ok(povw_receipt)
+ }
+ }
+}
+
/// Run a POVW join request
pub async fn join_povw(agent: &Agent, job_id: &Uuid, request: &JoinReq) -> Result<()> {
let mut conn = agent.redis_pool.get().await?;
@@ -32,46 +58,9 @@ pub async fn join_povw(agent: &Agent, job_id: &Uuid, request: &JoinReq) -> Resul
// Handle each receipt independently - they could be mixed types
let prover = agent.prover.as_ref().context("Missing prover from POVW join task")?;
- let (left_receipt, right_receipt): (
- SuccinctReceipt<WorkClaim<ReceiptClaim>>,
- SuccinctReceipt<WorkClaim<ReceiptClaim>>,
- ) = tokio::try_join!(
- async {
- match deserialize_obj::<SegmentReceipt>(&left_receipt_bytes) {
- Ok(segment_receipt) => {
- // Successfully deserialized as segment receipt, now lift to POVW
- let povw_receipt = prover
- .lift_povw(&segment_receipt)
- .context("Failed to lift left segment to POVW")?;
- Ok::<_, anyhow::Error>(povw_receipt)
- }
- Err(_) => {
- // Failed to deserialize as segment, try as already-lifted POVW receipt
- let povw_receipt: SuccinctReceipt<WorkClaim<ReceiptClaim>> =
- deserialize_obj(&left_receipt_bytes)
- .context("Failed to deserialize left POVW receipt")?;
- Ok(povw_receipt)
- }
- }
- },
- async {
- match deserialize_obj::<SegmentReceipt>(&right_receipt_bytes) {
- Ok(segment_receipt) => {
- // Successfully deserialized as segment receipt, now lift to POVW
- let povw_receipt = prover
- .lift_povw(&segment_receipt)
- .context("Failed to lift right segment to POVW")?;
- Ok::<_, anyhow::Error>(povw_receipt)
- }
- Err(_) => {
- // Failed to deserialize as segment, try as already-lifted POVW receipt
- let povw_receipt: SuccinctReceipt<WorkClaim<ReceiptClaim>> =
- deserialize_obj(&right_receipt_bytes)
- .context("Failed to deserialize right POVW receipt")?;
- Ok(povw_receipt)
- }
- }
- }
+ let (left_receipt, right_receipt) = tokio::try_join!(
+ lift_or_deserialize_povw_receipt(prover, &left_receipt_bytes, request.left, job_id),
+ lift_or_deserialize_povw_receipt(prover, &right_receipt_bytes, request.right, job_id)
)?;
tracing::debug!("Starting POVW join of receipts {} and {}", request.left, request.right);
|
||
| )?; | ||
|
|
||
| tracing::trace!("Joining {job_id} - {} + {} -> {}", request.left, request.right, request.idx); | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not resolve task, so might be confusing?