Skip to content

Commit

Permalink
feat(host): simplify proof request config reading
Browse files Browse the repository at this point in the history
  • Loading branch information
petarvujovic98 committed Jul 11, 2024
1 parent ae2f484 commit 05461a1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
4 changes: 4 additions & 0 deletions host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ impl ProverState {
pub fn task_manager(&self) -> TaskManagerWrapper {
get_task_manager(&(&self.opts).into())
}

pub fn request_config(&self) -> ProofRequestOpt {
self.opts.proof_request_opt.clone()
}
}

#[global_allocator]
Expand Down
21 changes: 8 additions & 13 deletions host/src/server/api/v1/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,10 @@ pub async fn validate_cache_input(
}
}

pub async fn handle_proof(
ProverState {
opts,
chain_specs: support_chain_specs,
..
}: ProverState,
req: Value,
) -> HostResult<ProofResponse> {
pub async fn handle_proof(prover_state: ProverState, req: Value) -> HostResult<ProofResponse> {
// Override the existing proof request config from the config file and command line
// options with the request from the client.
let mut config = opts.proof_request_opt.clone();
let mut config = prover_state.request_config();
config.merge(&req)?;

// Construct the actual proof request from the available configs.
Expand All @@ -117,16 +110,18 @@ pub async fn handle_proof(

// Check for a cached input for the given request config.
let cached_input = get_cached_input(
&opts.cache_path,
&prover_state.opts.cache_path,
proof_request.block_number,
&proof_request.network.to_string(),
);

let l1_chain_spec = support_chain_specs
let l1_chain_spec = prover_state
.chain_specs
.get_chain_spec(&proof_request.l1_network.to_string())
.ok_or_else(|| HostError::InvalidRequestConfig("Unsupported l1 network".to_string()))?;

let taiko_chain_spec = support_chain_specs
let taiko_chain_spec = prover_state
.chain_specs
.get_chain_spec(&proof_request.network.to_string())
.ok_or_else(|| HostError::InvalidRequestConfig("Unsupported raiko network".to_string()))?;

Expand Down Expand Up @@ -190,7 +185,7 @@ pub async fn handle_proof(

// Cache the input for future use.
set_cached_input(
&opts.cache_path,
&prover_state.opts.cache_path,
proof_request.block_number,
&proof_request.network.to_string(),
&input,
Expand Down
2 changes: 1 addition & 1 deletion host/src/server/api/v2/proof/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async fn cancel_handler(
) -> HostResult<CancelStatus> {
// Override the existing proof request config from the config file and command line
// options with the request from the client.
let mut config = prover_state.opts.proof_request_opt.clone();
let mut config = prover_state.request_config();
config.merge(&req)?;

// Construct the actual proof request from the available configs.
Expand Down
2 changes: 1 addition & 1 deletion host/src/server/api/v2/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn proof_handler(
inc_current_req();
// Override the existing proof request config from the config file and command line
// options with the request from the client.
let mut config = prover_state.opts.proof_request_opt.clone();
let mut config = prover_state.request_config();
config.merge(&req)?;

// Construct the actual proof request from the available configs.
Expand Down

0 comments on commit 05461a1

Please sign in to comment.