Skip to content

Commit

Permalink
chore: Switch to OPSuccinctHost (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani authored Feb 13, 2025
1 parent 7f8e60f commit d89f2ce
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 67 deletions.
14 changes: 7 additions & 7 deletions proposer/succinct/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ async fn request_span_proof(
}
};

let host_cli = match fetcher
.get_host_cli_args(
let host_args = match fetcher
.get_host_args(
payload.start,
payload.end,
ProgramType::Multi,
Expand All @@ -177,7 +177,7 @@ async fn request_span_proof(
}
};

let mem_kv_store = start_server_and_native_client(host_cli).await?;
let mem_kv_store = start_server_and_native_client(host_args).await?;

let sp1_stdin = match get_proof_stdin(mem_kv_store) {
Ok(stdin) => stdin,
Expand Down Expand Up @@ -338,8 +338,8 @@ async fn request_mock_span_proof(
}
};

let host_cli = match fetcher
.get_host_cli_args(
let host_args = match fetcher
.get_host_args(
payload.start,
payload.end,
ProgramType::Multi,
Expand All @@ -355,7 +355,7 @@ async fn request_mock_span_proof(
};

let start_time = Instant::now();
let oracle = start_server_and_native_client(host_cli.clone()).await?;
let oracle = start_server_and_native_client(host_args.clone()).await?;
let witness_generation_duration = start_time.elapsed();

let sp1_stdin = match get_proof_stdin(oracle) {
Expand All @@ -377,7 +377,7 @@ async fn request_mock_span_proof(
.get_l2_block_data_range(payload.start, payload.end)
.await?;

let l1_head = host_cli.l1_head;
let l1_head = host_args.kona_args.l1_head;
// Get the L1 block number from the L1 head.
let l1_block_number = fetcher.get_l1_header(l1_head.into()).await?.number;
let stats = ExecutionStats::new(
Expand Down
8 changes: 4 additions & 4 deletions scripts/prove/bin/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ async fn main() -> Result<()> {
let (l2_start_block, l2_end_block) =
get_validated_block_range(&data_fetcher, args.start, args.end, DEFAULT_RANGE).await?;

let host_cli = data_fetcher
.get_host_cli_args(l2_start_block, l2_end_block, ProgramType::Multi, cache_mode)
let host_args = data_fetcher
.get_host_args(l2_start_block, l2_end_block, ProgramType::Multi, cache_mode)
.await?;

let start_time = Instant::now();
let oracle = start_server_and_native_client(host_cli.clone()).await?;
let oracle = start_server_and_native_client(host_args.clone()).await?;
let witness_generation_duration = start_time.elapsed();

// Get the stdin for the block.
Expand Down Expand Up @@ -74,7 +74,7 @@ async fn main() -> Result<()> {
execute_multi(&data_fetcher, sp1_stdin, l2_start_block, l2_end_block).await?;

let l1_block_number = data_fetcher
.get_l1_header(host_cli.l1_head.into())
.get_l1_header(host_args.l1_head.into())
.await
.unwrap()
.number;
Expand Down
8 changes: 4 additions & 4 deletions scripts/prove/tests/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ async fn execute_batch() -> Result<()> {
let (l2_start_block, l2_end_block) =
get_rolling_block_range(&data_fetcher, ONE_HOUR, DEFAULT_RANGE).await?;

let host_cli = data_fetcher
.get_host_cli_args(
let host_args = data_fetcher
.get_host_args(
l2_start_block,
l2_end_block,
ProgramType::Multi,
CacheMode::DeleteCache,
)
.await?;

let oracle = start_server_and_native_client(host_cli.clone()).await?;
let oracle = start_server_and_native_client(host_args.clone()).await?;

// Get the stdin for the block.
let sp1_stdin = get_proof_stdin(oracle)?;
Expand All @@ -39,7 +39,7 @@ async fn execute_batch() -> Result<()> {
execute_multi(&data_fetcher, sp1_stdin, l2_start_block, l2_end_block).await?;

let l1_block_number = data_fetcher
.get_l1_header(host_cli.l1_head.into())
.get_l1_header(host_args.l1_head.into())
.await
.unwrap()
.number;
Expand Down
15 changes: 7 additions & 8 deletions scripts/utils/bin/cost_estimator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::Result;
use clap::Parser;
use futures::StreamExt;
use kona_host::single::SingleChainHost;
use log::info;
use op_succinct_host_utils::{
block_range::{
Expand All @@ -11,7 +10,7 @@ use op_succinct_host_utils::{
fetcher::{CacheMode, OPSuccinctDataFetcher, RunContext},
get_proof_stdin, start_server_and_native_client,
stats::ExecutionStats,
ProgramType,
OPSuccinctHost, ProgramType,
};
use op_succinct_scripts::HostExecutorArgs;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
Expand All @@ -31,7 +30,7 @@ const ONE_WEEK: Duration = Duration::from_secs(60 * 60 * 24 * 7);
/// Run the zkVM execution process for each split range in parallel. Writes the execution stats for
/// each block range to a CSV file after each execution completes (not guaranteed to be in order).
async fn execute_blocks_and_write_stats_csv(
host_clis: &[SingleChainHost],
host_args: &[OPSuccinctHost],
ranges: Vec<SpanBatchRange>,
l2_chain_id: u64,
start: u64,
Expand Down Expand Up @@ -75,9 +74,9 @@ async fn execute_blocks_and_write_stats_csv(

// Use futures::future::join_all to run the server and client in parallel. Note: stream::iter did not work here, possibly
// because the server and client are long-lived tasks.
let handles = host_clis.iter().cloned().map(|host_cli| {
let handles = host_args.iter().cloned().map(|host_args| {
tokio::spawn(async move {
let oracle = start_server_and_native_client(host_cli).await.unwrap();
let oracle = start_server_and_native_client(host_args).await.unwrap();
get_proof_stdin(oracle).unwrap()
})
});
Expand Down Expand Up @@ -222,10 +221,10 @@ async fn main() -> Result<()> {
};

// Get the host CLIs in order, in parallel.
let host_clis = futures::stream::iter(split_ranges.iter())
let host_args = futures::stream::iter(split_ranges.iter())
.map(|range| async {
data_fetcher
.get_host_cli_args(range.start, range.end, ProgramType::Multi, cache_mode)
.get_host_args(range.start, range.end, ProgramType::Multi, cache_mode)
.await
.expect("Failed to get host CLI args")
})
Expand All @@ -234,7 +233,7 @@ async fn main() -> Result<()> {
.await;

execute_blocks_and_write_stats_csv(
&host_clis,
&host_args,
split_ranges,
l2_chain_id,
l2_start_block,
Expand Down
8 changes: 4 additions & 4 deletions scripts/utils/bin/gen_sp1_test_artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ async fn main() -> Result<()> {
};

// Get the host CLIs in order, in parallel.
let host_clis = futures::stream::iter(split_ranges.iter())
let host_args = futures::stream::iter(split_ranges.iter())
.map(|range| async {
data_fetcher
.get_host_cli_args(range.start, range.end, ProgramType::Multi, cache_mode)
.get_host_args(range.start, range.end, ProgramType::Multi, cache_mode)
.await
.expect("Failed to get host CLI args")
})
Expand All @@ -55,8 +55,8 @@ async fn main() -> Result<()> {
.await;

let mut successful_ranges = Vec::new();
for (range, host_cli) in split_ranges.iter().zip(host_clis.iter()) {
let oracle = start_server_and_native_client(host_cli.clone())
for (range, host_args) in split_ranges.iter().zip(host_args.iter()) {
let oracle = start_server_and_native_client(host_args.clone())
.await
.unwrap();
let sp1_stdin = get_proof_stdin(oracle).unwrap();
Expand Down
74 changes: 38 additions & 36 deletions utils/host/src/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ use std::{

use alloy_primitives::{keccak256, map::HashMap, Bytes, U256, U64};

use crate::L2Output;
use crate::{
rollup_config::{get_rollup_config_path, merge_rollup_config},
ProgramType,
};
use crate::{L2Output, OPSuccinctHost};

#[derive(Clone)]
/// The OPSuccinctDataFetcher struct is used to fetch the L2 output data and L2 claim data for a
Expand Down Expand Up @@ -671,13 +671,13 @@ impl OPSuccinctDataFetcher {
/// Get the L2 output data for a given block number and save the boot info to a file in the data
/// directory with block_number. Return the arguments to be passed to the native host for
/// datagen.
pub async fn get_host_cli_args(
pub async fn get_host_args(
&self,
l2_start_block: u64,
l2_end_block: u64,
multi_block: ProgramType,
cache_mode: CacheMode,
) -> Result<SingleChainHost> {
) -> Result<OPSuccinctHost> {
// If the rollup config is not already loaded, fetch and save it.
if self.rollup_config.is_none() {
return Err(anyhow::anyhow!("Rollup config not loaded."));
Expand Down Expand Up @@ -780,39 +780,41 @@ impl OPSuccinctDataFetcher {
// witness data.
fs::create_dir_all(&data_directory)?;

Ok(SingleChainHost {
l1_head: l1_head_hash,
agreed_l2_output_root,
agreed_l2_head_hash,
claimed_l2_output_root,
claimed_l2_block_number: l2_end_block,
l2_chain_id: None,
// Trim the trailing slash to avoid double slashes in the URL.
l2_node_address: Some(
self.rpc_config
.l2_rpc
.as_str()
.trim_end_matches('/')
.to_string(),
),
l1_node_address: Some(
self.rpc_config
.l1_rpc
.as_str()
.trim_end_matches('/')
.to_string(),
),
l1_beacon_address: Some(
self.rpc_config
.l1_beacon_rpc
.as_str()
.trim_end_matches('/')
.to_string(),
),
data_dir: Some(data_directory.into()),
native: false,
server: true,
rollup_config_path: Some(rollup_config_path),
Ok(OPSuccinctHost {
kona_args: SingleChainHost {
l1_head: l1_head_hash,
agreed_l2_output_root,
agreed_l2_head_hash,
claimed_l2_output_root,
claimed_l2_block_number: l2_end_block,
l2_chain_id: None,
// Trim the trailing slash to avoid double slashes in the URL.
l2_node_address: Some(
self.rpc_config
.l2_rpc
.as_str()
.trim_end_matches('/')
.to_string(),
),
l1_node_address: Some(
self.rpc_config
.l1_rpc
.as_str()
.trim_end_matches('/')
.to_string(),
),
l1_beacon_address: Some(
self.rpc_config
.l1_beacon_rpc
.as_str()
.trim_end_matches('/')
.to_string(),
),
data_dir: Some(data_directory.into()),
native: false,
server: true,
rollup_config_path: Some(rollup_config_path),
},
})
}

Expand Down
7 changes: 3 additions & 4 deletions utils/host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ sol! {
}
}

#[derive(Debug, Clone)]
pub struct OPSuccinctHost {
pub kona_args: SingleChainHost,
}
Expand Down Expand Up @@ -95,12 +96,10 @@ pub fn get_agg_proof_stdin(

/// Start the server and native client. Each server is tied to a single client.
pub async fn start_server_and_native_client(
cfg: SingleChainHost,
cfg: OPSuccinctHost,
) -> Result<InMemoryOracle, anyhow::Error> {
let host = OPSuccinctHost { kona_args: cfg };

info!("Starting preimage server and client program.");
let in_memory_oracle = host.run().await?;
let in_memory_oracle = cfg.run().await?;

Ok(in_memory_oracle)
}
Expand Down

0 comments on commit d89f2ce

Please sign in to comment.