diff --git a/core/src/lib.rs b/core/src/lib.rs index fa7adc02..f64d2106 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -329,6 +329,7 @@ mod tests { proof_type, blob_proof_type: BlobProofType::ProofOfEquivalence, prover_args: test_proof_params(false), + image_id: None, }; prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await; } @@ -358,6 +359,7 @@ mod tests { proof_type, blob_proof_type: BlobProofType::ProofOfEquivalence, prover_args: test_proof_params(false), + image_id: None, }; prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await; } @@ -397,6 +399,7 @@ mod tests { proof_type, blob_proof_type: BlobProofType::ProofOfEquivalence, prover_args: test_proof_params(false), + image_id: None, }; prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await; } @@ -430,6 +433,7 @@ mod tests { proof_type, blob_proof_type: BlobProofType::ProofOfEquivalence, prover_args: test_proof_params(false), + image_id: None, }; prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await; } @@ -460,6 +464,7 @@ mod tests { proof_type, blob_proof_type: BlobProofType::ProofOfEquivalence, prover_args: test_proof_params(true), + image_id: None, }; let proof = prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await; diff --git a/host/src/cache.rs b/host/src/cache.rs index 606a7f4a..1144c598 100644 --- a/host/src/cache.rs +++ b/host/src/cache.rs @@ -108,6 +108,7 @@ mod test { blob_proof_type: BlobProofType::KzgVersionedHash, prover_args: Default::default(), l1_inclusion_block_number: 0, + image_id: None, }; let raiko = Raiko::new( l1_chain_spec.clone(), diff --git a/host/src/proof.rs b/host/src/proof.rs index 697bb1ea..9a8e7599 100644 --- a/host/src/proof.rs +++ b/host/src/proof.rs @@ -576,6 +576,7 @@ pub async fn handle_proof( #[cfg(test)] mod tests { use super::*; + use alloy_primitives::ChainId; use tokio::sync::mpsc; fn create_test_proof_request() -> ProofRequest { diff --git a/host/tests/common/request.rs b/host/tests/common/request.rs index d807587a..7e58e84e 100644 --- a/host/tests/common/request.rs +++ b/host/tests/common/request.rs @@ -1,8 +1,10 @@ -use raiko_core::interfaces::{AggregationOnlyRequest, ProofRequestOpt, ProverSpecificOpts}; +use raiko_core::interfaces::{ + get_aggregation_image, AggregationOnlyRequest, ProofRequestOpt, ProverSpecificOpts, +}; use raiko_host::server::api; -use raiko_lib::consts::Network; use raiko_lib::proof_type::ProofType; use raiko_lib::prover::Proof; +use raiko_lib::{consts::Network, prover::encode_image_id}; use raiko_tasks::{TaskDescriptor, TaskReport, TaskStatus}; use serde_json::json; @@ -20,6 +22,13 @@ pub fn make_proof_request( block_number, std::time::Instant::now().elapsed().as_secs() ); + let image_id = match proof_type { + ProofType::Sp1 | ProofType::Risc0 => { + let (_, image_id) = get_aggregation_image(*proof_type).unwrap(); + Some(encode_image_id(image_id)) + } + ProofType::Native | ProofType::Sgx => None, + }; ProofRequestOpt { block_number: Some(block_number), network: Some(network.to_string()), @@ -46,6 +55,7 @@ pub fn make_proof_request( sgx: None, sp1: None, }, + image_id, } } @@ -66,6 +76,13 @@ pub async fn make_aggregate_proof_request( .join(","), std::time::Instant::now().elapsed().as_secs() ); + let image_id = match proof_type { + ProofType::Sp1 | ProofType::Risc0 => { + let (_, image_id) = get_aggregation_image(*proof_type).unwrap(); + Some(encode_image_id(image_id)) + } + ProofType::Native | ProofType::Sgx => None, + }; AggregationOnlyRequest { aggregation_ids: block_numbers, proofs, @@ -83,6 +100,7 @@ pub async fn make_aggregate_proof_request( sgx: None, sp1: None, }, + image_id, } } @@ -246,7 +264,8 @@ pub async fn get_status_of_aggregation_proof_request( client: &Client, request: &AggregationOnlyRequest, ) -> TaskStatus { - let expected_task_descriptor: TaskDescriptor = TaskDescriptor::Aggregation(request.into()); + let expected_task_descriptor: TaskDescriptor = + TaskDescriptor::Aggregation(request.try_into().unwrap()); let report = v2_assert_report(client).await; for (task_descriptor, task_status) in &report { if task_descriptor == &expected_task_descriptor { diff --git a/host/tests/test/manual_test.rs b/host/tests/test/manual_test.rs index dc73e0c4..86cec9df 100644 --- a/host/tests/test/manual_test.rs +++ b/host/tests/test/manual_test.rs @@ -1,8 +1,10 @@ use crate::common::{complete_proof_request, v2_assert_report, Client}; -use raiko_core::interfaces::{ProofRequestOpt, ProverSpecificOpts}; +use raiko_core::interfaces::{get_aggregation_image, ProofRequestOpt, ProverSpecificOpts}; use raiko_host::server::api; +use raiko_lib::{proof_type::ProofType, prover::encode_image_id}; use raiko_tasks::TaskStatus; use serde_json::json; +use std::str::FromStr; /// This test is used to manually test the proof process. Operator can use this to test case to /// simplly test online service. @@ -32,16 +34,26 @@ pub async fn test_manual_prove() { let api_version = std::env::var("RAIKO_TEST_MANUAL_PROVE_API_VERSION").unwrap_or_default(); let network = std::env::var("RAIKO_TEST_MANUAL_PROVE_NETWORK").unwrap_or_default(); let proof_type = std::env::var("RAIKO_TEST_MANUAL_PROVE_PROOF_TYPE").unwrap_or_default(); + let proof_type = ProofType::from_str(&proof_type).unwrap(); let block_number = std::env::var("RAIKO_TEST_MANUAL_PROVE_BLOCK_NUMBER") .map(|s| s.parse::().unwrap()) .unwrap(); let raiko_rpc_url = std::env::var("RAIKO_TEST_MANUAL_PROVE_RAIKO_RPC_URL").unwrap_or_default(); + let image_id = match proof_type { + ProofType::Sp1 | ProofType::Risc0 => { + let (_, image_id) = get_aggregation_image(proof_type).unwrap(); + Some(encode_image_id(image_id)) + } + ProofType::Native | ProofType::Sgx => None, + }; + let client = Client::new(raiko_rpc_url.clone()); let request = ProofRequestOpt { block_number: Some(block_number), network: Some(network.clone()), - proof_type: Some(proof_type.clone()), + proof_type: Some(proof_type.to_string()), + image_id, // Untesting parameters l1_inclusion_block_number: None, diff --git a/taskdb/src/mem_db.rs b/taskdb/src/mem_db.rs index bcec17f6..f06b1fab 100644 --- a/taskdb/src/mem_db.rs +++ b/taskdb/src/mem_db.rs @@ -442,13 +442,14 @@ mod tests { #[test] fn test_db_enqueue() { let mut db = InMemoryTaskDb::new(); - let params = ProofTaskDescriptor { - chain_id: 1, - block_id: 1, - blockhash: B256::default(), - proof_system: ProofType::Native, - prover: "0x1234".to_owned(), - }; + let params = ProofTaskDescriptor::new( + 1, + 1, + B256::default(), + ProofType::Native, + "0x1234".to_owned(), + None, + ); db.enqueue_task(¶ms).expect("enqueue task"); let status = db.get_task_proving_status(¶ms); assert!(status.is_ok()); diff --git a/taskdb/tests/main.rs b/taskdb/tests/main.rs index 74b2a91b..e4577338 100644 --- a/taskdb/tests/main.rs +++ b/taskdb/tests/main.rs @@ -46,6 +46,7 @@ mod tests { prover_args, blob_proof_type: BlobProofType::ProofOfEquivalence, l1_inclusion_block_number: 0, + image_id: Some("test_image".to_string()), }, ) } @@ -60,18 +61,15 @@ mod tests { let (chain_id, blockhash, request) = create_random_task(&mut ChaCha8Rng::seed_from_u64(123)); - tama.enqueue_task( - &( - chain_id, - request.block_number, - blockhash, - request.proof_type, - request.prover.to_string(), - ) - .into(), - ) - .await - .unwrap(); + let task = ProofTaskDescriptor::new( + chain_id.into(), + request.block_number, + blockhash, + request.proof_type, + request.prover.to_string(), + request.image_id.clone(), + ); + tama.enqueue_task(&task).await.unwrap(); } #[tokio::test] @@ -88,60 +86,49 @@ mod tests { for _ in 0..5 { let (chain_id, blockhash, request) = create_random_task(&mut rng); - tama.enqueue_task( - &( - chain_id, - request.block_number, - blockhash, - request.proof_type, - request.prover.to_string(), - ) - .into(), - ) - .await - .unwrap(); + let task = ProofTaskDescriptor::new( + chain_id.into(), + request.block_number, + blockhash, + request.proof_type, + request.prover.to_string(), + request.image_id.clone(), + ); + tasks.push(task.clone()); - let task_status = tama - .get_task_proving_status( - &( - chain_id, - request.block_number, - blockhash, - request.proof_type, - request.prover.to_string(), - ) - .into(), - ) - .await - .unwrap() - .0; + tama.enqueue_task(&task).await.unwrap(); + + let task_desc = ProofTaskDescriptor::new( + chain_id.into(), + request.block_number, + blockhash, + request.proof_type, + request.prover.to_string(), + request.image_id.clone(), + ); + let task_status = tama.get_task_proving_status(&task_desc).await.unwrap().0; assert_eq!(task_status.len(), 1); let status = task_status .first() .expect("Already confirmed there is exactly 1 element"); assert_eq!(status.0, TaskStatus::Registered); - tasks.push(( - chain_id, - blockhash, + let task = ProofTaskDescriptor::new( + chain_id.into(), request.block_number, + blockhash, request.proof_type, - request.prover, - )); + request.prover.to_string(), + request.image_id.clone(), + ); + tasks.push(task); } std::thread::sleep(Duration::from_millis(1)); { - let task_0_desc: &ProofTaskDescriptor = &( - tasks[0].0, - tasks[0].2, - tasks[0].1, - tasks[0].3, - tasks[0].4.to_string(), - ) - .into(); - let task_status = tama.get_task_proving_status(task_0_desc).await.unwrap().0; + let task_0_desc = tasks[0].clone(); + let task_status = tama.get_task_proving_status(&task_0_desc).await.unwrap().0; println!("{task_status:?}"); tama.update_task_progress( task_0_desc.clone(), @@ -151,7 +138,7 @@ mod tests { .await .unwrap(); - let task_status = tama.get_task_proving_status(task_0_desc).await.unwrap().0; + let task_status = tama.get_task_proving_status(&task_0_desc).await.unwrap().0; println!("{task_status:?}"); assert_eq!(task_status.len(), 2); assert_eq!(task_status[1].0, TaskStatus::Cancelled_NeverStarted); @@ -159,20 +146,13 @@ mod tests { } // ----------------------- { - let task_1_desc: &ProofTaskDescriptor = &( - tasks[1].0, - tasks[1].2, - tasks[1].1, - tasks[1].3, - tasks[1].4.to_string(), - ) - .into(); + let task_1_desc = tasks[1].clone(); tama.update_task_progress(task_1_desc.clone(), TaskStatus::WorkInProgress, None) .await .unwrap(); { - let task_status = tama.get_task_proving_status(task_1_desc).await.unwrap().0; + let task_status = tama.get_task_proving_status(&task_1_desc).await.unwrap().0; assert_eq!(task_status.len(), 2); assert_eq!(task_status[1].0, TaskStatus::WorkInProgress); assert_eq!(task_status[0].0, TaskStatus::Registered); @@ -189,7 +169,7 @@ mod tests { .unwrap(); { - let task_status = tama.get_task_proving_status(task_1_desc).await.unwrap().0; + let task_status = tama.get_task_proving_status(&task_1_desc).await.unwrap().0; assert_eq!(task_status.len(), 3); assert_eq!(task_status[2].0, TaskStatus::CancellationInProgress); assert_eq!(task_status[1].0, TaskStatus::WorkInProgress); @@ -203,7 +183,7 @@ mod tests { .unwrap(); { - let task_status = tama.get_task_proving_status(task_1_desc).await.unwrap().0; + let task_status = tama.get_task_proving_status(&task_1_desc).await.unwrap().0; assert_eq!(task_status.len(), 4); assert_eq!(task_status[3].0, TaskStatus::Cancelled); assert_eq!(task_status[2].0, TaskStatus::CancellationInProgress); @@ -214,20 +194,13 @@ mod tests { // ----------------------- { - let task_2_desc: &ProofTaskDescriptor = &( - tasks[2].0, - tasks[2].2, - tasks[2].1, - tasks[2].3, - tasks[2].4.to_string(), - ) - .into(); + let task_2_desc = tasks[2].clone(); tama.update_task_progress(task_2_desc.clone(), TaskStatus::WorkInProgress, None) .await .unwrap(); { - let task_status = tama.get_task_proving_status(task_2_desc).await.unwrap().0; + let task_status = tama.get_task_proving_status(&task_2_desc).await.unwrap().0; assert_eq!(task_status.len(), 2); assert_eq!(task_status[1].0, TaskStatus::WorkInProgress); assert_eq!(task_status[0].0, TaskStatus::Registered); @@ -241,32 +214,25 @@ mod tests { .unwrap(); { - let task_status = tama.get_task_proving_status(task_2_desc).await.unwrap().0; + let task_status = tama.get_task_proving_status(&task_2_desc).await.unwrap().0; assert_eq!(task_status.len(), 3); assert_eq!(task_status[2].0, TaskStatus::Success); assert_eq!(task_status[1].0, TaskStatus::WorkInProgress); assert_eq!(task_status[0].0, TaskStatus::Registered); } - assert_eq!(proof, tama.get_task_proof(task_2_desc,).await.unwrap()); + assert_eq!(proof, tama.get_task_proof(&task_2_desc).await.unwrap()); } // ----------------------- { - let task_3_desc: &ProofTaskDescriptor = &( - tasks[3].0, - tasks[3].2, - tasks[3].1, - tasks[3].3, - tasks[3].4.to_string(), - ) - .into(); + let task_3_desc = tasks[3].clone(); tama.update_task_progress(task_3_desc.clone(), TaskStatus::WorkInProgress, None) .await .unwrap(); { - let task_status = tama.get_task_proving_status(task_3_desc).await.unwrap().0; + let task_status = tama.get_task_proving_status(&task_3_desc).await.unwrap().0; assert_eq!(task_status.len(), 2); assert_eq!(task_status[1].0, TaskStatus::WorkInProgress); assert_eq!(task_status[0].0, TaskStatus::Registered); @@ -283,7 +249,7 @@ mod tests { .unwrap(); { - let task_status = tama.get_task_proving_status(task_3_desc).await.unwrap().0; + let task_status = tama.get_task_proving_status(&task_3_desc).await.unwrap().0; assert_eq!(task_status.len(), 3); assert_eq!(task_status[2].0, TaskStatus::UnspecifiedFailureReason); assert_eq!(task_status[1].0, TaskStatus::WorkInProgress); @@ -297,7 +263,7 @@ mod tests { .unwrap(); { - let task_status = tama.get_task_proving_status(task_3_desc).await.unwrap().0; + let task_status = tama.get_task_proving_status(&task_3_desc).await.unwrap().0; assert_eq!(task_status.len(), 4); assert_eq!(task_status[3].0, TaskStatus::WorkInProgress); assert_eq!(task_status[2].0, TaskStatus::UnspecifiedFailureReason); @@ -317,7 +283,7 @@ mod tests { .unwrap(); { - let task_status = tama.get_task_proving_status(task_3_desc).await.unwrap().0; + let task_status = tama.get_task_proving_status(&task_3_desc).await.unwrap().0; assert_eq!(task_status.len(), 5); assert_eq!(task_status[4].0, TaskStatus::Success); assert_eq!(task_status[3].0, TaskStatus::WorkInProgress); @@ -326,7 +292,7 @@ mod tests { assert_eq!(task_status[0].0, TaskStatus::Registered); } - assert_eq!(proof, tama.get_task_proof(task_3_desc,).await.unwrap()); + assert_eq!(proof, tama.get_task_proof(&task_3_desc).await.unwrap()); } } }