Skip to content

Commit

Permalink
Fix job creation expiry issues in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay111meher committed Dec 2, 2024
1 parent 908b3d2 commit 6a501ab
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kalypso-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ generator = {path = "../generator", package = "generator"}
hex = "0.4.3"
kalypso_helper = {path = "../helper", package = "helper"}
log = "0.4"
matching_engine_helpers = { path = "../matching_engine", package = "matching_engine" }
matching_engine_helpers = { path = "../matching_engine", package = "matching_engine", features = ["use_l1_block_numbers"]}
reqwest = { version = "0.11", features = ["stream"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
14 changes: 14 additions & 0 deletions kalypso-cli/src/common_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ pub struct NonConfidentialRequest {
pub max_proof_generation_time: U256,
pub inputs: ethers::types::Bytes,
pub market_id: U256,
pub provider_http: Provider<Http>,
pub kalypso_rpc_url: String,
}

impl CommonDeps {
Expand Down Expand Up @@ -635,6 +637,9 @@ impl CommonDeps {
let market_id = U256::from_dec_str(market_id.as_str())
.map_err(|e| format!("Invalid Market Id: {}", e))?;

let provider_http =
Provider::<Http>::try_from(rpc_url).map_err(|e| format!("Invalid RPC URL: {}", e))?;

Ok(NonConfidentialRequest {
private_key_signer,
proof_marketplace,
Expand All @@ -643,6 +648,8 @@ impl CommonDeps {
max_proof_generation_time,
inputs,
market_id,
provider_http,
kalypso_rpc_url: rpc_url.clone(),
})
}
}
Expand Down Expand Up @@ -911,6 +918,8 @@ pub struct ConfidentialRequest {
pub entity_registry: bindings::entity_key_registry::EntityKeyRegistry<
SignerMiddleware<Provider<Http>, LocalWallet>,
>,
pub provider_http: Provider<Http>,
pub kalypso_rpc_url: String,
}

impl CommonDeps {
Expand Down Expand Up @@ -999,6 +1008,9 @@ impl CommonDeps {
rpc_url,
)?;

let provider_http =
Provider::<Http>::try_from(rpc_url).map_err(|e| format!("Invalid RPC URL: {}", e))?;

Ok(ConfidentialRequest {
private_key_signer,
proof_marketplace,
Expand All @@ -1009,6 +1021,8 @@ impl CommonDeps {
market_id,
private_inputs,
entity_registry,
provider_http,
kalypso_rpc_url: rpc_url.clone(),
})
}
}
Expand Down
47 changes: 45 additions & 2 deletions kalypso-cli/src/operations/create_request.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;

use async_trait::async_trait;
use ethers::providers::Middleware;
use ethers::{core::rand, signers::Signer, types::U256};

use crate::{common_deps::CommonDeps, operations::compute_pcrs::non_confidential_pcrs};
Expand Down Expand Up @@ -94,14 +95,35 @@ impl Operation for ConfidentialRequest {
)
.map_err(|e| format!("Failed Encryption: {}", e))?;

let latest_l2_block = confidential_request_info
.provider_http
.get_block_number()
.await
.map_err(|e| {
format!(
"Failed fetching latest kalypso block number from chain: {}",
e
)
})?;

let latest_l1_block = matching_engine_helpers::utility::get_l1_block_from_l2_block(
&confidential_request_info.kalypso_rpc_url,
latest_l2_block.as_u64().into(),
)
.await;

if latest_l1_block.is_none() {
return Err("Failed fetching latest 11 block".into());
}

let proof_request_transaction = CommonDeps::send_and_confirm(
confidential_request_info
.proof_marketplace
.create_ask(
bindings::proof_marketplace::Ask {
market_id: confidential_request_info.market_id,
reward: confidential_request_info.max_proof_generation_cost,
expiry: (10000000000000 as u64).into(),
expiry: (latest_l1_block.unwrap().as_u64() + 200).into(),
time_taken_for_proof_generation: confidential_request_info
.max_proof_generation_time,
deadline: U256::zero(),
Expand Down Expand Up @@ -185,14 +207,35 @@ impl Operation for NonConfidentialRequest {
println!("Token Approval: {}", token_approval_transaction);
}

let latest_l2_block = non_confidential_request_info
.provider_http
.get_block_number()
.await
.map_err(|e| {
format!(
"Failed fetching latest kalypso block number from chain: {}",
e
)
})?;

let latest_l1_block = matching_engine_helpers::utility::get_l1_block_from_l2_block(
&non_confidential_request_info.kalypso_rpc_url,
latest_l2_block.as_u64().into(),
)
.await;

if latest_l1_block.is_none() {
return Err("Failed fetching latest 11 block".into());
}

let proof_request_transaction = CommonDeps::send_and_confirm(
non_confidential_request_info
.proof_marketplace
.create_ask(
bindings::proof_marketplace::Ask {
market_id: non_confidential_request_info.market_id,
reward: non_confidential_request_info.max_proof_generation_cost,
expiry: (200 as u64).into(),
expiry: (latest_l1_block.unwrap().as_u64() + 200).into(),
time_taken_for_proof_generation: non_confidential_request_info
.max_proof_generation_time,
deadline: U256::zero(),
Expand Down

0 comments on commit 6a501ab

Please sign in to comment.